From adf88288606956093572178c0cca2032d2706ead Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Mon, 11 Oct 2021 14:45:36 +0100 Subject: [PATCH] Fix a few minor test issues (#5415) * Remove signal.abort() * Fix usage of .toString * Fix requests for files * Fix story GitOrigin-RevId: 37ab4be34a8975881aed2329d4b67f8df74837d8 --- .../js/features/pdf-preview/util/compiler.js | 1 - .../web/frontend/stories/pdf-preview.stories.js | 6 +++--- .../file-view/components/file-view.test.js | 17 ++++++++++++++++- .../components/pdf-js-viewer.test.js | 4 ++-- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/services/web/frontend/js/features/pdf-preview/util/compiler.js b/services/web/frontend/js/features/pdf-preview/util/compiler.js index 3f57cf4e6a..081f815bb6 100644 --- a/services/web/frontend/js/features/pdf-preview/util/compiler.js +++ b/services/web/frontend/js/features/pdf-preview/util/compiler.js @@ -46,7 +46,6 @@ export default class DocumentCompiler { } destroy() { - this.signal.abort() this.debouncedAutoCompile.cancel() } diff --git a/services/web/frontend/stories/pdf-preview.stories.js b/services/web/frontend/stories/pdf-preview.stories.js index 43c7ef3564..609c45b533 100644 --- a/services/web/frontend/stories/pdf-preview.stories.js +++ b/services/web/frontend/stories/pdf-preview.stories.js @@ -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 ( diff --git a/services/web/test/frontend/features/file-view/components/file-view.test.js b/services/web/test/frontend/features/file-view/components/file-view.test.js index 1fa4854e57..56770fab32 100644 --- a/services/web/test/frontend/features/file-view/components/file-view.test.js +++ b/services/web/test/frontend/features/file-view/components/file-view.test.js @@ -10,6 +10,7 @@ import FileView from '../../../../../frontend/js/features/file-view/components/f describe('', function () { const textFile = { + id: 'text-file', name: 'example.tex', linkedFileData: { v1_source_doc_id: 'v1-source-id', @@ -35,6 +36,15 @@ describe('', 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( {}} /> ) @@ -45,8 +55,13 @@ describe('', function () { }) it('shows messaging if the text view could not be loaded', async function () { + const unpreviewableTextFile = { + ...textFile, + name: 'example.not-tex', + } + renderWithEditorContext( - {}} /> + {}} /> ) await screen.findByText('Sorry, no preview is available', { diff --git a/services/web/test/frontend/features/pdf-preview/components/pdf-js-viewer.test.js b/services/web/test/frontend/features/pdf-preview/components/pdf-js-viewer.test.js index ca298acebb..f53d0c23ca 100644 --- a/services/web/test/frontend/features/pdf-preview/components/pdf-js-viewer.test.js +++ b/services/web/test/frontend/features/pdf-preview/components/pdf-js-viewer.test.js @@ -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')