pdf-preview-detached-root.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { expect } from 'chai'
  2. import { render, screen, fireEvent } from '@testing-library/react'
  3. import sysendTestHelper from '../../../helpers/sysend'
  4. import PdfPreviewDetachedRoot from '../../../../../frontend/js/features/pdf-preview/components/pdf-preview-detached-root'
  5. describe('<PdfPreviewDetachedRoot/>', function () {
  6. beforeEach(function () {
  7. const user = { id: 'user1' }
  8. window.user = user
  9. window.metaAttributesCache = new Map()
  10. window.metaAttributesCache.set('ol-user', user)
  11. window.metaAttributesCache.set('ol-project_id', 'project1')
  12. window.metaAttributesCache.set('ol-detachRole', 'detached')
  13. window.metaAttributesCache.set('ol-projectName', 'Project Name')
  14. })
  15. afterEach(function () {
  16. window.metaAttributesCache = new Map()
  17. })
  18. it('syncs compiling state', async function () {
  19. render(<PdfPreviewDetachedRoot />)
  20. sysendTestHelper.receiveMessage({
  21. role: 'detacher',
  22. event: 'connected',
  23. })
  24. sysendTestHelper.receiveMessage({
  25. role: 'detacher',
  26. event: 'state-compiling',
  27. data: { value: true },
  28. })
  29. await screen.findByRole('button', { name: 'Compiling…' })
  30. expect(screen.queryByRole('button', { name: 'Recompile' })).to.not.exist
  31. sysendTestHelper.receiveMessage({
  32. role: 'detacher',
  33. event: 'state-compiling',
  34. data: { value: false },
  35. })
  36. await screen.findByRole('button', { name: 'Recompile' })
  37. expect(screen.queryByRole('button', { name: 'Compiling…' })).to.not.exist
  38. })
  39. it('sends a clear cache request when the button is pressed', async function () {
  40. render(<PdfPreviewDetachedRoot />)
  41. sysendTestHelper.receiveMessage({
  42. role: 'detacher',
  43. event: 'state-showLogs',
  44. data: { value: true },
  45. })
  46. const clearCacheButton = await screen.findByRole('button', {
  47. name: 'Clear cached files',
  48. })
  49. expect(clearCacheButton.hasAttribute('disabled')).to.be.false
  50. fireEvent.click(clearCacheButton)
  51. expect(sysendTestHelper.getLastBroacastMessage()).to.deep.equal({
  52. role: 'detached',
  53. event: 'action-clearCache',
  54. data: {
  55. args: [],
  56. },
  57. })
  58. })
  59. })