pdf-js-viewer.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { EditorProviders } from '../../helpers/editor-providers'
  2. import PdfJsViewer from '../../../../frontend/js/features/pdf-preview/components/pdf-js-viewer'
  3. import { mockScope } from './scope'
  4. import { getContainerEl } from 'cypress/react'
  5. import { unmountComponentAtNode } from 'react-dom'
  6. import { PdfPreviewProvider } from '../../../../frontend/js/features/pdf-preview/components/pdf-preview-provider'
  7. // Unicode directional isolates, added around placeables by @fluent/bundle/esm/resolver
  8. const FSI = '\u2068'
  9. const PDI = '\u2069'
  10. describe('<PdfJSViewer/>', function () {
  11. beforeEach(function () {
  12. cy.interceptEvents()
  13. })
  14. it('loads all PDF pages', function () {
  15. cy.interceptCompile()
  16. const scope = mockScope()
  17. cy.mount(
  18. <EditorProviders scope={scope}>
  19. <PdfPreviewProvider>
  20. <div className="pdf-viewer">
  21. <PdfJsViewer url="/build/123/output.pdf?clsiserverid=foo" />
  22. </div>
  23. </PdfPreviewProvider>
  24. </EditorProviders>
  25. )
  26. cy.waitForCompile({ pdf: true })
  27. cy.findByTestId('pdfjs-viewer-inner').within(() => {
  28. cy.findByLabelText(`Page ${FSI}1${PDI}`)
  29. cy.findByLabelText(`Page ${FSI}2${PDI}`)
  30. cy.findByLabelText(`Page ${FSI}3${PDI}`)
  31. cy.findByLabelText(`Page ${FSI}4${PDI}`).should('not.exist')
  32. })
  33. cy.contains('Your Paper')
  34. })
  35. it('renders pages in a "loading" state', function () {
  36. cy.interceptCompile()
  37. const scope = mockScope()
  38. cy.mount(
  39. <EditorProviders scope={scope}>
  40. <PdfPreviewProvider>
  41. <div className="pdf-viewer">
  42. <PdfJsViewer url="/build/123/output.pdf" />
  43. </div>
  44. </PdfPreviewProvider>
  45. </EditorProviders>
  46. )
  47. cy.waitForCompile()
  48. cy.get('.page.loading')
  49. })
  50. it('can be unmounted while loading a document', function () {
  51. cy.interceptCompile()
  52. const scope = mockScope()
  53. cy.mount(
  54. <EditorProviders scope={scope}>
  55. <PdfPreviewProvider>
  56. <div className="pdf-viewer">
  57. <PdfJsViewer url="/build/123/output.pdf?clsiserverid=foo" />
  58. </div>
  59. </PdfPreviewProvider>
  60. </EditorProviders>
  61. )
  62. cy.waitForCompile()
  63. cy.then(() => unmountComponentAtNode(getContainerEl()))
  64. })
  65. it('can be unmounted after loading a document', function () {
  66. cy.interceptCompile()
  67. const scope = mockScope()
  68. cy.mount(
  69. <EditorProviders scope={scope}>
  70. <PdfPreviewProvider>
  71. <div className="pdf-viewer">
  72. <PdfJsViewer url="/build/123/output.pdf?clsiserverid=foo" />
  73. </div>
  74. </PdfPreviewProvider>
  75. </EditorProviders>
  76. )
  77. cy.waitForCompile({ pdf: true })
  78. cy.findByTestId('pdfjs-viewer-inner').within(() => {
  79. cy.findByLabelText(`Page ${FSI}1${PDI}`)
  80. })
  81. cy.then(() => unmountComponentAtNode(getContainerEl()))
  82. })
  83. })