pdf-js-viewer.spec.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. describe('<PdfJSViewer/>', function () {
  7. beforeEach(function () {
  8. cy.interceptCompile()
  9. cy.interceptEvents()
  10. })
  11. it('loads all PDF pages', function () {
  12. const scope = mockScope()
  13. cy.mount(
  14. <EditorProviders scope={scope}>
  15. <div className="pdf-viewer">
  16. <PdfJsViewer url="/build/123/output.pdf" />
  17. </div>
  18. </EditorProviders>
  19. )
  20. cy.findByLabelText('Page 1')
  21. cy.findByLabelText('Page 2')
  22. cy.findByLabelText('Page 3')
  23. cy.findByLabelText('Page 4').should('not.exist')
  24. cy.contains('Your Paper')
  25. })
  26. it('renders pages in a "loading" state', function () {
  27. const scope = mockScope()
  28. cy.mount(
  29. <EditorProviders scope={scope}>
  30. <div className="pdf-viewer">
  31. <PdfJsViewer url="/build/123/output.pdf" />
  32. </div>
  33. </EditorProviders>
  34. )
  35. cy.findByLabelText('Loading…')
  36. })
  37. it('can be unmounted while loading a document', function () {
  38. const scope = mockScope()
  39. cy.mount(
  40. <EditorProviders scope={scope}>
  41. <div className="pdf-viewer">
  42. <PdfJsViewer url="/build/123/output.pdf" />
  43. </div>
  44. </EditorProviders>
  45. )
  46. cy.then(() => unmountComponentAtNode(getContainerEl()))
  47. })
  48. it('can be unmounted after loading a document', function () {
  49. const scope = mockScope()
  50. cy.mount(
  51. <EditorProviders scope={scope}>
  52. <div className="pdf-viewer">
  53. <PdfJsViewer url="/build/123/output.pdf" />
  54. </div>
  55. </EditorProviders>
  56. )
  57. cy.findByLabelText('Page 1')
  58. cy.then(() => unmountComponentAtNode(getContainerEl()))
  59. })
  60. })