overleaf/services/web/test/frontend/components/pdf-preview/detach-compile-button.spec.tsx
Alf Eaton 283c1d7282 Merge pull request #13605 from overleaf/ae-meta-tests
[cypress] Set/reset window.metaAttributesCache globally

GitOrigin-RevId: 5aa1d5e37780b53f6ddf7d34587e2119ba328003
2023-07-17 10:49:15 +00:00

84 lines
2 KiB
TypeScript

import { EditorProviders } from '../../helpers/editor-providers'
import DetachCompileButtonWrapper from '../../../../frontend/js/features/pdf-preview/components/detach-compile-button-wrapper'
import { mockScope } from './scope'
import { testDetachChannel } from '../../helpers/detach-channel'
describe('<DetachCompileButtonWrapper />', function () {
beforeEach(function () {
cy.interceptEvents()
})
it('detacher mode and not linked: does not show button ', function () {
cy.interceptCompile()
cy.window().then(win => {
win.metaAttributesCache = new Map([['ol-detachRole', 'detacher']])
})
const scope = mockScope()
cy.mount(
<EditorProviders scope={scope}>
<DetachCompileButtonWrapper />
</EditorProviders>
)
cy.waitForCompile()
cy.findByRole('button', { name: 'Recompile' }).should('not.exist')
})
it('detacher mode and linked: show button', function () {
cy.interceptCompile()
cy.window().then(win => {
win.metaAttributesCache = new Map([['ol-detachRole', 'detacher']])
})
const scope = mockScope()
cy.mount(
<EditorProviders scope={scope}>
<DetachCompileButtonWrapper />
</EditorProviders>
)
cy.waitForCompile()
cy.wrap(null).then(() => {
testDetachChannel.postMessage({
role: 'detached',
event: 'connected',
})
})
cy.findByRole('button', { name: 'Recompile' })
})
it('not detacher mode and linked: does not show button ', function () {
cy.interceptCompile()
cy.window().then(win => {
win.metaAttributesCache = new Map([['ol-detachRole', 'detached']])
})
const scope = mockScope()
cy.mount(
<EditorProviders scope={scope}>
<DetachCompileButtonWrapper />
</EditorProviders>
)
cy.waitForCompile()
cy.wrap(null).then(() => {
testDetachChannel.postMessage({
role: 'detacher',
event: 'connected',
})
})
cy.findByRole('button', { name: 'Recompile' }).should('not.exist')
})
})