-
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.
[No Jira] Fix Phone Numbers - Contact Links Work (#1005)
* Make contact link work, move error messages, styling improvements * Make contact go to details tab and add test
- Loading branch information
1 parent
5750ca7
commit e3e6a5a
Showing
10 changed files
with
229 additions
and
82 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
pages/accountLists/[accountListId]/tools/fix/phoneNumbers/[[...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,97 @@ | ||
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 { GetInvalidPhoneNumbersMocks } from 'src/components/Tool/FixPhoneNumbers/FixPhoneNumbersMocks'; | ||
import { GetInvalidPhoneNumbersQuery } from 'src/components/Tool/FixPhoneNumbers/GetInvalidPhoneNumbers.generated'; | ||
import i18n from 'src/lib/i18n'; | ||
import theme from 'src/theme'; | ||
import FixPhoneNumbersPage 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> | ||
<I18nextProvider i18n={i18n}> | ||
<SnackbarProvider> | ||
<GqlMockedProvider<{ | ||
GetInvalidPhoneNumbers: GetInvalidPhoneNumbersQuery; | ||
}> | ||
mocks={GetInvalidPhoneNumbersMocks} | ||
> | ||
<FixPhoneNumbersPage /> | ||
</GqlMockedProvider> | ||
</SnackbarProvider> | ||
</I18nextProvider> | ||
</TestRouter> | ||
</ThemeProvider> | ||
); | ||
|
||
describe('FixPhoneNumbersPage', () => { | ||
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('LoadingSpinner')).not.toBeInTheDocument(), | ||
); | ||
const contactName = await findByText('Test Contact'); | ||
|
||
expect(contactName).toBeInTheDocument(); | ||
userEvent.click(contactName); | ||
|
||
await waitFor(() => { | ||
expect(pushFn).toHaveBeenCalledWith( | ||
`/accountLists/${accountListId}/tools/fix/phoneNumbers/${GetInvalidPhoneNumbersMocks.GetInvalidPhoneNumbers.people.nodes[0].id}`, | ||
); | ||
}); | ||
}); | ||
|
||
it('should show errors', async () => { | ||
const { findAllByRole, findByText } = render(<Components />); | ||
|
||
userEvent.clear((await findAllByRole('textbox'))[0]); | ||
expect(await findByText('This field is required')).toBeInTheDocument(); | ||
}); | ||
}); |
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
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.