-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MPDX-8005 Merge People UI, Styling & merge mutations (#966)
MergePeople UI, reusable components and mergePeopleBulk proxy mutation
- Loading branch information
1 parent
4b589bf
commit b3e0d9a
Showing
17 changed files
with
711 additions
and
592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
pages/accountLists/[accountListId]/tools/mergePeople/[[...contactId]].page.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useRouter } from 'next/router'; | ||
import { ThemeProvider } from '@mui/material/styles'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { getSession } from 'next-auth/react'; | ||
import { SnackbarProvider } from 'notistack'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import TestRouter from '__tests__/util/TestRouter'; | ||
import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; | ||
import { GetPersonDuplicatesQuery } from 'src/components/Tool/MergePeople/GetPersonDuplicates.generated'; | ||
import { getPersonDuplicatesMocks } from 'src/components/Tool/MergePeople/PersonDuplicatesMock'; | ||
import i18n from 'src/lib/i18n'; | ||
import theme from 'src/theme'; | ||
import MergePeoplePage from './[[...contactId]].page'; | ||
|
||
jest.mock('next-auth/react'); | ||
jest.mock('next/router', () => ({ | ||
useRouter: jest.fn(), | ||
})); | ||
jest.mock('src/lib/helpScout', () => ({ | ||
suggestArticles: jest.fn(), | ||
})); | ||
jest.mock('notistack', () => ({ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
...jest.requireActual('notistack'), | ||
useSnackbar: () => { | ||
return { | ||
enqueueSnackbar: jest.fn(), | ||
}; | ||
}, | ||
})); | ||
|
||
const pushFn = jest.fn(); | ||
const accountListId = 'account-list-1'; | ||
const session = { | ||
expires: '2021-10-28T14:48:20.897Z', | ||
user: { | ||
email: 'Chair Library Bed', | ||
image: null, | ||
name: 'Dung Tapestry', | ||
token: 'superLongJwtString', | ||
}, | ||
}; | ||
const Components = () => ( | ||
<ThemeProvider theme={theme}> | ||
<TestRouter> | ||
<GqlMockedProvider<{ | ||
GetPersonDuplicates: GetPersonDuplicatesQuery; | ||
}> | ||
mocks={getPersonDuplicatesMocks} | ||
> | ||
<I18nextProvider i18n={i18n}> | ||
<SnackbarProvider> | ||
<MergePeoplePage /> | ||
</SnackbarProvider> | ||
</I18nextProvider> | ||
</GqlMockedProvider> | ||
</TestRouter> | ||
</ThemeProvider> | ||
); | ||
|
||
describe('MergePeoplePage', () => { | ||
beforeEach(() => { | ||
(getSession as jest.Mock).mockResolvedValue(session); | ||
(useRouter as jest.Mock).mockReturnValue({ | ||
query: { | ||
accountListId, | ||
}, | ||
isReady: true, | ||
push: pushFn, | ||
}); | ||
}); | ||
|
||
it('should open up contact details', async () => { | ||
const { findByText, queryByTestId } = render(<Components />); | ||
await waitFor(() => | ||
expect(queryByTestId('loading')).not.toBeInTheDocument(), | ||
); | ||
|
||
const contactName = await findByText('John Doe'); | ||
|
||
expect(contactName).toBeInTheDocument(); | ||
userEvent.click(contactName); | ||
|
||
await waitFor(() => { | ||
expect(pushFn).toHaveBeenCalledWith( | ||
`/accountLists/${accountListId}/tools/mergePeople/${'contact-1'}`, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
extend type Mutation { | ||
mergePeopleBulk(input: MergePeopleBulkInput!): [ID!]! | ||
} | ||
|
||
input MergePeopleBulkInput { | ||
winnersAndLosers: [WinnersAndLosers!]! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Resolvers } from '../../graphql-rest.page.generated'; | ||
|
||
const MergePeopleBulkResolvers: Resolvers = { | ||
Mutation: { | ||
mergePeopleBulk: ( | ||
_source, | ||
{ input: { winnersAndLosers } }, | ||
{ dataSources }, | ||
) => { | ||
return dataSources.mpdxRestApi.mergePeopleBulk(winnersAndLosers); | ||
}, | ||
}, | ||
}; | ||
|
||
export { MergePeopleBulkResolvers }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.