diff --git a/src/components/Tool/FixEmailAddresses/FixEmailAddressPerson/FixEmailAddressPerson.tsx b/src/components/Tool/FixEmailAddresses/FixEmailAddressPerson/FixEmailAddressPerson.tsx index 3c134a68a..5b9a9e5e8 100644 --- a/src/components/Tool/FixEmailAddresses/FixEmailAddressPerson/FixEmailAddressPerson.tsx +++ b/src/components/Tool/FixEmailAddresses/FixEmailAddressPerson/FixEmailAddressPerson.tsx @@ -208,7 +208,10 @@ export const FixEmailAddressPerson: React.FC = ({ {email.primary ? ( - + handleChangePrimary(id, index)} + > ) : ( diff --git a/src/components/Tool/FixEmailAddresses/FixEmailAddresses.test.tsx b/src/components/Tool/FixEmailAddresses/FixEmailAddresses.test.tsx index f975b9c47..084c4a0a9 100644 --- a/src/components/Tool/FixEmailAddresses/FixEmailAddresses.test.tsx +++ b/src/components/Tool/FixEmailAddresses/FixEmailAddresses.test.tsx @@ -98,15 +98,76 @@ describe('FixPhoneNumbers-Home', () => { expect(queryByTestId('no-data')).not.toBeInTheDocument(); }); - it('change primary of first email', async () => { - const { getByTestId, queryByTestId } = render(); + describe('handleChangePrimary()', () => { + it('changes primary of first email', async () => { + const { getByTestId, queryByTestId } = render(); + + const star1 = await waitFor(() => + getByTestId('starOutlineIcon-testid-1'), + ); + userEvent.click(star1); + + expect(queryByTestId('starIcon-testid-0')).not.toBeInTheDocument(); + expect(getByTestId('starIcon-testid-1')).toBeInTheDocument(); + expect(getByTestId('starOutlineIcon-testid-0')).toBeInTheDocument(); + }); + + it('should choose primary and deselect primary from others', async () => { + const { getByTestId, queryByTestId } = render( + , + ); - const star1 = await waitFor(() => getByTestId('starOutlineIcon-testid-1')); - userEvent.click(star1); + let newPrimary; + await waitFor(() => { + expect(getByTestId('starIcon-testid-0')).toBeInTheDocument(); + expect(getByTestId('starIcon-testid-1')).toBeInTheDocument(); + newPrimary = getByTestId('starIcon-testid-2'); + expect(newPrimary).toBeInTheDocument(); + }); + userEvent.click(newPrimary); - expect(queryByTestId('starIcon-testid-0')).not.toBeInTheDocument(); - expect(getByTestId('starIcon-testid-1')).toBeInTheDocument(); - expect(getByTestId('starOutlineIcon-testid-0')).toBeInTheDocument(); + await waitFor(() => { + expect(queryByTestId('starIcon-testid-0')).not.toBeInTheDocument(); + expect(queryByTestId('starIcon-testid-1')).not.toBeInTheDocument(); + expect(getByTestId('starIcon-testid-2')).toBeInTheDocument(); + expect(getByTestId('starOutlineIcon-testid-0')).toBeInTheDocument(); + expect(getByTestId('starOutlineIcon-testid-1')).toBeInTheDocument(); + expect( + queryByTestId('starOutlineIcon-testid-2'), + ).not.toBeInTheDocument(); + }); + }); }); it('delete third email from first person', async () => {