Skip to content

Commit

Permalink
More improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Aug 2, 2024
1 parent cbcb3d8 commit 9e12d3f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 48 deletions.
3 changes: 3 additions & 0 deletions src/components/Tool/FixEmailAddresses/EmailValidationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ const EmailValidationForm = ({ personId }: EmailValidationFormProps) => {
onCompleted: () => {
enqueueSnackbar(t('Added email address'), { variant: 'success' });
},
onError: () => {
enqueueSnackbar(t('Failed to add email address'), { variant: 'error' });
},
});
};

Expand Down
96 changes: 48 additions & 48 deletions src/components/Tool/FixEmailAddresses/FixEmailAddresses.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('FixEmailAddresses-Home', () => {
expect(getByTestId('starOutlineIcon-testid-0')).toBeInTheDocument();
});

it('should add an new email address and update GraphQL and reset form', async () => {
it('should add an new email address, firing a GraphQL mutation and resetting the form', async () => {
const { getByTestId, getAllByLabelText } = render(<Components />);
await waitFor(() => {
expect(getByTestId('textfield-testid-0')).toBeInTheDocument();
Expand Down Expand Up @@ -172,7 +172,53 @@ describe('FixEmailAddresses-Home', () => {
expect(getByTestId('starIcon-testid2-0')).toBeInTheDocument();
});

describe('add email address', () => {
it('should render no contacts with no data', async () => {
const { getByText, getByTestId } = render(
<Components
mocks={{
GetInvalidEmailAddresses: {
people: { nodes: [] },
},
}}
/>,
);
await waitFor(() =>
expect(getByTestId('fixEmailAddresses-null-state')).toBeInTheDocument(),
);
expect(
getByText('No people with email addresses need attention'),
).toBeInTheDocument();
});

it('should modify first email of first contact', async () => {
const { getByTestId } = render(<Components />);
await waitFor(() => {
expect(getByTestId('textfield-testid-0')).toBeInTheDocument();
});
const firstInput = getByTestId('textfield-testid-0');

expect(firstInput).toHaveValue('[email protected]');
userEvent.type(firstInput, '123');
expect(firstInput).toHaveValue('[email protected]');
});

describe('setContactFocus()', () => {
it('should open up contact details', async () => {
const { getByText, queryByTestId } = render(<Components />);
await waitFor(() =>
expect(queryByTestId('loading')).not.toBeInTheDocument(),
);
expect(setContactFocus).not.toHaveBeenCalled();

const contactName = getByText('Test Contact');

expect(contactName).toBeInTheDocument();
userEvent.click(contactName);
expect(setContactFocus).toHaveBeenCalledWith(contactId);
});
});

describe('Add email address - Testing cache', () => {
interface AddEmailAddressProps {
postSaveResponse: object;
emailAddressNodes: object[];
Expand Down Expand Up @@ -302,50 +348,4 @@ describe('FixEmailAddresses-Home', () => {
});
});
});

it('should render no contacts with no data', async () => {
const { getByText, getByTestId } = render(
<Components
mocks={{
GetInvalidEmailAddresses: {
people: { nodes: [] },
},
}}
/>,
);
await waitFor(() =>
expect(getByTestId('fixEmailAddresses-null-state')).toBeInTheDocument(),
);
expect(
getByText('No people with email addresses need attention'),
).toBeInTheDocument();
});

it('should modify first email of first contact', async () => {
const { getByTestId } = render(<Components />);
await waitFor(() => {
expect(getByTestId('textfield-testid-0')).toBeInTheDocument();
});
const firstInput = getByTestId('textfield-testid-0');

expect(firstInput).toHaveValue('[email protected]');
userEvent.type(firstInput, '123');
expect(firstInput).toHaveValue('[email protected]');
});

describe('setContactFocus()', () => {
it('should open up contact details', async () => {
const { getByText, queryByTestId } = render(<Components />);
await waitFor(() =>
expect(queryByTestId('loading')).not.toBeInTheDocument(),
);
expect(setContactFocus).not.toHaveBeenCalled();

const contactName = getByText('Test Contact');

expect(contactName).toBeInTheDocument();
userEvent.click(contactName);
expect(setContactFocus).toHaveBeenCalledWith(contactId);
});
});
});

0 comments on commit 9e12d3f

Please sign in to comment.