Skip to content

Commit

Permalink
Allow for selection of primary when all email addresses are primary
Browse files Browse the repository at this point in the history
  • Loading branch information
wrandall22 committed Jul 24, 2024
1 parent 122cd9b commit ad84715
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ export const FixEmailAddressPerson: React.FC<FixEmailAddressPersonProps> = ({
</Typography>
</Box>
{email.primary ? (
<Box data-testid={`starIcon-${id}-${index}`}>
<Box
data-testid={`starIcon-${id}-${index}`}
onClick={() => handleChangePrimary(id, index)}
>
<HoverableIcon path={mdiStar} size={1} />
</Box>
) : (
Expand Down
75 changes: 68 additions & 7 deletions src/components/Tool/FixEmailAddresses/FixEmailAddresses.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,76 @@ describe('FixPhoneNumbers-Home', () => {
expect(queryByTestId('no-data')).not.toBeInTheDocument();
});

it('change primary of first email', async () => {
const { getByTestId, queryByTestId } = render(<Components />);
describe('handleChangePrimary()', () => {
it('changes primary of first email', async () => {
const { getByTestId, queryByTestId } = render(<Components />);

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(
<Components
mocks={{
GetInvalidEmailAddresses: {
people: {
nodes: [
{
...mockInvalidEmailAddressesResponse[0],
emailAddresses: {
nodes: [
{
...contactOneEmailAddressNodes[0],
primary: true,
},
{
...contactOneEmailAddressNodes[1],
primary: true,
},
{
...contactOneEmailAddressNodes[2],
primary: true,
},
],
},
},
{
...mockInvalidEmailAddressesResponse[1],
},
],
},
},
}}
/>,
);

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 () => {
Expand Down

0 comments on commit ad84715

Please sign in to comment.