2022-04-06 06:14:43 -04:00
|
|
|
import sysendTestHelper from '../../helpers/sysend'
|
|
|
|
import PdfPreviewDetachedRoot from '../../../../frontend/js/features/pdf-preview/components/pdf-preview-detached-root'
|
2022-06-06 10:43:25 -04:00
|
|
|
import { User } from '../../../../types/user'
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
describe('<PdfPreviewDetachedRoot/>', function () {
|
|
|
|
beforeEach(function () {
|
2022-06-06 10:43:25 -04:00
|
|
|
window.user = { id: 'user1' } as User
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
window.metaAttributesCache = new Map<string, unknown>([
|
|
|
|
['ol-user', window.user],
|
|
|
|
['ol-project_id', 'project1'],
|
|
|
|
['ol-detachRole', 'detached'],
|
|
|
|
['ol-projectName', 'Project Name'],
|
|
|
|
])
|
|
|
|
|
|
|
|
cy.interceptCompile()
|
|
|
|
cy.interceptEvents()
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
window.metaAttributesCache = new Map()
|
|
|
|
sysendTestHelper.resetHistory()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('syncs compiling state', function () {
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(<PdfPreviewDetachedRoot />).then(() => {
|
2022-04-06 06:14:43 -04:00
|
|
|
sysendTestHelper.receiveMessage({
|
|
|
|
role: 'detacher',
|
|
|
|
event: 'connected',
|
|
|
|
})
|
|
|
|
|
|
|
|
sysendTestHelper.receiveMessage({
|
|
|
|
role: 'detacher',
|
|
|
|
event: 'state-compiling',
|
|
|
|
data: { value: true },
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Compiling…' })
|
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
|
|
|
.should('not.exist')
|
|
|
|
.then(() => {
|
|
|
|
sysendTestHelper.receiveMessage({
|
|
|
|
role: 'detacher',
|
|
|
|
event: 'state-compiling',
|
|
|
|
data: { value: false },
|
|
|
|
})
|
|
|
|
})
|
|
|
|
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 () {
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(<PdfPreviewDetachedRoot />).then(() => {
|
2022-04-06 06:14:43 -04:00
|
|
|
sysendTestHelper.receiveMessage({
|
|
|
|
role: 'detacher',
|
|
|
|
event: 'state-showLogs',
|
|
|
|
data: { value: true },
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Clear cached files' })
|
|
|
|
.should('not.be.disabled')
|
|
|
|
.click()
|
|
|
|
.then(() => {
|
|
|
|
expect(sysendTestHelper.getLastBroacastMessage()).to.deep.equal({
|
|
|
|
role: 'detached',
|
|
|
|
event: 'action-clearCache',
|
|
|
|
data: {
|
|
|
|
args: [],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|