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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. cy.interceptEvents()
  11. })
  12. it('syncs compiling state', function () {
  13. cy.interceptCompile()
  14. cy.mount(<PdfPreviewDetachedRoot />)
  15. cy.wrap(null).then(() => {
  16. testDetachChannel.postMessage({
  17. role: 'detacher',
  18. event: 'connected',
  19. })
  20. testDetachChannel.postMessage({
  21. role: 'detacher',
  22. event: 'state-compiling',
  23. data: { value: true },
  24. })
  25. })
  26. cy.findByRole('button', { name: 'Compiling…' })
  27. cy.findByRole('button', { name: 'Recompile' }).should('not.exist')
  28. cy.wrap(null).then(() => {
  29. testDetachChannel.postMessage({
  30. role: 'detacher',
  31. event: 'state-compiling',
  32. data: { value: false },
  33. })
  34. })
  35. cy.findByRole('button', { name: 'Recompile' })
  36. cy.findByRole('button', { name: 'Compiling…' }).should('not.exist')
  37. })
  38. it('sends a clear cache request when the button is pressed', function () {
  39. cy.interceptCompile()
  40. cy.mount(<PdfPreviewDetachedRoot />)
  41. cy.wrap(null).then(() => {
  42. testDetachChannel.postMessage({
  43. role: 'detacher',
  44. event: 'state-showLogs',
  45. data: { value: true },
  46. })
  47. })
  48. cy.spy(detachChannel, 'postMessage').as('postDetachMessage')
  49. cy.findByRole('button', { name: 'Clear cached files' })
  50. .should('not.be.disabled')
  51. .click()
  52. cy.get('@postDetachMessage').should('have.been.calledWith', {
  53. role: 'detached',
  54. event: 'action-clearCache',
  55. data: {
  56. args: [],
  57. },
  58. })
  59. })
  60. })