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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import sysendTestHelper from '../../helpers/sysend'
  2. import PdfPreviewDetachedRoot from '../../../../frontend/js/features/pdf-preview/components/pdf-preview-detached-root'
  3. import { User } from '../../../../types/user'
  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. sysendTestHelper.resetHistory()
  19. })
  20. it('syncs compiling state', function () {
  21. cy.mount(<PdfPreviewDetachedRoot />).then(() => {
  22. sysendTestHelper.receiveMessage({
  23. role: 'detacher',
  24. event: 'connected',
  25. })
  26. sysendTestHelper.receiveMessage({
  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' })
  34. .should('not.exist')
  35. .then(() => {
  36. sysendTestHelper.receiveMessage({
  37. role: 'detacher',
  38. event: 'state-compiling',
  39. data: { value: false },
  40. })
  41. })
  42. cy.findByRole('button', { name: 'Recompile' })
  43. cy.findByRole('button', { name: 'Compiling…' }).should('not.exist')
  44. })
  45. it('sends a clear cache request when the button is pressed', function () {
  46. cy.mount(<PdfPreviewDetachedRoot />).then(() => {
  47. sysendTestHelper.receiveMessage({
  48. role: 'detacher',
  49. event: 'state-showLogs',
  50. data: { value: true },
  51. })
  52. })
  53. cy.findByRole('button', { name: 'Clear cached files' })
  54. .should('not.be.disabled')
  55. .click()
  56. .should(() => {
  57. expect(sysendTestHelper.getLastBroacastMessage()).to.deep.equal({
  58. role: 'detached',
  59. event: 'action-clearCache',
  60. data: {
  61. args: [],
  62. },
  63. })
  64. })
  65. })
  66. })