detach-compile-button.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.interceptEvents()
  8. })
  9. it('detacher mode and not linked: does not show button ', function () {
  10. cy.interceptCompile()
  11. cy.window().then(win => {
  12. win.metaAttributesCache.set('ol-detachRole', 'detacher')
  13. })
  14. const scope = mockScope()
  15. cy.mount(
  16. <EditorProviders scope={scope}>
  17. <DetachCompileButtonWrapper />
  18. </EditorProviders>
  19. )
  20. cy.waitForCompile()
  21. cy.findByRole('button', { name: 'Recompile' }).should('not.exist')
  22. })
  23. it('detacher mode and linked: show button', function () {
  24. cy.interceptCompile()
  25. cy.window().then(win => {
  26. win.metaAttributesCache.set('ol-detachRole', 'detacher')
  27. })
  28. const scope = mockScope()
  29. cy.mount(
  30. <EditorProviders scope={scope}>
  31. <DetachCompileButtonWrapper />
  32. </EditorProviders>
  33. )
  34. cy.waitForCompile()
  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.interceptCompile()
  45. cy.window().then(win => {
  46. win.metaAttributesCache.set('ol-detachRole', 'detached')
  47. })
  48. const scope = mockScope()
  49. cy.mount(
  50. <EditorProviders scope={scope}>
  51. <DetachCompileButtonWrapper />
  52. </EditorProviders>
  53. )
  54. cy.waitForCompile()
  55. cy.wrap(null).then(() => {
  56. testDetachChannel.postMessage({
  57. role: 'detacher',
  58. event: 'connected',
  59. })
  60. })
  61. cy.findByRole('button', { name: 'Recompile' }).should('not.exist')
  62. })
  63. })