2023-10-04 15:36:34 -04:00
|
|
|
import { screen } from '@testing-library/react'
|
2021-04-28 07:41:20 -04:00
|
|
|
import fetchMock from 'fetch-mock'
|
|
|
|
|
2021-05-21 07:32:51 -04:00
|
|
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
2023-09-27 13:01:30 -04:00
|
|
|
import FileViewHeader from '../../../../../frontend/js/features/file-view/components/file-view-header'
|
2023-10-04 15:36:34 -04:00
|
|
|
import { USER_ID } from '../../../helpers/editor-providers'
|
2024-09-18 05:05:31 -04:00
|
|
|
import { fileViewFile } from '@/features/ide-react/util/file-view'
|
2021-04-28 07:41:20 -04:00
|
|
|
|
2021-06-10 07:26:04 -04:00
|
|
|
describe('<FileViewHeader/>', function () {
|
2021-04-28 07:41:20 -04:00
|
|
|
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',
|
2023-10-04 15:36:34 -04:00
|
|
|
importer_id: USER_ID,
|
2021-04-28 07:41:20 -04:00
|
|
|
},
|
|
|
|
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.reset()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('header text', function () {
|
|
|
|
it('Renders the correct text for a file with the url provider', function () {
|
2023-09-28 09:42:31 -04:00
|
|
|
renderWithEditorContext(<FileViewHeader file={urlFile} />)
|
2021-04-28 07:41:20 -04:00
|
|
|
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 () {
|
2023-09-28 09:42:31 -04:00
|
|
|
renderWithEditorContext(<FileViewHeader file={projectFile} />)
|
2021-04-28 07:41:20 -04:00
|
|
|
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 () {
|
2021-05-21 07:32:51 -04:00
|
|
|
renderWithEditorContext(
|
2021-06-10 07:26:04 -04:00
|
|
|
<FileViewHeader
|
2021-04-28 07:41:20 -04:00
|
|
|
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 () {
|
2023-09-28 09:42:31 -04:00
|
|
|
renderWithEditorContext(<FileViewHeader file={urlFile} />)
|
2021-04-28 07:41:20 -04:00
|
|
|
|
|
|
|
screen.getByText('Download', { exact: false })
|
|
|
|
})
|
|
|
|
})
|
2024-09-18 05:05:31 -04:00
|
|
|
|
|
|
|
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, 9, 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 Wed, 16th Oct 24', {
|
|
|
|
exact: false,
|
|
|
|
})
|
|
|
|
})
|
2021-04-28 07:41:20 -04:00
|
|
|
})
|