pdf-js-viewer.spec.tsx 2.1 KB

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