Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPDX-8443] Ergonomock aliases #1199

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"eslint-plugin-react": "^7.31.8",
"full-icu": "^1.5.0",
"glob": "^8.0.3",
"graphql-ergonomock": "npm:@cruglobal/graphql-ergonomock@^1.2.1",
"graphql-ergonomock": "npm:@cruglobal/graphql-ergonomock@^1.2.2",
"husky": "^8.0.1",
"i18next-parser": "^9.0.2",
"jest": "^29.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import userEvent from '@testing-library/user-event';
import { SnackbarProvider } from 'notistack';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { GetDesignationAccountsQuery } from 'src/components/EditDonationModal/EditDonationModal.generated';
import { GetDonorAccountsQuery } from 'src/components/common/DonorAccountAutocomplete/DonorAccountAutocomplete.generated';
import theme from '../../../../../../../../theme';
import { AddDonation } from './AddDonation';
import { AddDonationMutation } from './AddDonation.generated';
Expand Down Expand Up @@ -58,7 +59,11 @@ describe('AddDonation', () => {
<LocalizationProvider dateAdapter={AdapterLuxon}>
<ThemeProvider theme={theme}>
<SnackbarProvider>
<GqlMockedProvider<{ AddDonation: AddDonationMutation }>
<GqlMockedProvider<{
AddDonation: AddDonationMutation;
GetDesignationAccounts: GetDesignationAccountsQuery;
GetDonorAccounts: GetDonorAccountsQuery;
}>
onCall={mutationSpy}
mocks={{
GetDonationModal: {
Expand Down Expand Up @@ -91,8 +96,7 @@ describe('AddDonation', () => {
accountListDonorAccounts: [
{
id: 'donor-acc-1',
accountNumber: 'acct-01',
displayName: 'Cool Donor Account',
name: 'Cool Donor Account',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ import React from 'react';
import { ThemeProvider } from '@mui/material/styles';
import userEvent from '@testing-library/user-event';
import { ApolloErgonoMockMap } from 'graphql-ergonomock';
import { DeepPartial } from 'ts-essentials';
import TestRouter from '__tests__/util/TestRouter';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { render, waitFor } from '__tests__/util/testingLibraryReactMock';
import { LoadCoachingListQuery } from 'src/components/Coaching/LoadCoachingList.generated';
import theme from 'src/theme';
import { GetToolNotificationsQuery } from './GetToolNotifcations.generated';
import NavMenu from './NavMenu';

const accountListId = 'test121';

interface TestComponentProps {
router?: Partial<NextRouter>;
mocks?: ApolloErgonoMockMap;
mocks?: ApolloErgonoMockMap &
DeepPartial<{
GetToolNotifications: GetToolNotificationsQuery;
LoadCoachingList: LoadCoachingListQuery;
}>;
}

const TestComponent: React.FC<TestComponentProps> = ({ router, mocks }) => (
Expand Down Expand Up @@ -192,18 +199,13 @@ describe('NavMenu', () => {
<TestComponent
mocks={{
GetToolNotifications: {
contacts: {
totalCount: 0,
},
people: {
totalCount: 0,
},
contactDuplicates: {
totalCount: 0,
},
personDuplicates: {
totalCount: 0,
},
fixCommitmentInfo: { totalCount: 0 },
fixMailingAddresses: { totalCount: 0 },
fixSendNewsletter: { totalCount: 0 },
fixEmailAddresses: { totalCount: 0 },
fixPhoneNumbers: { totalCount: 0 },
mergeContacts: { totalCount: 0 },
mergePeople: { totalCount: 0 },
},
}}
/>,
Expand All @@ -227,18 +229,13 @@ describe('NavMenu', () => {
<TestComponent
mocks={{
GetToolNotifications: {
contacts: {
totalCount: 1,
},
people: {
totalCount: 1,
},
contactDuplicates: {
totalCount: 1,
},
personDuplicates: {
totalCount: 1,
},
fixCommitmentInfo: { totalCount: 1 },
fixMailingAddresses: { totalCount: 1 },
fixSendNewsletter: { totalCount: 1 },
fixEmailAddresses: { totalCount: 1 },
fixPhoneNumbers: { totalCount: 1 },
mergeContacts: { totalCount: 1 },
mergePeople: { totalCount: 1 },
},
}}
/>,
Expand All @@ -263,18 +260,13 @@ describe('NavMenu', () => {
<TestComponent
mocks={{
GetToolNotifications: {
contacts: {
totalCount: 30,
},
people: {
totalCount: 30,
},
contactDuplicates: {
totalCount: 130,
},
personDuplicates: {
totalCount: 30,
},
fixCommitmentInfo: { totalCount: 30 },
fixMailingAddresses: { totalCount: 30 },
fixSendNewsletter: { totalCount: 30 },
fixEmailAddresses: { totalCount: 30 },
fixPhoneNumbers: { totalCount: 30 },
mergeContacts: { totalCount: 130 },
mergePeople: { totalCount: 30 },
},
}}
/>,
Expand Down
18 changes: 7 additions & 11 deletions src/components/Tool/Appeal/InitialPage/Appeals.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const testAppeal = {

const mocks = {
GetAppeals: {
appeals: {
primaryAppeal: {
nodes: [testAppeal],
totalCount: 1,
},
regularAppeals: {
nodes: [testAppeal],
totalCount: 1,
pageInfo: {
Expand Down Expand Up @@ -75,11 +79,7 @@ describe('AppealsTest', () => {
<SnackbarProvider>
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<GqlMockedProvider<{ GetAppeals: GetAppealsQuery }>
// @ts-expect-error graphql-ergonomock does not handle renamed fields correctly, so
// the mock field name doesn't match the query field name
mocks={mocks}
>
<GqlMockedProvider<{ GetAppeals: GetAppealsQuery }> mocks={mocks}>
<Appeals accountListId={accountListId} />
</GqlMockedProvider>
</TestRouter>
Expand All @@ -99,11 +99,7 @@ describe('AppealsTest', () => {
<SnackbarProvider>
<ThemeProvider theme={theme}>
<TestRouter router={router}>
<GqlMockedProvider<{ GetAppeals: GetAppealsQuery }>
// @ts-expect-error graphql-ergonomock does not handle renamed fields correctly, so
// the mock field name doesn't match the query field name
mocks={mocks}
>
<GqlMockedProvider<{ GetAppeals: GetAppealsQuery }> mocks={mocks}>
<Appeals accountListId={accountListId} />
</GqlMockedProvider>
</TestRouter>
Expand Down
15 changes: 7 additions & 8 deletions src/components/Tool/Home/ToolsHome.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ const accountListId = 'account-list-1';

const mocks = {
GetToolNotifications: {
// graphql-ergonomock doesn't handle renamed fields, so we have to mock
// using the name of the field in the GraphQL schema, not the renamed field
contacts: { totalCount: 2 },
people: { totalCount: 4 },
contactDuplicates: { totalCount: 6 },
personDuplicates: { totalCount: 100 },
fixCommitmentInfo: { totalCount: 2 },
fixMailingAddresses: { totalCount: 2 },
fixSendNewsletter: { totalCount: 2 },
fixEmailAddresses: { totalCount: 4 },
fixPhoneNumbers: { totalCount: 4 },
mergeContacts: { totalCount: 6 },
mergePeople: { totalCount: 100 },
},
};

Expand All @@ -30,8 +31,6 @@ const TestComponent: React.FC<TestComponentProps> = ({ setup = false }) => (
<GqlMockedProvider<{
GetToolNotifications: GetToolNotificationsQuery;
}>
// @ts-expect-error graphql-ergonomock does not handle renamed fields correctly, so
// the mock field name doesn't match the query field name
mocks={mocks}
>
<TestRouter
Expand Down
15 changes: 7 additions & 8 deletions src/components/Tool/NavToolList/NavToolList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ const router = {

const mocks = {
GetToolNotifications: {
// graphql-ergonomock doesn't handle renamed fields, so we have to mock
// using the name of the field in the GraphQL schema, not the renamed field
contacts: { totalCount: 2 },
people: { totalCount: 4 },
contactDuplicates: { totalCount: 6 },
personDuplicates: { totalCount: 10 },
fixCommitmentInfo: { totalCount: 2 },
fixMailingAddresses: { totalCount: 2 },
fixSendNewsletter: { totalCount: 2 },
fixEmailAddresses: { totalCount: 4 },
fixPhoneNumbers: { totalCount: 4 },
mergeContacts: { totalCount: 6 },
mergePeople: { totalCount: 10 },
},
};

Expand All @@ -34,8 +35,6 @@ const TestComponent = () => (
<GqlMockedProvider<{
GetToolNotifications: GetToolNotificationsQuery;
}>
// @ts-expect-error graphql-ergonomock does not handle renamed fields correctly, so
// the mock field name doesn't match the query field name
mocks={mocks}
>
<NavToolList toggle={toggleMock} isOpen={true} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ describe('UserPreferenceProvider', () => {
user: {
id: userId,
preferences: {
// @ts-expect-error graphql-ergonomock does not handle renamed fields correctly, so
// the mock field name doesn't match the query field name
localeDisplay: 'es',
locale: 'es',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const onChange = jest.fn();
const mocks = {
GetDonorAccounts: {
accountListDonorAccounts: [
{ id: 'donor-1', displayName: 'Donor 1' },
{ id: 'donor-2', displayName: 'Donor 2' },
{ id: 'donor-3', displayName: 'Donor 3' },
{ id: 'donor-1', name: 'Donor 1' },
{ id: 'donor-2', name: 'Donor 2' },
{ id: 'donor-3', name: 'Donor 3' },
],
},
};
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11711,14 +11711,14 @@ __metadata:
languageName: node
linkType: hard

"graphql-ergonomock@npm:@cruglobal/graphql-ergonomock@^1.2.1":
version: 1.2.1
resolution: "@cruglobal/graphql-ergonomock@npm:1.2.1"
"graphql-ergonomock@npm:@cruglobal/graphql-ergonomock@^1.2.2":
version: 1.2.2
resolution: "@cruglobal/graphql-ergonomock@npm:1.2.2"
dependencies:
fast-json-stable-stringify: ^2.1.0
graphql: ^16.9.0
seedrandom: ^3.0.5
checksum: 79bbf1a38a6b3ebeebc7bb6d1222934b85157f76559407cbabbcd6794eeece7ba6ca50a737f2959cec516b244c62eae3b36a617ac109c9ef3c75e14ca577f525
checksum: 04c6a4d03dff7d718e6978c7c93fc506f9cf2f2eff0c905c5cbbab382dc5358e1d91ad651dc5f3a3bb691246ff3fa491d0b28ce48fa34c9a513310e8446409c8
languageName: node
linkType: hard

Expand Down Expand Up @@ -15110,7 +15110,7 @@ __metadata:
full-icu: ^1.5.0
glob: ^8.0.3
graphql: ^16.9.0
graphql-ergonomock: "npm:@cruglobal/graphql-ergonomock@^1.2.1"
graphql-ergonomock: "npm:@cruglobal/graphql-ergonomock@^1.2.2"
graphql-tag: ^2.12.6
husky: ^8.0.1
i18next: ^21.9.2
Expand Down
Loading