file-view-text.test.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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.js'
  5. describe('<FileViewText/>', function () {
  6. const file = {
  7. name: 'example.tex',
  8. linkedFileData: {
  9. v1_source_doc_id: 'v1-source-id',
  10. source_project_id: 'source-project-id',
  11. source_entity_path: '/source-entity-path.ext',
  12. provider: 'project_file',
  13. },
  14. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  15. }
  16. beforeEach(function () {
  17. fetchMock.reset()
  18. })
  19. it('renders a text view', async function () {
  20. fetchMock.head('express:/project/:project_id/file/:file_id', {
  21. status: 201,
  22. headers: { 'Content-Length': 10000 },
  23. })
  24. fetchMock.get(
  25. 'express:/project/:project_id/file/:file_id',
  26. 'Text file content'
  27. )
  28. renderWithEditorContext(
  29. <FileViewText file={file} onError={() => {}} onLoad={() => {}} />
  30. )
  31. await screen.findByText('Text file content', { exact: false })
  32. })
  33. })