detach-compile-button.spec.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { EditorProviders } from '../../helpers/editor-providers'
  2. import DetachCompileButtonWrapper from '../../../../frontend/js/features/pdf-preview/components/detach-compile-button-wrapper'
  3. import { mockScope } from './scope'
  4. import { testDetachChannel } from '../../helpers/detach-channel'
  5. describe('<DetachCompileButtonWrapper />', function () {
  6. beforeEach(function () {
  7. cy.interceptCompile()
  8. cy.interceptEvents()
  9. })
  10. afterEach(function () {
  11. window.metaAttributesCache = new Map()
  12. })
  13. it('detacher mode and not linked: does not show button ', function () {
  14. cy.window().then(win => {
  15. win.metaAttributesCache = new Map([['ol-detachRole', 'detacher']])
  16. })
  17. const scope = mockScope()
  18. cy.mount(
  19. <EditorProviders scope={scope}>
  20. <DetachCompileButtonWrapper />
  21. </EditorProviders>
  22. )
  23. cy.findByRole('button', { name: 'Recompile' }).should('not.exist')
  24. })
  25. it('detacher mode and linked: show button', function () {
  26. cy.window().then(win => {
  27. win.metaAttributesCache = new Map([['ol-detachRole', 'detacher']])
  28. })
  29. const scope = mockScope()
  30. cy.mount(
  31. <EditorProviders scope={scope}>
  32. <DetachCompileButtonWrapper />
  33. </EditorProviders>
  34. )
  35. cy.wrap(null).then(() => {
  36. testDetachChannel.postMessage({
  37. role: 'detached',
  38. event: 'connected',
  39. })
  40. })
  41. cy.findByRole('button', { name: 'Recompile' })
  42. })
  43. it('not detacher mode and linked: does not show button ', function () {
  44. cy.window().then(win => {
  45. win.metaAttributesCache = new Map([['ol-detachRole', 'detached']])
  46. })
  47. const scope = mockScope()
  48. cy.mount(
  49. <EditorProviders scope={scope}>
  50. <DetachCompileButtonWrapper />
  51. </EditorProviders>
  52. )
  53. cy.wrap(null).then(() => {
  54. testDetachChannel.postMessage({
  55. role: 'detacher',
  56. event: 'connected',
  57. })
  58. })
  59. cy.findByRole('button', { name: 'Recompile' }).should('not.exist')
  60. })
  61. })