-
Notifications
You must be signed in to change notification settings - Fork 5
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
19b332e
commit 080a5aa
Showing
3 changed files
with
67 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import React from 'react' | ||
import HomePage from './HomePage' | ||
import { makeMockPortal, makeMockPortalStudy } from './test-utils/mocking-utils' | ||
import { useNavContext } from './navbar/NavContextProvider' | ||
import { setupRouterTest } from './test-utils/router-testing-utils' | ||
|
||
jest.mock('./navbar/NavContextProvider') | ||
|
||
describe('HomePage', () => { | ||
it('renders the study list in alphabetical order', () => { | ||
const portalList = [ | ||
makeMockPortal('Z Portal', [ | ||
makeMockPortalStudy('Z Study', 'studyZ'), | ||
makeMockPortalStudy('A Study', 'studyA'), | ||
makeMockPortalStudy('M Study 1', 'studyM1') | ||
]), | ||
makeMockPortal('A Portal', [ | ||
makeMockPortalStudy('M Study 2', 'studyM2') | ||
]) | ||
] | ||
|
||
const mockContextValue = { | ||
breadCrumbs: [], | ||
setBreadCrumbs: jest.fn(), | ||
portalList, | ||
setPortalList: jest.fn() | ||
} | ||
|
||
;(useNavContext as jest.Mock).mockReturnValue(mockContextValue) | ||
|
||
const { RoutedComponent } = setupRouterTest(<HomePage/>) | ||
render(RoutedComponent) | ||
|
||
expect(screen.getByText('My Studies')).toBeInTheDocument() | ||
|
||
const studies = screen.queryAllByText(/Study/) | ||
|
||
expect(studies[0]).toHaveTextContent('M Study 2') // the study from "A Portal" | ||
expect(studies[1]).toHaveTextContent('A Study') // the remaining three studies from "Z Portal" | ||
expect(studies[2]).toHaveTextContent('M Study 1') | ||
expect(studies[3]).toHaveTextContent('Z Study') | ||
}) | ||
}) |
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