-
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.
- Loading branch information
1 parent
e08a629
commit 6a5db31
Showing
6 changed files
with
356 additions
and
15 deletions.
There are no files selected for viewing
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
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,165 @@ | ||
import React from 'react'; | ||
import { ThemeProvider } from '@mui/material/styles'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { SnackbarProvider } from 'notistack'; | ||
import TestRouter from '__tests__/util/TestRouter'; | ||
import { GqlMockedProvider } from '__tests__/util/graphqlMocking'; | ||
import { ContactsProvider } from 'src/components/Contacts/ContactsContext/ContactsContext'; | ||
import theme from 'src/theme'; | ||
import { GetPersonDuplicatesQuery } from './GetPersonDuplicates.generated'; | ||
import MergePeople from './MergePeople'; | ||
import { getPersonDuplicatesMocks } from './PersonDuplicatesMock'; | ||
|
||
const accountListId = '123'; | ||
|
||
const setContactFocus = jest.fn(); | ||
const mockEnqueue = jest.fn(); | ||
|
||
jest.mock('notistack', () => ({ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
...jest.requireActual('notistack'), | ||
useSnackbar: () => { | ||
return { | ||
enqueueSnackbar: mockEnqueue, | ||
}; | ||
}, | ||
})); | ||
|
||
interface MergePeopleWrapperProps { | ||
mutationSpy?: () => void; | ||
} | ||
|
||
const MergePeopleWrapper: React.FC<MergePeopleWrapperProps> = ({ | ||
mutationSpy, | ||
}) => { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<TestRouter> | ||
<GqlMockedProvider<{ | ||
GetPersonDuplicates: GetPersonDuplicatesQuery; | ||
}> | ||
mocks={getPersonDuplicatesMocks} | ||
onCall={mutationSpy} | ||
> | ||
<ContactsProvider | ||
activeFilters={{}} | ||
setActiveFilters={() => {}} | ||
starredFilter={{}} | ||
setStarredFilter={() => {}} | ||
filterPanelOpen={false} | ||
setFilterPanelOpen={() => {}} | ||
contactId={[]} | ||
searchTerm={''} | ||
> | ||
<MergePeople | ||
accountListId={accountListId} | ||
setContactFocus={setContactFocus} | ||
/> | ||
</ContactsProvider> | ||
</GqlMockedProvider> | ||
</TestRouter> | ||
</ThemeProvider> | ||
); | ||
}; | ||
|
||
describe('Tools - MergePeople', () => { | ||
it('should render', async () => { | ||
const { findByText, getByTestId } = render(<MergePeopleWrapper />); | ||
|
||
expect(await findByText('Merge People')).toBeInTheDocument(); | ||
expect(getByTestId('PeopleMergeDescription').textContent).toMatch( | ||
'You have 55 possible duplicate people', | ||
); | ||
}); | ||
|
||
it('should merge people', async () => { | ||
const mutationSpy = jest.fn(); | ||
|
||
const { getByText, queryAllByTestId, findByText, getByRole } = render( | ||
<SnackbarProvider> | ||
<MergePeopleWrapper mutationSpy={mutationSpy} /> | ||
</SnackbarProvider>, | ||
); | ||
|
||
await waitFor(() => | ||
expect(queryAllByTestId('MergeContactPair')).toHaveLength(2), | ||
); | ||
expect(getByText('(Siebel)')).toBeInTheDocument(); | ||
|
||
expect( | ||
getByRole('button', { name: 'Confirm and Continue' }), | ||
).toBeDisabled(); | ||
userEvent.click(getByText('555-555-5555')); | ||
expect(await findByText('Use this one')).toBeInTheDocument(); | ||
expect( | ||
getByRole('button', { name: 'Confirm and Continue' }), | ||
).not.toBeDisabled(); | ||
|
||
userEvent.click(getByRole('button', { name: 'Confirm and Continue' })); | ||
await waitFor(() => | ||
expect(mockEnqueue).toHaveBeenCalledWith('Success!', { | ||
variant: 'success', | ||
}), | ||
); | ||
|
||
const mergeCalls = mutationSpy.mock.calls | ||
.map(([{ operation }]) => operation) | ||
.filter(({ operationName }) => operationName === 'MergePeopleBulk'); | ||
expect(mergeCalls).toHaveLength(1); | ||
expect(mergeCalls[0].variables).toEqual({ | ||
input: { | ||
winnersAndLosers: [ | ||
{ | ||
loserId: 'person-1.5', | ||
winnerId: 'person-1', | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
it('should ignore contacts', async () => { | ||
const mutationSpy = jest.fn(); | ||
|
||
const { queryByText, queryAllByTestId, findByText, getByRole } = render( | ||
<SnackbarProvider> | ||
<MergePeopleWrapper mutationSpy={mutationSpy} /> | ||
</SnackbarProvider>, | ||
); | ||
|
||
await waitFor(() => | ||
expect(queryAllByTestId('MergeContactPair')).toHaveLength(2), | ||
); | ||
const confirmButton = getByRole('button', { name: 'Confirm and Continue' }); | ||
|
||
expect(confirmButton).toBeDisabled(); | ||
userEvent.click(queryAllByTestId('rightButton')[0]); | ||
expect(await findByText('Use this one')).toBeInTheDocument(); | ||
userEvent.click(queryAllByTestId('ignoreButton')[0]); | ||
expect(queryByText('Use this one')).not.toBeInTheDocument(); | ||
expect( | ||
getByRole('button', { name: 'Confirm and Continue' }), | ||
).not.toBeDisabled(); | ||
}); | ||
|
||
describe('setContactFocus()', () => { | ||
it('should open up contact details', async () => { | ||
const mutationSpy = jest.fn(); | ||
const { findByText, queryByTestId } = render( | ||
<MergePeopleWrapper mutationSpy={mutationSpy} />, | ||
); | ||
await waitFor(() => | ||
expect(queryByTestId('loading')).not.toBeInTheDocument(), | ||
); | ||
expect(setContactFocus).not.toHaveBeenCalled(); | ||
|
||
const contactName = await findByText('Ellie Francisco'); | ||
|
||
expect(contactName).toBeInTheDocument(); | ||
userEvent.click(contactName); | ||
expect(setContactFocus).toHaveBeenCalledWith('contact-2'); | ||
}); | ||
}); | ||
}); |
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.