Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Oct 4, 2024
1 parent 15f3632 commit fb108d5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { ThemeProvider } from '@mui/material/styles';
import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { GetPartnerGivingAnalysisIdsForMassSelectionQuery } from 'src/hooks/GetIdsForMassSelection.generated';
import {
GetPartnerGivingAnalysisIdsForMassSelectionQuery,
GetTaskIdsForMassSelectionQuery,
} from 'src/hooks/GetIdsForMassSelection.generated';
import theme from 'src/theme';
import {
PartnerGivingAnalysisReport,
Expand Down Expand Up @@ -204,15 +207,17 @@ const mocks: Mocks = {
GetPartnerGivingAnalysisIdsForMassSelection: {
partnerGivingAnalysisReport: {
contacts: [
{
id: '01',
},
{
id: '02',
},
{
id: '03',
},
{ id: '01' },
{ id: '02' },
{ id: '03' },
{ id: '04' },
{ id: '05' },
{ id: '06' },
{ id: '07' },
{ id: '08' },
{ id: '09' },
{ id: '10' },
{ id: '11' },
],
},
},
Expand Down Expand Up @@ -447,6 +452,7 @@ describe('PartnerGivingAnalysisReport', () => {
<ThemeProvider theme={theme}>
<GqlMockedProvider<{
GetPartnerGivingAnalysisReport: GetPartnerGivingAnalysisReportQuery;
GetTaskIdsForMassSelection: GetTaskIdsForMassSelectionQuery;
}>
mocks={mocks}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const Components = ({ viewMode = TableViewModeEnum.List }: ComponentsProps) => {
],
pageInfo: {
hasNextPage: true,
endCursor: 'endCursor',
endCursor: `endCursor${requestCount}`,
},
},
};
Expand Down Expand Up @@ -112,14 +112,26 @@ const Components = ({ viewMode = TableViewModeEnum.List }: ComponentsProps) => {
],
pageInfo: {
hasNextPage: false,
endCursor: 'endCursor',
endCursor: 'endCursor3',
},
},
};
}
requestCount++;
return mutationResponse;
},
GetContactIdsForMassSelection: {
contacts: {
nodes: [
{ id: '01' },
{ id: '02' },
{ id: '03' },
{ id: '04' },
{ id: '05' },
{ id: '06' },
],
},
},
}}
onCall={mutationSpy}
>
Expand Down Expand Up @@ -179,25 +191,21 @@ describe('DeleteAppealContactModal', () => {
it('fetches all the appealContacts and matches up the correct ID to send to the API', async () => {
const { getByRole } = render(<Components />);

expect(mutationSpy).toHaveBeenCalledTimes(0);

await waitFor(() => {
expect(mutationSpy).toHaveBeenCalledTimes(8);
});

// Call AppealContacts 4 times getting all contacts.
expect(mutationSpy.mock.calls[0][0].operation.operationName).toEqual(
'AppealContacts',
);
expect(mutationSpy.mock.calls[1][0].operation.operationName).toEqual(
'AppealContacts',
);
expect(mutationSpy.mock.calls[5][0].operation.operationName).toEqual(
'AppealContacts',
);
expect(mutationSpy.mock.calls[6][0].operation.operationName).toEqual(
'AppealContacts',
// Call AppealContacts 3 times getting all contacts.
await waitFor(() =>
expect(mutationSpy).toHaveGraphqlOperation('AppealContacts', {
after: 'endCursor2',
appealId: 'appealId',
}),
);
expect(mutationSpy).toHaveGraphqlOperation('AppealContacts', {
after: null,
appealId: 'appealId',
});
expect(mutationSpy).toHaveGraphqlOperation('AppealContacts', {
after: 'endCursor1',
appealId: 'appealId',
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ export const DeleteAppealContactModal: React.FC<
while (hasNextPage) {
const response = await fetchMore({
variables: {
appealId: appealId,
after: cursor,
first: 100,
},
});

Expand Down

0 comments on commit fb108d5

Please sign in to comment.