Skip to content

Commit

Permalink
Adding testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Jun 25, 2024
1 parent 9ea79bf commit a3ad428
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions src/components/Tool/FixMailingAddresses/FixMailingAddresses.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,134 @@ describe('FixSendNewsletter', () => {
expect(setContactFocus).toHaveBeenCalledWith(contactId);
});
});

describe('handleSingleConfirm()', () => {
it('should fire handleSingleConfirm', async () => {
const { getAllByRole, getByText, queryByTestId } = render(
<Components
mocks={{
InvalidAddresses: {
...mockInvalidAddressesResponse.InvalidAddresses,
},
}}
/>,
);
await waitFor(() =>
expect(queryByTestId('loading')).not.toBeInTheDocument(),
);
userEvent.click(getAllByRole('button', { name: 'Confirm' })[0]);

const name = 'Baggins, Frodo';
await waitFor(() => expect(getByText(name)).toBeInTheDocument());

// TODO: Fix when GraphQL is fixed
await waitFor(() =>
expect(mockEnqueue).toHaveBeenCalledWith(
`${name} - Error while saving addresses. undefined`,
{
variant: 'error',
},
),
);

// await waitFor(() =>
// expect(queryByText(name)).not.toBeInTheDocument(),
// );
});
});

describe('handleBulkConfirm()', () => {
it('should fire handleSingleConfirm', async () => {
process.env.APP_NAME = 'MPDX';
const { getByRole, queryByTestId } = render(
<Components
mocks={{
InvalidAddresses: {
...mockInvalidAddressesResponse.InvalidAddresses,
},
}}
/>,
);
await waitFor(() =>
expect(queryByTestId('loading')).not.toBeInTheDocument(),
);
userEvent.click(getByRole('button', { name: 'Confirm 1 as MPDX' }));

await waitFor(() =>
expect(getByRole('heading', { name: 'Confirm' })).toBeInTheDocument(),
);

userEvent.click(getByRole('button', { name: 'Yes' }));

// TODO: Fix when GraphQL is fixed
const name = 'Baggins, Frodo';
await waitFor(() => {
expect(mockEnqueue).toHaveBeenCalledWith(
`Error updating contact ${name}`,
{
variant: 'error',
autoHideDuration: 7000,
},
);
expect(mockEnqueue).toHaveBeenCalledWith(
`Error when updating 1 contact(s)`,
{
variant: 'error',
},
);
});

// await waitFor(() =>
// expect(queryByText(name)).not.toBeInTheDocument(),
// );
});
});

it('should fire handleSingleConfirm', async () => {
process.env.APP_NAME = 'MPDX';
const { getByRole, queryByTestId } = render(
<Components
mocks={{
InvalidAddresses: {
...mockInvalidAddressesResponse.InvalidAddresses,
},
}}
/>,
);
await waitFor(() =>
expect(queryByTestId('loading')).not.toBeInTheDocument(),
);
const name = 'Baggins, Frodo';
userEvent.click(getByRole('combobox'));
userEvent.click(getByRole('option', { name: 'DataServer' }));

userEvent.click(getByRole('button', { name: 'Confirm 1 as DataServer' }));

await waitFor(() =>
expect(getByRole('heading', { name: 'Confirm' })).toBeInTheDocument(),
);

userEvent.click(getByRole('button', { name: 'Yes' }));

// TODO: Fix when GraphQL is fixed
await waitFor(() => {
expect(mockEnqueue).toHaveBeenCalledWith(
`Error updating contact ${name}`,
{
variant: 'error',
autoHideDuration: 7000,
},
);
expect(mockEnqueue).toHaveBeenCalledWith(
`Error when updating 1 contact(s)`,
{
variant: 'error',
},
);
});

// await waitFor(() =>
// expect(queryByText(name)).not.toBeInTheDocument(),
// );
});
});

0 comments on commit a3ad428

Please sign in to comment.