mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 23:36:00 -05:00
be45aec5b5
GitOrigin-RevId: 739e1c1fccaa583bd3e13da96802b8c6d4164ad8
104 lines
2.7 KiB
TypeScript
104 lines
2.7 KiB
TypeScript
import '../../helpers/bootstrap-3'
|
|
import { EditorProviders } from '../../helpers/editor-providers'
|
|
import PdfJsViewer from '../../../../frontend/js/features/pdf-preview/components/pdf-js-viewer'
|
|
import { mockScope } from './scope'
|
|
import { getContainerEl } from 'cypress/react'
|
|
import { unmountComponentAtNode } from 'react-dom'
|
|
import { PdfPreviewProvider } from '../../../../frontend/js/features/pdf-preview/components/pdf-preview-provider'
|
|
|
|
// Unicode directional isolates, added around placeables by @fluent/bundle/esm/resolver
|
|
const FSI = '\u2068'
|
|
const PDI = '\u2069'
|
|
|
|
describe('<PdfJSViewer/>', function () {
|
|
beforeEach(function () {
|
|
cy.interceptEvents()
|
|
})
|
|
|
|
it('loads all PDF pages', function () {
|
|
cy.interceptCompile()
|
|
|
|
const scope = mockScope()
|
|
|
|
cy.mount(
|
|
<EditorProviders scope={scope}>
|
|
<PdfPreviewProvider>
|
|
<div className="pdf-viewer">
|
|
<PdfJsViewer url="/build/123/output.pdf" />
|
|
</div>
|
|
</PdfPreviewProvider>
|
|
</EditorProviders>
|
|
)
|
|
|
|
cy.waitForCompile({ pdf: true })
|
|
|
|
cy.findByRole('region', { name: `Page ${FSI}1${PDI}` })
|
|
cy.findByRole('region', { name: `Page ${FSI}2${PDI}` })
|
|
cy.findByRole('region', { name: `Page ${FSI}3${PDI}` })
|
|
cy.findByRole('region', { name: `Page ${FSI}4${PDI}` }).should('not.exist')
|
|
|
|
cy.contains('Your Paper')
|
|
})
|
|
|
|
it('renders pages in a "loading" state', function () {
|
|
cy.interceptCompile()
|
|
|
|
const scope = mockScope()
|
|
|
|
cy.mount(
|
|
<EditorProviders scope={scope}>
|
|
<PdfPreviewProvider>
|
|
<div className="pdf-viewer">
|
|
<PdfJsViewer url="/build/123/output.pdf" />
|
|
</div>
|
|
</PdfPreviewProvider>
|
|
</EditorProviders>
|
|
)
|
|
|
|
cy.waitForCompile()
|
|
|
|
cy.get('.page.loading')
|
|
})
|
|
|
|
it('can be unmounted while loading a document', function () {
|
|
cy.interceptCompile()
|
|
|
|
const scope = mockScope()
|
|
|
|
cy.mount(
|
|
<EditorProviders scope={scope}>
|
|
<PdfPreviewProvider>
|
|
<div className="pdf-viewer">
|
|
<PdfJsViewer url="/build/123/output.pdf" />
|
|
</div>
|
|
</PdfPreviewProvider>
|
|
</EditorProviders>
|
|
)
|
|
|
|
cy.waitForCompile()
|
|
|
|
cy.then(() => unmountComponentAtNode(getContainerEl()))
|
|
})
|
|
|
|
it('can be unmounted after loading a document', function () {
|
|
cy.interceptCompile()
|
|
|
|
const scope = mockScope()
|
|
|
|
cy.mount(
|
|
<EditorProviders scope={scope}>
|
|
<PdfPreviewProvider>
|
|
<div className="pdf-viewer">
|
|
<PdfJsViewer url="/build/123/output.pdf" />
|
|
</div>
|
|
</PdfPreviewProvider>
|
|
</EditorProviders>
|
|
)
|
|
|
|
cy.waitForCompile({ pdf: true })
|
|
|
|
cy.findByRole('region', { name: `Page ${FSI}1${PDI}` })
|
|
|
|
cy.then(() => unmountComponentAtNode(getContainerEl()))
|
|
})
|
|
})
|