2021-05-21 07:32:51 -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'
|
2021-06-10 07:26:04 -04:00
|
|
|
import FileViewText from '../../../../../frontend/js/features/file-view/components/file-view-text.js'
|
2021-04-28 07:41:20 -04:00
|
|
|
|
2021-06-10 07:26:04 -04:00
|
|
|
describe('<FileViewText/>', function () {
|
2021-04-28 07:41:20 -04:00
|
|
|
const 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',
|
|
|
|
},
|
|
|
|
created: new Date(2021, 1, 17, 3, 24).toISOString(),
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
fetchMock.reset()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders a text view', 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'
|
|
|
|
)
|
|
|
|
|
2021-05-21 07:32:51 -04:00
|
|
|
renderWithEditorContext(
|
2021-06-10 07:26:04 -04:00
|
|
|
<FileViewText file={file} onError={() => {}} onLoad={() => {}} />
|
2021-05-21 07:32:51 -04:00
|
|
|
)
|
2021-04-28 07:41:20 -04:00
|
|
|
|
|
|
|
await screen.findByText('Text file content', { exact: false })
|
|
|
|
})
|
|
|
|
})
|