-
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.
Merge pull request #969 from CruGlobal/MPDX-7956-Fix-Email-Addresses-…
…Contact-Name-Link MPDX-7956 Fix Email Addresses Contact Name Link
- Loading branch information
Showing
7 changed files
with
233 additions
and
232 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
pages/accountLists/[accountListId]/tools/fixEmailAddresses/[[...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,104 @@ | ||
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 { ErgonoMockShape } from 'graphql-ergonomock'; | ||
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 { mockInvalidEmailAddressesResponse } from 'src/components/Tool/FixEmailAddresses/FixEmailAddressesMocks'; | ||
import { InvalidAddressesQuery } from 'src/components/Tool/FixMailingAddresses/GetInvalidAddresses.generated'; | ||
import i18n from 'src/lib/i18n'; | ||
import theme from 'src/theme'; | ||
import FixEmailAddressesPage 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 contactId = 'contactId'; | ||
const session = { | ||
expires: '2021-10-28T14:48:20.897Z', | ||
user: { | ||
email: 'Chair Library Bed', | ||
image: null, | ||
name: 'Dung Tapestry', | ||
token: 'superLongJwtString', | ||
}, | ||
}; | ||
const Components = ({ | ||
mockNodes = mockInvalidEmailAddressesResponse, | ||
}: { | ||
mockNodes?: ErgonoMockShape[]; | ||
}) => ( | ||
<ThemeProvider theme={theme}> | ||
<TestRouter> | ||
<GqlMockedProvider<{ | ||
InvalidAddresses: InvalidAddressesQuery; | ||
}> | ||
mocks={{ | ||
GetInvalidEmailAddresses: { | ||
people: { | ||
nodes: mockNodes, | ||
}, | ||
}, | ||
}} | ||
> | ||
<I18nextProvider i18n={i18n}> | ||
<SnackbarProvider> | ||
<FixEmailAddressesPage /> | ||
</SnackbarProvider> | ||
</I18nextProvider> | ||
</GqlMockedProvider> | ||
</TestRouter> | ||
</ThemeProvider> | ||
); | ||
|
||
describe('FixEmailAddressesPage', () => { | ||
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 { getByText, queryByTestId } = render(<Components />); | ||
await waitFor(() => | ||
expect(queryByTestId('loading')).not.toBeInTheDocument(), | ||
); | ||
|
||
const contactName = getByText('Test Contact'); | ||
|
||
expect(contactName).toBeInTheDocument(); | ||
userEvent.click(contactName); | ||
|
||
await waitFor(() => { | ||
expect(pushFn).toHaveBeenCalledWith( | ||
`/accountLists/${accountListId}/tools/fixEmailAddresses/${contactId}`, | ||
); | ||
}); | ||
}); | ||
}); |
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.