-
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
Showing
5 changed files
with
216 additions
and
127 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
62 changes: 41 additions & 21 deletions
62
src/components/Layouts/Primary/NavBar/NavTools/NavTools.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 |
---|---|---|
@@ -1,35 +1,55 @@ | ||
import React from 'react'; | ||
import { MockedProvider } from '@apollo/client/testing'; | ||
import { ThemeProvider } from '@mui/material/styles'; | ||
import { render } from '@testing-library/react'; | ||
import { SetupProvider } from 'src/components/Setup/SetupProvider'; | ||
import { render, waitFor } from '@testing-library/react'; | ||
import TestRouter from '__tests__/util/TestRouter'; | ||
import { useSetupContext } from 'src/components/Setup/SetupProvider'; | ||
import theme from 'src/theme'; | ||
import { getTopBarMultipleMock } from '../../TopBar/TopBar.mock'; | ||
import { NavTools } from './NavTools'; | ||
|
||
jest.mock('next/router', () => ({ | ||
useRouter: () => { | ||
return { | ||
query: { accountListId: 'abc' }, | ||
isReady: true, | ||
}; | ||
}, | ||
})); | ||
jest.mock('src/components/Setup/SetupProvider'); | ||
|
||
const mocks = [getTopBarMultipleMock()]; | ||
const router = { | ||
query: { accountListId: 'abc' }, | ||
isReady: true, | ||
push: jest.fn(), | ||
}; | ||
|
||
describe('AddMenuPanel', () => { | ||
const TestComponent = () => ( | ||
<ThemeProvider theme={theme}> | ||
<TestRouter router={router}> | ||
<MockedProvider mocks={[getTopBarMultipleMock()]} addTypename={false}> | ||
<NavTools /> | ||
</MockedProvider> | ||
</TestRouter> | ||
</ThemeProvider> | ||
); | ||
|
||
describe('NavTools', () => { | ||
it('default', async () => { | ||
const { getByTestId } = render( | ||
<ThemeProvider theme={theme}> | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<SetupProvider> | ||
<NavTools /> | ||
</SetupProvider> | ||
</MockedProvider> | ||
</ThemeProvider>, | ||
); | ||
(useSetupContext as jest.MockedFn<typeof useSetupContext>).mockReturnValue({ | ||
onSetupTour: false, | ||
}); | ||
|
||
const { findByText, getByTestId, getByText } = render(<TestComponent />); | ||
|
||
expect(getByTestId('NavTools')).toBeInTheDocument(); | ||
expect(getByText('Add')).toBeInTheDocument(); | ||
expect(await findByText('John Smith')).toBeInTheDocument(); | ||
}); | ||
|
||
it('hides links during the setup tour', async () => { | ||
(useSetupContext as jest.MockedFn<typeof useSetupContext>).mockReturnValue({ | ||
onSetupTour: true, | ||
}); | ||
|
||
const { queryByText, getByTestId } = render(<TestComponent />); | ||
|
||
expect(getByTestId('NavTools')).toBeInTheDocument(); | ||
expect(queryByText('Add')).not.toBeInTheDocument(); | ||
await waitFor(() => | ||
expect(queryByText('John Smith')).not.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
Oops, something went wrong.