pdf-preview-detached-root.spec.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import PdfPreviewDetachedRoot from '../../../../frontend/js/features/pdf-preview/components/pdf-preview-detached-root'
  2. import { detachChannel, testDetachChannel } from '../../helpers/detach-channel'
  3. describe('<PdfPreviewDetachedRoot/>', function () {
  4. beforeEach(function () {
  5. window.metaAttributesCache.set('ol-user', { id: 'user1' })
  6. window.metaAttributesCache.set('ol-project_id', 'project1')
  7. window.metaAttributesCache.set('ol-detachRole', 'detached')
  8. window.metaAttributesCache.set('ol-projectName', 'Project Name')
  9. window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
  10. window.metaAttributesCache.set('ol-compileSettings', {
  11. reducedWarningThreshold: 'default',
  12. compileTimeout: 240,
  13. })
  14. cy.interceptEvents()
  15. })
  16. it('syncs compiling state', function () {
  17. cy.interceptCompile()
  18. cy.mount(<PdfPreviewDetachedRoot />)
  19. cy.wrap(null).then(() => {
  20. testDetachChannel.postMessage({
  21. role: 'detacher',
  22. event: 'connected',
  23. })
  24. testDetachChannel.postMessage({
  25. role: 'detacher',
  26. event: 'state-compiling',
  27. data: { value: true },
  28. })
  29. })
  30. cy.findByRole('button', { name: 'Compiling…' })
  31. cy.findByRole('button', { name: 'Recompile' }).should('not.exist')
  32. cy.wrap(null).then(() => {
  33. testDetachChannel.postMessage({
  34. role: 'detacher',
  35. event: 'state-compiling',
  36. data: { value: false },
  37. })
  38. })
  39. cy.findByRole('button', { name: 'Recompile' })
  40. cy.findByRole('button', { name: 'Compiling…' }).should('not.exist')
  41. })
  42. it('sends a clear cache request when the button is pressed', function () {
  43. cy.interceptCompile()
  44. cy.mount(<PdfPreviewDetachedRoot />)
  45. cy.wrap(null).then(() => {
  46. testDetachChannel.postMessage({
  47. role: 'detacher',
  48. event: 'state-showLogs',
  49. data: { value: true },
  50. })
  51. })
  52. cy.spy(detachChannel, 'postMessage').as('postDetachMessage')
  53. cy.findByRole('button', { name: 'Clear cached files' })
  54. .should('not.be.disabled')
  55. .click()
  56. cy.get('@postDetachMessage').should('have.been.calledWith', {
  57. role: 'detached',
  58. event: 'action-clearCache',
  59. data: {
  60. args: [],
  61. },
  62. })
  63. })
  64. })