mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 20:33:12 -05:00
d6de6da781
* [web] Remove unnecessary divs around `fileInfo` * [web] Add file-view SCSS style * [web] Simplify `TPRFileViewInfo` * [web] Add div for action buttons * [web] Misc. simplifications * [web] Add Overleaf logo in bg when selecting multiple files * [web] Add message when multiple files are selected * [web] Add .full-size class * [web] Import styles from LESS file * [web] Update icons, use MaterialIcon * [web] Use OLButton * [web] Add missing space between icons and text * [web] Adjust margins * [web] Fix alert button * [web] Update Alerts * [web] Update `FileViewLoadingIndicator` * [web] Fix test "shows a loading indicator..." This was failing because `LoadingSpinner` is shown after a setTimeout. Maybe we can skip this setTimeout when delay==0 ? * [web] Remove Row/Col around error notifications * [web] Replace `!!` by `Boolean` Co-authored-by: ilkin-overleaf <100852799+ilkin-overleaf@users.noreply.github.com> * [web] Use `alert` class in BS3 only Co-authored-by: Ilkin Ismailov <ilkin.ismailov@overleaf.com> * [web] Update "Go to settings" to OLButton Co-authored-by: Ilkin Ismailov <ilkin.ismailov@overleaf.com> * [web] Use `BootstrapVersionSwitcher` instead of `isBootstrap5` Co-authored-by: Ilkin Ismailov <ilkin.ismailov@overleaf.com> * [web] Align Alert content to the left in BS5 * [web] Remove `leadingIcon` on Refresh buttons * [web] Make the download link be an OLButton * [web] Set `tpr-refresh-error` in BS3 only Co-authored-by: Rebeka Dekany <50901361+rebekadekany@users.noreply.github.com> * [web] Use `var(--white);` instead of `white` Co-authored-by: Rebeka <rebeka.dekany@overleaf.com> * [web] Update OLButton size (small -> sm) --------- Co-authored-by: ilkin-overleaf <100852799+ilkin-overleaf@users.noreply.github.com> Co-authored-by: Ilkin Ismailov <ilkin.ismailov@overleaf.com> Co-authored-by: Rebeka Dekany <50901361+rebekadekany@users.noreply.github.com> Co-authored-by: Rebeka <rebeka.dekany@overleaf.com> GitOrigin-RevId: 04f369c0f1a53d47619a1570648ee58de5050751
87 lines
2.4 KiB
JavaScript
87 lines
2.4 KiB
JavaScript
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',
|
|
},
|
|
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.reset()
|
|
})
|
|
|
|
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} />)
|
|
|
|
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,
|
|
})
|
|
})
|
|
})
|
|
})
|