pdf-js-viewer.spec.tsx 1.7 KB

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