Fix a few minor test issues (#5415)

* Remove signal.abort()
* Fix usage of .toString
* Fix requests for files
* Fix story

GitOrigin-RevId: 37ab4be34a8975881aed2329d4b67f8df74837d8
This commit is contained in:
Alf Eaton 2021-10-11 14:45:36 +01:00 committed by Copybot
parent 845b2fbc04
commit adf8828860
4 changed files with 21 additions and 7 deletions

View file

@ -46,7 +46,6 @@ export default class DocumentCompiler {
}
destroy() {
this.signal.abort()
this.debouncedAutoCompile.cancel()
}

View file

@ -404,16 +404,16 @@ export const CompileError = () => {
})
const Inner = () => {
const { recompile } = usePdfPreviewContext()
const { startCompile } = usePdfPreviewContext()
const handleStatusChange = useCallback(
event => {
setStatus(event.target.value)
window.setTimeout(() => {
recompile()
startCompile()
}, 0)
},
[recompile]
[startCompile]
)
return (

View file

@ -10,6 +10,7 @@ import FileView from '../../../../../frontend/js/features/file-view/components/f
describe('<FileView/>', function () {
const textFile = {
id: 'text-file',
name: 'example.tex',
linkedFileData: {
v1_source_doc_id: 'v1-source-id',
@ -35,6 +36,15 @@ describe('<FileView/>', function () {
describe('for a text file', function () {
it('shows a loading indicator while the file is loading', async function () {
fetchMock.head('express:/project/:project_id/file/:file_id', {
status: 201,
headers: { 'Content-Length': 10000 },
})
fetchMock.get(
'express:/project/:project_id/file/:file_id',
'Text file content'
)
renderWithEditorContext(
<FileView file={textFile} storeReferencesKeys={() => {}} />
)
@ -45,8 +55,13 @@ describe('<FileView/>', function () {
})
it('shows messaging if the text view could not be loaded', async function () {
const unpreviewableTextFile = {
...textFile,
name: 'example.not-tex',
}
renderWithEditorContext(
<FileView file={textFile} storeReferencesKeys={() => {}} />
<FileView file={unpreviewableTextFile} storeReferencesKeys={() => {}} />
)
await screen.findByText('Sorry, no preview is available', {

View file

@ -6,8 +6,8 @@ import { pathToFileURL } from 'url'
import PdfJsViewer from '../../../../../frontend/js/features/pdf-preview/components/pdf-js-viewer'
const example = pathToFileURL(
path.join(__dirname, '../fixtures/test-example.pdf').toString()
)
path.join(__dirname, '../fixtures/test-example.pdf')
).toString()
const exampleCorrupt = pathToFileURL(
path.join(__dirname, '../fixtures/test-example-corrupt.pdf')