detach-compile-button.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import DetachCompileButton from '../../../../../frontend/js/features/pdf-preview/components/detach-compile-button'
  2. import { renderWithEditorContext } from '../../../helpers/render-with-context'
  3. import { screen, fireEvent } from '@testing-library/react'
  4. import sysendTestHelper from '../../../helpers/sysend'
  5. import { expect } from 'chai'
  6. describe('<DetachCompileButton/>', function () {
  7. afterEach(function () {
  8. window.metaAttributesCache = new Map()
  9. sysendTestHelper.resetHistory()
  10. })
  11. it('detacher mode and linked: show button ', async function () {
  12. window.metaAttributesCache.set('ol-detachRole', 'detacher')
  13. renderWithEditorContext(<DetachCompileButton />)
  14. sysendTestHelper.receiveMessage({
  15. role: 'detached',
  16. event: 'connected',
  17. })
  18. await screen.getByRole('button', {
  19. name: 'Recompile',
  20. })
  21. })
  22. it('detacher mode and not linked: does not show button ', async function () {
  23. window.metaAttributesCache.set('ol-detachRole', 'detacher')
  24. renderWithEditorContext(<DetachCompileButton />)
  25. expect(
  26. await screen.queryByRole('button', {
  27. name: 'Recompile',
  28. })
  29. ).to.not.exist
  30. })
  31. it('not detacher mode and linked: does not show button ', async function () {
  32. window.metaAttributesCache.set('ol-detachRole', 'detached')
  33. renderWithEditorContext(<DetachCompileButton />)
  34. sysendTestHelper.receiveMessage({
  35. role: 'detacher',
  36. event: 'connected',
  37. })
  38. expect(
  39. await screen.queryByRole('button', {
  40. name: 'Recompile',
  41. })
  42. ).to.not.exist
  43. })
  44. it('send compile clicks via detached action', async function () {
  45. window.metaAttributesCache.set('ol-detachRole', 'detacher')
  46. renderWithEditorContext(<DetachCompileButton />)
  47. sysendTestHelper.receiveMessage({
  48. role: 'detached',
  49. event: 'connected',
  50. })
  51. const compileButton = await screen.getByRole('button', {
  52. name: 'Recompile',
  53. })
  54. fireEvent.click(compileButton)
  55. expect(sysendTestHelper.getLastBroacastMessage()).to.deep.equal({
  56. role: 'detacher',
  57. event: 'action-start-compile',
  58. data: { args: [] },
  59. })
  60. })
  61. })