Skip to content

Commit

Permalink
Adding test now GraphQl is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Jun 28, 2024
1 parent 2e8fce8 commit 02e4111
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 59 deletions.
1 change: 0 additions & 1 deletion src/components/Tool/FixMailingAddresses/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { HandleSingleConfirmProps, emptyAddress } from './FixMailingAddresses';
import { ContactAddressFragment } from './GetInvalidAddresses.generated';

const ContactHeader = styled(CardHeader)(() => ({
cursor: 'pointer',
'.MuiCardHeader-action': {
alignSelf: 'center',
},
Expand Down
100 changes: 45 additions & 55 deletions src/components/Tool/FixMailingAddresses/FixMailingAddresses.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ describe('FixSendNewsletter', () => {

describe('handleSingleConfirm()', () => {
it('should fire handleSingleConfirm', async () => {
const { getAllByRole, getByText, queryByTestId } = render(
const { getAllByRole, getByText, queryByTestId, queryByText } = render(
<Components
mocks={{
InvalidAddresses: {
Expand All @@ -447,72 +447,76 @@ describe('FixSendNewsletter', () => {
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(),
// );
await waitFor(() => {
expect(mockEnqueue).toHaveBeenCalledWith(`Updated contact ${name}`, {
variant: 'success',
});
expect(queryByText(name)).not.toBeInTheDocument();
});
});
});

describe('handleBulkConfirm()', () => {
it('should fire handleSingleConfirm', async () => {
process.env.APP_NAME = 'MPDX';
const { getByRole, queryByTestId } = render(
const name1 = 'Baggins, Frodo';
const name2 = 'Gamgee, Samwise';
const { getByRole, queryByTestId, queryByText } = render(
<Components
mocks={{
InvalidAddresses: {
...mockInvalidAddressesResponse.InvalidAddresses,
contacts: {
nodes: [
{
id: 'contactId',
name: name1,
status: null,
addresses: {
nodes: [mpdxSourcedAddress, tntSourcedAddress],
},
},
{
id: 'contactId2',
name: name2,
status: null,
addresses: {
nodes: [mpdxSourcedAddress, tntSourcedAddress],
},
},
],
},
},
}}
/>,
);
await waitFor(() =>
expect(queryByTestId('loading')).not.toBeInTheDocument(),
);
userEvent.click(getByRole('button', { name: 'Confirm 1 as MPDX' }));
userEvent.click(getByRole('button', { name: 'Confirm 2 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',
},
);
});
expect(mockEnqueue).toHaveBeenCalledWith(`Updated contact ${name1}`, {
variant: 'success',
});
expect(mockEnqueue).toHaveBeenCalledWith(`Updated contact ${name2}`, {
variant: 'success',
});

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

it('should fire handleSingleConfirm', async () => {
process.env.APP_NAME = 'MPDX';
const { getByRole, queryByTestId } = render(
const { getByRole, queryByTestId, queryByText } = render(
<Components
mocks={{
InvalidAddresses: {
Expand All @@ -536,25 +540,11 @@ describe('FixSendNewsletter', () => {

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',
},
);
expect(mockEnqueue).toHaveBeenCalledWith(`Updated contact ${name}`, {
variant: 'success',
});
expect(queryByText(name)).not.toBeInTheDocument();
});

// await waitFor(() =>
// expect(queryByText(name)).not.toBeInTheDocument(),
// );
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ const FixSendNewsletter: React.FC<Props> = ({
attributes: {
id: address.id,
validValues: true,
// TODO: Fix the Graph QL Input
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
primaryMailingAddress: address.primaryMailingAddress,
},
},
Expand Down

0 comments on commit 02e4111

Please sign in to comment.