mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-07-29 23:00:08 +02:00

* 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
108 lines
3.6 KiB
JavaScript
108 lines
3.6 KiB
JavaScript
import { screen } from '@testing-library/react'
|
|
import fetchMock from 'fetch-mock'
|
|
|
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
|
import FileViewHeader from '../../../../../frontend/js/features/file-view/components/file-view-header'
|
|
import { USER_ID } from '../../../helpers/editor-providers'
|
|
import { fileViewFile } from '@/features/ide-react/util/file-view'
|
|
|
|
describe('<FileViewHeader/>', function () {
|
|
const urlFile = {
|
|
name: 'example.tex',
|
|
linkedFileData: {
|
|
url: 'https://overleaf.com',
|
|
provider: 'url',
|
|
},
|
|
created: new Date(2021, 1, 17, 3, 24).toISOString(),
|
|
}
|
|
|
|
const projectFile = {
|
|
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',
|
|
importer_id: USER_ID,
|
|
},
|
|
created: new Date(2021, 1, 17, 3, 24).toISOString(),
|
|
}
|
|
|
|
const projectOutputFile = {
|
|
name: 'example.pdf',
|
|
linkedFileData: {
|
|
v1_source_doc_id: 'v1-source-id',
|
|
source_output_file_path: '/source-entity-path.ext',
|
|
provider: 'project_output_file',
|
|
},
|
|
created: new Date(2021, 1, 17, 3, 24).toISOString(),
|
|
}
|
|
|
|
beforeEach(function () {
|
|
fetchMock.removeRoutes().clearHistory()
|
|
})
|
|
|
|
describe('header text', function () {
|
|
it('Renders the correct text for a file with the url provider', function () {
|
|
renderWithEditorContext(<FileViewHeader file={urlFile} />)
|
|
screen.getByText('Imported from', { exact: false })
|
|
screen.getByText('at 3:24 am Wed, 17th Feb 21', {
|
|
exact: false,
|
|
})
|
|
})
|
|
|
|
it('Renders the correct text for a file with the project_file provider', function () {
|
|
renderWithEditorContext(<FileViewHeader file={projectFile} />)
|
|
screen.getByText('Imported from', { exact: false })
|
|
screen.getByText('Another project', { exact: false })
|
|
screen.getByText('/source-entity-path.ext, at 3:24 am Wed, 17th Feb 21', {
|
|
exact: false,
|
|
})
|
|
})
|
|
|
|
it('Renders the correct text for a file with the project_output_file provider', function () {
|
|
renderWithEditorContext(
|
|
<FileViewHeader
|
|
file={projectOutputFile}
|
|
storeReferencesKeys={() => {}}
|
|
/>
|
|
)
|
|
screen.getByText('Imported from the output of', { exact: false })
|
|
screen.getByText('Another project', { exact: false })
|
|
screen.getByText('/source-entity-path.ext, at 3:24 am Wed, 17th Feb 21', {
|
|
exact: false,
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('The download button', function () {
|
|
it('exists', function () {
|
|
renderWithEditorContext(<FileViewHeader file={urlFile} />)
|
|
|
|
screen.getByText('Download')
|
|
})
|
|
})
|
|
|
|
it('should use importedAt as timestamp when present in the linked file data', function () {
|
|
const fileFromServer = {
|
|
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',
|
|
importer_id: USER_ID,
|
|
importedAt: new Date(2024, 8, 16, 1, 30).getTime(),
|
|
},
|
|
created: new Date(2021, 1, 17, 3, 24).toISOString(),
|
|
}
|
|
// FIXME: This should be tested through the <EditorAndPdf /> component instead
|
|
const fileShown = fileViewFile(fileFromServer)
|
|
renderWithEditorContext(<FileViewHeader file={fileShown} />)
|
|
screen.getByText('Imported from', { exact: false })
|
|
screen.getByText('Another project', { exact: false })
|
|
screen.getByText('/source-entity-path.ext, at 1:30 am Mon, 16th Sep 24', {
|
|
exact: false,
|
|
})
|
|
})
|
|
})
|