pdf-js-viewer.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/react18'
  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.findByRole('region', { name: `Page ${FSI}1${PDI}` })
  28. cy.findByRole('region', { name: `Page ${FSI}2${PDI}` })
  29. cy.findByRole('region', { name: `Page ${FSI}3${PDI}` })
  30. cy.findByRole('region', { name: `Page ${FSI}4${PDI}` }).should('not.exist')
  31. cy.contains('Your Paper')
  32. })
  33. it('renders pages in a "loading" state', function () {
  34. cy.interceptCompile()
  35. const scope = mockScope()
  36. cy.mount(
  37. <EditorProviders scope={scope}>
  38. <PdfPreviewProvider>
  39. <div className="pdf-viewer">
  40. <PdfJsViewer url="/build/123/output.pdf" />
  41. </div>
  42. </PdfPreviewProvider>
  43. </EditorProviders>
  44. )
  45. cy.waitForCompile()
  46. cy.get('.page.loading')
  47. })
  48. it('can be unmounted while loading a document', function () {
  49. cy.interceptCompile()
  50. const scope = mockScope()
  51. cy.mount(
  52. <EditorProviders scope={scope}>
  53. <PdfPreviewProvider>
  54. <div className="pdf-viewer">
  55. <PdfJsViewer url="/build/123/output.pdf?clsiserverid=foo" />
  56. </div>
  57. </PdfPreviewProvider>
  58. </EditorProviders>
  59. )
  60. cy.waitForCompile()
  61. cy.then(() => unmountComponentAtNode(getContainerEl()))
  62. })
  63. it('can be unmounted after loading a document', function () {
  64. cy.interceptCompile()
  65. const scope = mockScope()
  66. cy.mount(
  67. <EditorProviders scope={scope}>
  68. <PdfPreviewProvider>
  69. <div className="pdf-viewer">
  70. <PdfJsViewer url="/build/123/output.pdf?clsiserverid=foo" />
  71. </div>
  72. </PdfPreviewProvider>
  73. </EditorProviders>
  74. )
  75. cy.waitForCompile({ pdf: true })
  76. cy.findByRole('region', { name: `Page ${FSI}1${PDI}` })
  77. cy.then(() => unmountComponentAtNode(getContainerEl()))
  78. })
  79. })