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

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