Просмотр исходного кода

Fix a few minor test issues (#5415)

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

GitOrigin-RevId: 37ab4be34a8975881aed2329d4b67f8df74837d8
Alf Eaton 5 лет назад
Родитель
Сommit
adf8828860

+ 0 - 1
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()
   }
 

+ 3 - 3
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 (

+ 16 - 1
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('<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', {

+ 2 - 2
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')