mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-10 14:40:47 +02:00
b901bb6c75
* Update fetch-mock to version 12 * Replace `fetchMock.done` by `fetchMock.callHistory.done` * Replace `…Mock.called` by `…Mock.callHistory.called` * Replace `fetchMock.reset` by `fetchMock.hardReset` * Replace `fetchMock.restore` by `fetchMock.hardReset` * Replace `fetchMock.resetHistory` by `fetchMock.clearHistory` * Replace `fetchMock.calls` by `fetchMock.callHistory.calls` * Replace `fetchMock.flush` by `fetchMock.callHistory.flush` * Update tests for fetch-mock version 12 See https://www.wheresrhys.co.uk/fetch-mock/docs/Usage/upgrade-guide * Update stories for fetch-mock version 12 * Remove `overwriteRoutes` option * Add `fetchMock.spyGlobal()` to storybook * Remove deprecated `sendAsJson` param * Replace `fetchMock.hardReset()` by `fetchMock.removeRoutes().clearHistory()` * Fixup fetch-mock in storybook: Call `mockGlobal` inside the hook, call `removeRoutes` and `unmockGlobal` on cleanup Behaviour can be tested by navigating between https://storybook.dev-overleaf.com/main/?path=/story/editor-ai-error-assistant-compile-log-entries--first-log-entry https://storybook.dev-overleaf.com/main/?path=/story/editor-ai-error-assistant-compile-log-entries--rate-limited https://storybook.dev-overleaf.com/main/?path=/story/project-list-notifications--project-invite https://storybook.dev-overleaf.com/main/?path=/story/project-list-notifications--project-invite-network-error And clicking the buttons GitOrigin-RevId: 35611b4430259e4c21c3d819ad18b2e6dab66242
89 lines
2.5 KiB
React
89 lines
2.5 KiB
React
import {
|
|
screen,
|
|
waitForElementToBeRemoved,
|
|
fireEvent,
|
|
} from '@testing-library/react'
|
|
import fetchMock from 'fetch-mock'
|
|
|
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
|
import FileView from '../../../../../frontend/js/features/file-view/components/file-view'
|
|
|
|
describe('<FileView/>', function () {
|
|
const textFile = {
|
|
id: 'text-file',
|
|
name: 'example.tex',
|
|
linkedFileData: {
|
|
v1_source_doc_id: 'v1-source-id',
|
|
source_project_id: 'source-project-id',
|
|
source_entity_path: '/source-entity-path.ext',
|
|
provider: 'project_file',
|
|
},
|
|
hash: '012345678901234567890123',
|
|
created: new Date(2021, 1, 17, 3, 24).toISOString(),
|
|
}
|
|
|
|
const imageFile = {
|
|
id: '60097ca20454610027c442a8',
|
|
name: 'file.jpg',
|
|
linkedFileData: {
|
|
source_entity_path: '/source-entity-path',
|
|
provider: 'project_file',
|
|
},
|
|
}
|
|
|
|
beforeEach(function () {
|
|
fetchMock.removeRoutes().clearHistory()
|
|
})
|
|
|
|
describe('for a text file', function () {
|
|
it('shows a loading indicator while the file is loading', async function () {
|
|
fetchMock.head('express:/project/:project_id/blob/:hash', {
|
|
status: 201,
|
|
headers: { 'Content-Length': 10000 },
|
|
})
|
|
fetchMock.get(
|
|
'express:/project/:project_id/blob/:hash',
|
|
'Text file content'
|
|
)
|
|
|
|
renderWithEditorContext(<FileView file={textFile} />)
|
|
|
|
await waitForElementToBeRemoved(() =>
|
|
screen.getByTestId('loading-panel-file-view')
|
|
)
|
|
})
|
|
|
|
it('shows messaging if the text view could not be loaded', async function () {
|
|
const unpreviewableTextFile = {
|
|
...textFile,
|
|
name: 'example.not-tex',
|
|
}
|
|
|
|
renderWithEditorContext(<FileView file={unpreviewableTextFile} />)
|
|
|
|
await screen.findByText('Sorry, no preview is available', {
|
|
exact: false,
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('for an image file', function () {
|
|
it('shows a loading indicator while the file is loading', async function () {
|
|
renderWithEditorContext(<FileView file={imageFile} />)
|
|
|
|
screen.getByTestId('loading-panel-file-view')
|
|
})
|
|
|
|
it('shows messaging if the image could not be loaded', async function () {
|
|
renderWithEditorContext(<FileView file={imageFile} />)
|
|
|
|
// Fake the image request failing as the request is handled by the browser
|
|
fireEvent.error(screen.getByRole('img'))
|
|
|
|
await screen.findByText('Sorry, no preview is available', {
|
|
exact: false,
|
|
})
|
|
})
|
|
})
|
|
})
|