2022-04-06 06:14:43 -04:00
|
|
|
import { EditorProviders } from '../../helpers/editor-providers'
|
|
|
|
import PdfPreviewHybridToolbar from '../../../../frontend/js/features/pdf-preview/components/pdf-preview-hybrid-toolbar'
|
2023-01-09 07:52:11 -05:00
|
|
|
import { testDetachChannel } from '../../helpers/detach-channel'
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
describe('<PdfPreviewHybridToolbar/>', function () {
|
|
|
|
beforeEach(function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
window.metaAttributesCache = new Map()
|
|
|
|
window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
|
2022-04-06 06:14:43 -04:00
|
|
|
cy.interceptEvents()
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
window.metaAttributesCache = new Map()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows normal mode', function () {
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
<EditorProviders>
|
|
|
|
<PdfPreviewHybridToolbar />
|
|
|
|
</EditorProviders>
|
|
|
|
)
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('orphan mode', function () {
|
|
|
|
it('shows connecting message on load', function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache = new Map([['ol-detachRole', 'detached']])
|
|
|
|
})
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
<EditorProviders>
|
|
|
|
<PdfPreviewHybridToolbar />
|
|
|
|
</EditorProviders>
|
|
|
|
)
|
|
|
|
|
|
|
|
cy.contains('Connecting with the editor')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows compile UI when connected', function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache = new Map([['ol-detachRole', 'detached']])
|
|
|
|
})
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
<EditorProviders>
|
|
|
|
<PdfPreviewHybridToolbar />
|
|
|
|
</EditorProviders>
|
2023-01-09 07:52:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
cy.wrap(null).then(() => {
|
|
|
|
testDetachChannel.postMessage({
|
2022-04-06 06:14:43 -04:00
|
|
|
role: 'detacher',
|
|
|
|
event: 'connected',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows connecting message when disconnected', function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache = new Map([['ol-detachRole', 'detached']])
|
|
|
|
})
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
<EditorProviders>
|
|
|
|
<PdfPreviewHybridToolbar />
|
|
|
|
</EditorProviders>
|
2023-01-09 07:52:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
cy.wrap(null).then(() => {
|
|
|
|
testDetachChannel.postMessage({
|
2022-04-06 06:14:43 -04:00
|
|
|
role: 'detacher',
|
|
|
|
event: 'connected',
|
|
|
|
})
|
2023-01-09 07:52:11 -05:00
|
|
|
testDetachChannel.postMessage({
|
2022-04-06 06:14:43 -04:00
|
|
|
role: 'detacher',
|
|
|
|
event: 'closed',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.contains('Connecting with the editor')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows redirect button after timeout', function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache = new Map([['ol-detachRole', 'detached']])
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.clock()
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
<EditorProviders>
|
|
|
|
<PdfPreviewHybridToolbar />
|
|
|
|
</EditorProviders>
|
|
|
|
)
|
|
|
|
|
|
|
|
cy.tick(6000)
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Redirect to editor' })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|