file-view-text.test.jsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.removeRoutes().clearHistory()
  20. window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
  21. })
  22. it('renders a text view', async function () {
  23. fetchMock.head('express:/project/:project_id/blob/:hash', {
  24. status: 201,
  25. headers: { 'Content-Length': 10000 },
  26. })
  27. fetchMock.get(
  28. 'express:/project/:project_id/blob/:hash',
  29. 'Text file content'
  30. )
  31. renderWithEditorContext(
  32. <FileViewText file={file} onError={() => {}} onLoad={() => {}} />
  33. )
  34. await screen.findByText('Text file content', { exact: false })
  35. })
  36. })