Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Nov 5, 2024
1 parent 704cc04 commit 56e645f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ describe('AddAddressModal', () => {
expect(handleClose).toHaveBeenCalled();
});

it('requires at least one field to be filled', async () => {
const { getByRole } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<AddAddressModal
accountListId={accountListId}
contactId={contactId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);

const saveButton = getByRole('button', { name: 'Save' });
await waitFor(() => expect(saveButton).toBeDisabled());

userEvent.type(getByRole('textbox', { name: 'City' }), 'City');
await waitFor(() => expect(saveButton).not.toBeDisabled());
});

it('should create contact address', async () => {
const mutationSpy = jest.fn();
const newStreet = '4321 Neat Street';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,47 @@ describe('EditContactAddressModal', () => {
expect(handleClose).toHaveBeenCalled();
});

it('requires at least one field to be filled', async () => {
const { getByRole } = render(
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider>
<EditContactAddressModal
contactId={contactId}
accountListId={accountListId}
handleClose={handleClose}
address={{
city: '',
country: '',
historic: false,
id: 'address-1',
location: '',
metroArea: '',
postalCode: '',
primaryMailingAddress: false,
region: '',
source: 'MPDX',
state: '',
street: '123 Cool Street',
createdAt: '',
startDate: '',
}}
/>
</GqlMockedProvider>
</ThemeProvider>
</SnackbarProvider>,
);

const saveButton = getByRole('button', { name: 'Save' });
await waitFor(() => expect(saveButton).not.toBeDisabled());

userEvent.clear(getByRole('combobox', { name: 'Street' }));
await waitFor(() => expect(saveButton).toBeDisabled());

userEvent.type(getByRole('textbox', { name: 'City' }), 'City');
await waitFor(() => expect(saveButton).not.toBeDisabled());
});

it('should edit contact address', async () => {
const mutationSpy = jest.fn();
const newStreet = '4321 Neat Street';
Expand Down

0 comments on commit 56e645f

Please sign in to comment.