binary-file-text.test.js 1.1 KB

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