overleaf/services/web/test/frontend/features/pdf-preview/components/pdf-js-viewer.test.js
Alf Eaton 9f969d07e0 Delete unused PDF-related code (#6334)
* Remove new logs UI code
* Remove unused preview components
* Move metrics file
* Remove Angular PDF controllers
* Move the service worker util functions
* Remove the ide/pdfng folder
* Remove vendored pdf.js
* Remove showNewPdfPreview
* Use mockCompile
* Remove split test code

GitOrigin-RevId: 723b7440c62cda51f6ad8bb9c691900882166d21
2022-03-16 09:03:04 +00:00

37 lines
1.3 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 () {
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()
})
})