2022-04-06 06:14:43 -04:00
|
|
|
|
import localStorage from '../../../../frontend/js/infrastructure/local-storage'
|
|
|
|
|
import PdfPreview from '../../../../frontend/js/features/pdf-preview/components/pdf-preview'
|
|
|
|
|
import { EditorProviders } from '../../helpers/editor-providers'
|
|
|
|
|
import { mockScope } from './scope'
|
2022-07-21 04:31:31 -04:00
|
|
|
|
import { useLayoutContext } from '../../../../frontend/js/shared/context/layout-context'
|
|
|
|
|
import { FC, useEffect } from 'react'
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2022-05-27 08:32:27 -04:00
|
|
|
|
const storeAndFireEvent = (win: typeof window, key: string, value: unknown) => {
|
2022-04-06 06:14:43 -04:00
|
|
|
|
localStorage.setItem(key, value)
|
|
|
|
|
win.dispatchEvent(new StorageEvent('storage', { key }))
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-21 04:31:31 -04:00
|
|
|
|
const Layout: FC<{ layout: string; view?: string }> = ({ layout, view }) => {
|
|
|
|
|
const { changeLayout } = useLayoutContext()
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
changeLayout(layout, view)
|
|
|
|
|
}, [changeLayout, layout, view])
|
|
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
describe('<PdfPreview/>', function () {
|
|
|
|
|
beforeEach(function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
|
2023-06-27 09:37:53 -04:00
|
|
|
|
window.metaAttributesCache.set(
|
|
|
|
|
'ol-compilesUserContentDomain',
|
|
|
|
|
'https://compiles-user.dev-overleaf.com'
|
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.interceptEvents()
|
|
|
|
|
})
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
afterEach(function () {
|
|
|
|
|
window.metaAttributesCache = new Map()
|
|
|
|
|
})
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
it('renders the PDF preview', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
window.metaAttributesCache.set('ol-preventCompileOnLoad', false)
|
|
|
|
|
cy.interceptCompile('compile')
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// wait for "compile on load" to finish
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.waitForCompile({ pdf: true })
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('runs a compile when the Recompile button is pressed', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// press the Recompile button => compile
|
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// wait for compile to finish
|
|
|
|
|
cy.waitForCompile({ pdf: true })
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
|
|
cy.contains('Your Paper')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('runs a compile on `pdf:recompile` event', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cy.window().then(win => {
|
|
|
|
|
win.dispatchEvent(new CustomEvent('pdf:recompile'))
|
|
|
|
|
})
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// wait for compile to finish
|
|
|
|
|
cy.waitForCompile({ pdf: true })
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
|
|
cy.contains('Your Paper')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does not compile while compiling', function () {
|
|
|
|
|
let counter = 0
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptDeferredCompile(() => counter++).then(
|
|
|
|
|
resolveDeferredCompile => {
|
|
|
|
|
const scope = mockScope()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.mount(
|
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// start compiling
|
2023-05-24 06:05:09 -04:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-05-24 06:05:09 -04:00
|
|
|
|
cy.findByRole('button', { name: 'Compiling…' }).then(() => {
|
|
|
|
|
// trigger a recompile
|
|
|
|
|
cy.window().then(win => {
|
|
|
|
|
win.dispatchEvent(new CustomEvent('pdf:recompile'))
|
|
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-05-24 06:05:09 -04:00
|
|
|
|
// finish the original compile
|
|
|
|
|
resolveDeferredCompile()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-05-24 06:05:09 -04:00
|
|
|
|
// wait for the original compile to finish
|
|
|
|
|
cy.waitForCompile({ pdf: true })
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-05-24 06:05:09 -04:00
|
|
|
|
// NOTE: difficult to assert that a second request won't be sent, at some point
|
|
|
|
|
expect(counter).to.equal(1)
|
|
|
|
|
})
|
2023-03-06 07:50:17 -05:00
|
|
|
|
}
|
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('disables compile button while compile is running', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptDeferredCompile().then(resolveDeferredCompile => {
|
|
|
|
|
const scope = mockScope()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.mount(
|
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.findByRole('button', { name: 'Compiling…' })
|
|
|
|
|
.should('be.disabled')
|
|
|
|
|
.then(resolveDeferredCompile)
|
|
|
|
|
|
|
|
|
|
cy.waitForCompile()
|
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).should('not.be.disabled')
|
|
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('runs a compile on doc change if autocompile is enabled', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cy.window().then(win => {
|
|
|
|
|
cy.clock()
|
|
|
|
|
|
|
|
|
|
// switch on auto compile
|
|
|
|
|
storeAndFireEvent(win, 'autocompile_enabled:project123', true)
|
|
|
|
|
|
|
|
|
|
// fire a doc:changed event => compile
|
|
|
|
|
win.dispatchEvent(new CustomEvent('doc:changed'))
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// wait enough time for the compile to start
|
2022-06-23 07:26:54 -04:00
|
|
|
|
cy.tick(6000) // > AUTO_COMPILE_DEBOUNCE
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
|
|
cy.clock().invoke('restore')
|
|
|
|
|
})
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// wait for compile to finish
|
|
|
|
|
cy.waitForCompile({ pdf: true })
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does not run a compile on doc change if autocompile is disabled', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cy.window().then(win => {
|
|
|
|
|
cy.clock()
|
|
|
|
|
|
|
|
|
|
// make sure auto compile is switched off
|
|
|
|
|
storeAndFireEvent(win, 'autocompile_enabled:project123', false)
|
|
|
|
|
|
|
|
|
|
// fire a doc:changed event => no compile
|
|
|
|
|
win.dispatchEvent(new CustomEvent('doc:changed'))
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// wait enough time for the compile to start
|
|
|
|
|
cy.tick(6000) // AUTO_COMPILE_DEBOUNCE
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
|
|
cy.clock().invoke('restore')
|
|
|
|
|
})
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// NOTE: difficult to assert that a request hasn't been sent
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does not run a compile on doc change if autocompile is blocked by syntax check', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
const scope = mockScope()
|
|
|
|
|
// enable linting in the editor
|
|
|
|
|
scope.settings.syntaxValidation = true
|
|
|
|
|
// mock a linting error
|
|
|
|
|
scope.hasLintingError = true
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cy.window().then(win => {
|
|
|
|
|
cy.clock()
|
|
|
|
|
|
|
|
|
|
// switch on auto compile
|
|
|
|
|
storeAndFireEvent(win, 'autocompile_enabled:project123', true)
|
|
|
|
|
|
|
|
|
|
// switch on syntax checking
|
|
|
|
|
storeAndFireEvent(win, 'stop_on_validation_error', true)
|
|
|
|
|
|
|
|
|
|
// fire a doc:changed event => no compile
|
|
|
|
|
win.dispatchEvent(new CustomEvent('doc:changed'))
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// wait enough time for the compile to start
|
|
|
|
|
cy.tick(6000) // AUTO_COMPILE_DEBOUNCE
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
|
|
cy.clock().invoke('restore')
|
|
|
|
|
})
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// NOTE: difficult to assert that a request hasn't been sent
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
2023-03-06 07:50:17 -05:00
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByText('Code check failed')
|
|
|
|
|
})
|
|
|
|
|
|
2022-07-21 04:31:31 -04:00
|
|
|
|
it('does not run a compile on doc change if the PDF preview is not open', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
2022-07-21 04:31:31 -04:00
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
|
|
|
|
cy.mount(
|
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<Layout layout="flat" view="editor" />
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cy.window().then(win => {
|
|
|
|
|
cy.clock()
|
|
|
|
|
|
|
|
|
|
// switch on auto compile
|
|
|
|
|
storeAndFireEvent(win, 'autocompile_enabled:project123', true)
|
|
|
|
|
|
|
|
|
|
// fire a doc:changed event => compile
|
|
|
|
|
win.dispatchEvent(new CustomEvent('doc:changed'))
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// wait enough time for the compile to start
|
2022-07-21 04:31:31 -04:00
|
|
|
|
cy.tick(6000) // > AUTO_COMPILE_DEBOUNCE
|
|
|
|
|
|
|
|
|
|
cy.clock().invoke('restore')
|
|
|
|
|
})
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// NOTE: difficult to assert that a request hasn't been sent
|
2022-07-21 04:31:31 -04:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
|
|
|
|
})
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
describe('error messages', function () {
|
2022-04-06 06:14:43 -04:00
|
|
|
|
const compileErrorStatuses = {
|
|
|
|
|
'clear-cache':
|
|
|
|
|
'Sorry, something went wrong and your project could not be compiled. Please try again in a few moments.',
|
|
|
|
|
'clsi-maintenance':
|
|
|
|
|
'The compile servers are down for maintenance, and will be back shortly.',
|
|
|
|
|
'compile-in-progress':
|
|
|
|
|
'A previous compile is still running. Please wait a minute and try compiling again.',
|
|
|
|
|
exited: 'Server Error',
|
|
|
|
|
failure: 'No PDF',
|
|
|
|
|
generic: 'Server Error',
|
|
|
|
|
'project-too-large': 'Project too large',
|
|
|
|
|
'rate-limited': 'Compile rate limit hit',
|
|
|
|
|
terminated: 'Compilation cancelled',
|
|
|
|
|
timedout: 'Timed out',
|
|
|
|
|
'too-recently-compiled':
|
|
|
|
|
'This project was compiled very recently, so this compile has been skipped.',
|
|
|
|
|
unavailable:
|
|
|
|
|
'Sorry, the compile server for your project was temporarily unavailable. Please try again in a few moments.',
|
|
|
|
|
foo: 'Sorry, something went wrong and your project could not be compiled. Please try again in a few moments.',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const [status, message] of Object.entries(compileErrorStatuses)) {
|
|
|
|
|
it(`displays error message for '${status}' status`, function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.intercept('POST', '/project/*/compile*', {
|
2022-04-06 06:14:43 -04:00
|
|
|
|
body: {
|
|
|
|
|
status,
|
|
|
|
|
clsiServerId: 'foo',
|
|
|
|
|
compileGroup: 'priority',
|
|
|
|
|
},
|
|
|
|
|
}).as('compile')
|
|
|
|
|
|
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.wait('@compile')
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByText(message)
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-03-06 07:50:17 -05:00
|
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
it('displays expandable raw logs', function () {
|
|
|
|
|
cy.interceptCompile()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
const scope = mockScope()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.mount(
|
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.waitForCompile({ pdf: true })
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'View logs' }).click()
|
|
|
|
|
cy.findByRole('button', { name: 'View PDF' })
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Expand' }).click()
|
|
|
|
|
cy.findByRole('button', { name: 'Collapse' }).click()
|
|
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
it('displays error messages if there were validation problems', function () {
|
|
|
|
|
const validationProblems = {
|
|
|
|
|
sizeCheck: {
|
|
|
|
|
resources: [
|
|
|
|
|
{ path: 'foo/bar', kbSize: 76221 },
|
|
|
|
|
{ path: 'bar/baz', kbSize: 2342 },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
mainFile: true,
|
|
|
|
|
conflictedPaths: [
|
|
|
|
|
{
|
|
|
|
|
path: 'foo/bar',
|
2022-04-06 06:14:43 -04:00
|
|
|
|
},
|
2023-03-06 07:50:17 -05:00
|
|
|
|
{
|
|
|
|
|
path: 'foo/baz',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.intercept('POST', '/project/*/compile*', {
|
|
|
|
|
body: {
|
|
|
|
|
status: 'validation-problems',
|
|
|
|
|
validationProblems,
|
|
|
|
|
clsiServerId: 'foo',
|
|
|
|
|
compileGroup: 'priority',
|
|
|
|
|
},
|
|
|
|
|
}).as('compile')
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
const scope = mockScope()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.mount(
|
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.wait('@compile')
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByText('Project too large')
|
|
|
|
|
cy.findByText('Unknown main document')
|
|
|
|
|
cy.findByText('Conflicting Paths Found')
|
|
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
describe('clear cache', function () {
|
2022-04-06 06:14:43 -04:00
|
|
|
|
it('sends a clear cache request when the button is pressed', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.waitForCompile({ pdf: true })
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'View logs' }).click()
|
|
|
|
|
cy.findByRole('button', { name: 'Clear cached files' }).should(
|
|
|
|
|
'not.be.disabled'
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.intercept('DELETE', '/project/*/output*', {
|
2022-04-06 06:14:43 -04:00
|
|
|
|
statusCode: 204,
|
|
|
|
|
delay: 100,
|
|
|
|
|
}).as('clear-cache')
|
|
|
|
|
|
|
|
|
|
// click the button
|
|
|
|
|
cy.findByRole('button', { name: 'Clear cached files' }).click()
|
|
|
|
|
cy.findByRole('button', { name: 'Clear cached files' }).should(
|
|
|
|
|
'be.disabled'
|
|
|
|
|
)
|
|
|
|
|
cy.wait('@clear-cache')
|
|
|
|
|
cy.findByRole('button', { name: 'Clear cached files' }).should(
|
|
|
|
|
'not.be.disabled'
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('handle "recompile from scratch"', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.waitForCompile({ pdf: true })
|
|
|
|
|
cy.interceptCompile('recompile')
|
|
|
|
|
cy.intercept('DELETE', '/project/*/output*', {
|
|
|
|
|
statusCode: 204,
|
|
|
|
|
delay: 100,
|
|
|
|
|
}).as('clear-cache')
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
|
|
// show the logs UI
|
|
|
|
|
cy.findByRole('button', { name: 'View logs' }).click()
|
|
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Clear cached files' }).should(
|
|
|
|
|
'not.be.disabled'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TODO: open the menu?
|
|
|
|
|
cy.findByRole('menuitem', {
|
|
|
|
|
name: 'Recompile from scratch',
|
|
|
|
|
hidden: true,
|
|
|
|
|
}).trigger('click', { force: true })
|
|
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Clear cached files' }).should(
|
|
|
|
|
'be.disabled'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Compiling…' })
|
|
|
|
|
cy.wait('@clear-cache')
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
// wait for recompile from scratch to finish
|
|
|
|
|
cy.waitForCompile({ pdf: true, prefix: 'recompile' })
|
|
|
|
|
|
|
|
|
|
cy.findByRole('button', { name: 'Recompile' })
|
2022-04-06 06:14:43 -04:00
|
|
|
|
})
|
2023-03-06 07:50:17 -05:00
|
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
describe('invalid URLs and broken PDFs', function () {
|
2022-04-06 06:14:43 -04:00
|
|
|
|
it('shows an error for an invalid URL', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
|
|
|
|
cy.intercept('/build/*/output.pdf*', {
|
2022-04-06 06:14:43 -04:00
|
|
|
|
statusCode: 500,
|
|
|
|
|
body: {
|
|
|
|
|
message: 'something awful happened',
|
|
|
|
|
code: 'AWFUL_ERROR',
|
|
|
|
|
},
|
|
|
|
|
}).as('compile-pdf-error')
|
|
|
|
|
|
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.waitForCompile()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.wait('@compile-pdf-error')
|
|
|
|
|
|
2022-07-28 10:39:17 -04:00
|
|
|
|
cy.contains('Something went wrong while rendering this PDF.')
|
|
|
|
|
cy.contains(
|
|
|
|
|
'Please try recompiling the project from scratch, and if that doesn’t help, follow our troubleshooting guide.'
|
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByLabelText('Page 1').should('not.exist')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('shows an error for a corrupt PDF', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
|
|
|
|
cy.intercept('/build/*/output.pdf*', {
|
2022-04-06 06:14:43 -04:00
|
|
|
|
fixture: 'build/output-corrupt.pdf,null',
|
|
|
|
|
}).as('compile-pdf-corrupt')
|
|
|
|
|
|
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.waitForCompile()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.wait('@compile-pdf-corrupt')
|
|
|
|
|
|
2022-07-28 10:39:17 -04:00
|
|
|
|
cy.contains('Something went wrong while rendering this PDF.')
|
|
|
|
|
cy.contains(
|
|
|
|
|
'Please try recompiling the project from scratch, and if that doesn’t help, follow our troubleshooting guide.'
|
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByLabelText('Page 1').should('not.exist')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('human readable logs', function () {
|
|
|
|
|
it('shows human readable hint for undefined reference errors', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
|
|
|
|
|
|
|
|
|
cy.intercept('/build/*/output.log*', {
|
2022-04-06 06:14:43 -04:00
|
|
|
|
fixture: 'build/output-human-readable.log',
|
2023-03-06 07:50:17 -05:00
|
|
|
|
}).as('compile-log')
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.waitForCompile()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByRole('button', { name: 'View logs' }).click()
|
|
|
|
|
|
|
|
|
|
cy.findByText(
|
|
|
|
|
"Reference `intorduction' on page 1 undefined on input line 11."
|
|
|
|
|
)
|
|
|
|
|
cy.findByText(
|
|
|
|
|
"Reference `section1' on page 1 undefined on input line 13."
|
|
|
|
|
)
|
|
|
|
|
cy.findByText('There were undefined references.')
|
|
|
|
|
|
|
|
|
|
cy.findAllByText(
|
|
|
|
|
/You have referenced something which has not yet been labelled/
|
|
|
|
|
).should('have.length', 3)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does not show human readable hint when no undefined reference errors', function () {
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.interceptCompile()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.intercept('/build/*/output.log?*', {
|
|
|
|
|
fixture: 'build/output-undefined-references.log',
|
2023-03-06 07:50:17 -05:00
|
|
|
|
}).as('compile-log')
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
|
|
const scope = mockScope()
|
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
|
<EditorProviders scope={scope}>
|
|
|
|
|
<div className="pdf-viewer">
|
|
|
|
|
<PdfPreview />
|
|
|
|
|
</div>
|
|
|
|
|
</EditorProviders>
|
|
|
|
|
)
|
|
|
|
|
|
2023-03-06 07:50:17 -05:00
|
|
|
|
cy.findByRole('button', { name: 'Recompile' }).click()
|
|
|
|
|
cy.waitForCompile()
|
2022-04-06 06:14:43 -04:00
|
|
|
|
cy.findByRole('button', { name: 'View logs' }).click()
|
|
|
|
|
|
|
|
|
|
cy.findByText(
|
|
|
|
|
"Package rerunfilecheck Warning: File `output.brf' has changed. Rerun to get bibliographical references right."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cy.findByText(
|
|
|
|
|
/You have referenced something which has not yet been labelled/
|
|
|
|
|
).should('not.exist')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|