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

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