file-view-text.test.jsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { screen } from '@testing-library/react'
  2. import fetchMock from 'fetch-mock'
  3. import { renderWithEditorContext } from '../../../helpers/render-with-context'
  4. import FileViewText from '../../../../../frontend/js/features/file-view/components/file-view-text'
  5. describe('<FileViewText/>', function () {
  6. const file = {
  7. id: '123',
  8. hash: '1234',
  9. name: 'example.tex',
  10. linkedFileData: {
  11. v1_source_doc_id: 'v1-source-id',
  12. source_project_id: 'source-project-id',
  13. source_entity_path: '/source-entity-path.ext',
  14. provider: 'project_file',
  15. },
  16. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  17. }
  18. beforeEach(function () {
  19. fetchMock.reset()
  20. })
  21. it('renders a text view', async function () {
  22. fetchMock.head('express:/project/:project_id/file/:file_id', {
  23. status: 201,
  24. headers: { 'Content-Length': 10000 },
  25. })
  26. fetchMock.get(
  27. 'express:/project/:project_id/file/:file_id',
  28. 'Text file content'
  29. )
  30. renderWithEditorContext(
  31. <FileViewText file={file} onError={() => {}} onLoad={() => {}} />
  32. )
  33. await screen.findByText('Text file content', { exact: false })
  34. })
  35. })