2024-07-24 09:40:24 -04:00
|
|
|
import '../../helpers/bootstrap-3'
|
2022-04-06 06:14:43 -04:00
|
|
|
import PdfPreviewDetachedRoot from '../../../../frontend/js/features/pdf-preview/components/pdf-preview-detached-root'
|
2023-01-09 07:52:11 -05:00
|
|
|
import { detachChannel, testDetachChannel } from '../../helpers/detach-channel'
|
2022-04-06 06:14:43 -04:00
|
|
|
|
2023-01-09 07:52:11 -05:00
|
|
|
describe('<PdfPreviewDetachedRoot/>', function () {
|
2022-04-06 06:14:43 -04:00
|
|
|
beforeEach(function () {
|
2024-06-18 06:01:37 -04:00
|
|
|
window.metaAttributesCache.set('ol-user', { id: 'user1' })
|
2023-07-04 04:12:03 -04:00
|
|
|
window.metaAttributesCache.set('ol-project_id', 'project1')
|
|
|
|
window.metaAttributesCache.set('ol-detachRole', 'detached')
|
|
|
|
window.metaAttributesCache.set('ol-projectName', 'Project Name')
|
|
|
|
window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
cy.interceptEvents()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('syncs compiling state', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
cy.interceptCompile()
|
|
|
|
|
2023-01-09 07:52:11 -05:00
|
|
|
cy.mount(<PdfPreviewDetachedRoot />)
|
|
|
|
|
|
|
|
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: 'state-compiling',
|
|
|
|
data: { value: true },
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Compiling…' })
|
2023-01-09 07:52:11 -05:00
|
|
|
cy.findByRole('button', { name: 'Recompile' }).should('not.exist')
|
|
|
|
cy.wrap(null).then(() => {
|
|
|
|
testDetachChannel.postMessage({
|
|
|
|
role: 'detacher',
|
|
|
|
event: 'state-compiling',
|
|
|
|
data: { value: false },
|
2022-04-06 06:14:43 -04:00
|
|
|
})
|
2023-01-09 07:52:11 -05:00
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
|
|
|
cy.findByRole('button', { name: 'Compiling…' }).should('not.exist')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sends a clear cache request when the button is pressed', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
cy.interceptCompile()
|
|
|
|
|
2023-01-09 07:52:11 -05:00
|
|
|
cy.mount(<PdfPreviewDetachedRoot />)
|
|
|
|
|
|
|
|
cy.wrap(null).then(() => {
|
|
|
|
testDetachChannel.postMessage({
|
2022-04-06 06:14:43 -04:00
|
|
|
role: 'detacher',
|
|
|
|
event: 'state-showLogs',
|
|
|
|
data: { value: true },
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2023-01-09 07:52:11 -05:00
|
|
|
cy.spy(detachChannel, 'postMessage').as('postDetachMessage')
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
cy.findByRole('button', { name: 'Clear cached files' })
|
|
|
|
.should('not.be.disabled')
|
|
|
|
.click()
|
2023-01-09 07:52:11 -05:00
|
|
|
|
2023-05-24 06:03:36 -04:00
|
|
|
cy.get('@postDetachMessage').should('have.been.calledWith', {
|
2023-01-09 07:52:11 -05:00
|
|
|
role: 'detached',
|
|
|
|
event: 'action-clearCache',
|
|
|
|
data: {
|
|
|
|
args: [],
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
})
|
|
|
|
})
|