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

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