pdf-js-viewer.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { expect } from 'chai'
  2. import { screen } from '@testing-library/react'
  3. import path from 'path'
  4. import { renderWithEditorContext } from '../../../helpers/render-with-context'
  5. import { pathToFileURL } from 'url'
  6. import PdfJsViewer from '../../../../../frontend/js/features/pdf-preview/components/pdf-js-viewer'
  7. const example = pathToFileURL(
  8. path.join(__dirname, '../fixtures/test-example.pdf')
  9. ).toString()
  10. describe('<PdfJSViewer/>', function () {
  11. it('loads all PDF pages', async function () {
  12. renderWithEditorContext(<PdfJsViewer url={example} />)
  13. await screen.findByLabelText('Page 1')
  14. await screen.findByLabelText('Page 2')
  15. await screen.findByLabelText('Page 3')
  16. expect(screen.queryByLabelText('Page 4')).to.not.exist
  17. })
  18. it('renders pages in a "loading" state', async function () {
  19. renderWithEditorContext(<PdfJsViewer url={example} />)
  20. await screen.findByLabelText('Loading…')
  21. })
  22. it('can be unmounted while loading a document', async function () {
  23. const { unmount } = renderWithEditorContext(<PdfJsViewer url={example} />)
  24. unmount()
  25. })
  26. it('can be unmounted after loading a document', async function () {
  27. const { unmount } = renderWithEditorContext(<PdfJsViewer url={example} />)
  28. await screen.findByLabelText('Page 1')
  29. unmount()
  30. })
  31. })