pdf-js-viewer.spec.tsx 2.4 KB

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