pdf-compile-time.test.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { render, screen } from '@testing-library/react'
  2. import { expect } from 'chai'
  3. import PdfCompileTime from '../../../../frontend/js/features/pdf-preview/components/pdf-compile-time'
  4. import { DetachCompileContext } from '../../../../frontend/js/shared/context/detach-compile-context'
  5. function renderComponent(compileTimeClientE2E?: number) {
  6. return render(
  7. <DetachCompileContext.Provider
  8. value={
  9. {
  10. compiling: false,
  11. deliveryLatencies: {
  12. compileTimeClientE2E,
  13. },
  14. } as any
  15. }
  16. >
  17. <PdfCompileTime />
  18. </DetachCompileContext.Provider>
  19. )
  20. }
  21. describe('<PdfCompileTime />', function () {
  22. it('does not render when compile duration is missing', function () {
  23. renderComponent(undefined)
  24. expect(screen.queryByText('1.2 s')).to.not.exist
  25. })
  26. it('renders when compile duration is available', function () {
  27. renderComponent(1200)
  28. screen.getByText('1.2 s')
  29. })
  30. it('renders a running timer while compiling', function () {
  31. render(
  32. <DetachCompileContext.Provider
  33. value={
  34. {
  35. compiling: true,
  36. deliveryLatencies: {},
  37. } as any
  38. }
  39. >
  40. <PdfCompileTime />
  41. </DetachCompileContext.Provider>
  42. )
  43. screen.getByText('0.0 s')
  44. })
  45. })