-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All this just to get coverage for one branch in clipped-image.tsx! (But also additional code in TSX with coverage, plus a couple fixes)
- Loading branch information
1 parent
f8e912e
commit cfa5fcb
Showing
11 changed files
with
313 additions
and
390 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
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
25 changes: 24 additions & 1 deletion
25
src/app/pages/press/page-context.js → src/app/pages/press/page-context.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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,50 @@ | ||
import React from 'react'; | ||
import {render, screen, waitFor} from '@testing-library/preact'; | ||
import {describe, it} from '@jest/globals'; | ||
import {MemoryRouter} from 'react-router-dom'; | ||
import Press from '~/pages/press/press'; | ||
|
||
const mockPathname = jest.fn(); | ||
const mockNavigate = jest.fn(); | ||
const mockCarousel = ({children}: React.PropsWithChildren<object>) => <div>{children}</div>; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useLocation: () => ({ | ||
get pathname() {return mockPathname();} | ||
}), | ||
Navigate: () => mockNavigate() | ||
})); | ||
jest.mock('~/components/carousel/carousel', () => mockCarousel); | ||
|
||
describe('press page', () => { | ||
it('renders main press page', async () => { | ||
mockPathname.mockReturnValueOnce('').mockReturnValueOnce(''); | ||
render( | ||
<MemoryRouter initialEntries={['/']}> | ||
<Press /> | ||
</MemoryRouter> | ||
); | ||
await screen.findByText('In the press'); | ||
await waitFor(() => expect(document.title).toMatch('- OpenStax')); | ||
document.title = ''; | ||
}); | ||
it('renders press article page', async () => { | ||
render( | ||
<MemoryRouter initialEntries={['/article-slug']}> | ||
<Press /> | ||
</MemoryRouter> | ||
); | ||
expect(await screen.findAllByRole('heading')).toHaveLength(2); | ||
}); | ||
it('tries to Navigate on slash', async () => { | ||
mockPathname.mockReturnValueOnce('/').mockReturnValueOnce(''); | ||
mockNavigate.mockReturnValue(<div>This is navigate</div>); | ||
render( | ||
<MemoryRouter initialEntries={['/']}> | ||
<Press /> | ||
</MemoryRouter> | ||
); | ||
await screen.findByText('This is navigate'); | ||
}); | ||
}); |
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