mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
2bf422b76d
Only use the React compiler when showNewPdfPreview is set GitOrigin-RevId: 24bf8dc6a830e670ee8dc30b8e0329127de1a1a8
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
import { expect } from 'chai'
|
|
import { screen } from '@testing-library/react'
|
|
import path from 'path'
|
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
|
import { pathToFileURL } from 'url'
|
|
import PdfJsViewer from '../../../../../frontend/js/features/pdf-preview/components/pdf-js-viewer'
|
|
|
|
const example = pathToFileURL(
|
|
path.join(__dirname, '../fixtures/test-example.pdf')
|
|
).toString()
|
|
|
|
describe('<PdfJSViewer/>', function () {
|
|
beforeEach(function () {
|
|
window.showNewPdfPreview = true
|
|
})
|
|
|
|
afterEach(function () {
|
|
window.showNewPdfPreview = undefined
|
|
})
|
|
|
|
it('loads all PDF pages', async function () {
|
|
renderWithEditorContext(<PdfJsViewer url={example} />)
|
|
|
|
await screen.findByLabelText('Page 1')
|
|
await screen.findByLabelText('Page 2')
|
|
await screen.findByLabelText('Page 3')
|
|
expect(screen.queryByLabelText('Page 4')).to.not.exist
|
|
})
|
|
|
|
it('renders pages in a "loading" state', async function () {
|
|
renderWithEditorContext(<PdfJsViewer url={example} />)
|
|
await screen.findByLabelText('Loading…')
|
|
})
|
|
|
|
it('can be unmounted while loading a document', async function () {
|
|
const { unmount } = renderWithEditorContext(<PdfJsViewer url={example} />)
|
|
unmount()
|
|
})
|
|
|
|
it('can be unmounted after loading a document', async function () {
|
|
const { unmount } = renderWithEditorContext(<PdfJsViewer url={example} />)
|
|
await screen.findByLabelText('Page 1')
|
|
unmount()
|
|
})
|
|
})
|