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