detach-compile-button.spec.tsx 2.0 KB

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