file-view-header.test.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { screen } from '@testing-library/react'
  2. import fetchMock from 'fetch-mock'
  3. import { renderWithEditorContext } from '../../../helpers/render-with-context'
  4. import FileViewHeader from '../../../../../frontend/js/features/file-view/components/file-view-header'
  5. import { USER_ID } from '../../../helpers/editor-providers'
  6. import { fileViewFile } from '@/features/ide-react/util/file-view'
  7. import { projectOutputFile, textFile, urlFile } from '../util/files'
  8. describe('<FileViewHeader/>', function () {
  9. beforeEach(function () {
  10. fetchMock.removeRoutes().clearHistory()
  11. })
  12. describe('header text', function () {
  13. it('Renders the correct text for a file with the url provider', function () {
  14. renderWithEditorContext(<FileViewHeader file={urlFile} />)
  15. screen.getByText('Imported from', { exact: false })
  16. screen.getByText('at 3:24 am Wed, 17th Feb 21', {
  17. exact: false,
  18. })
  19. })
  20. it('Renders the correct text for a file with the project_file provider', function () {
  21. renderWithEditorContext(<FileViewHeader file={textFile} />)
  22. screen.getByText('Imported from', { exact: false })
  23. screen.getByText('Another project', { exact: false })
  24. screen.getByText('/source-entity-path.ext, at 3:24 am Wed, 17th Feb 21', {
  25. exact: false,
  26. })
  27. })
  28. it('Renders the correct text for a file with the project_output_file provider', function () {
  29. renderWithEditorContext(<FileViewHeader file={projectOutputFile} />)
  30. screen.getByText('Imported from the output of', { exact: false })
  31. screen.getByText('Another project', { exact: false })
  32. screen.getByText('/source-entity-path.ext, at 3:24 am Wed, 17th Feb 21', {
  33. exact: false,
  34. })
  35. })
  36. })
  37. describe('The download button', function () {
  38. it('exists', function () {
  39. renderWithEditorContext(<FileViewHeader file={urlFile} />)
  40. screen.getByText('Download')
  41. })
  42. })
  43. it('should use importedAt as timestamp when present in the linked file data', function () {
  44. const fileFromServer = {
  45. _id: 'some-id',
  46. hash: 'some-hash',
  47. name: 'example.tex',
  48. linkedFileData: {
  49. v1_source_doc_id: 'v1-source-id',
  50. source_project_id: 'source-project-id',
  51. source_entity_path: '/source-entity-path.ext',
  52. provider: 'project_file',
  53. importer_id: USER_ID,
  54. importedAt: new Date(2024, 8, 16, 1, 30).getTime(),
  55. },
  56. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  57. }
  58. // FIXME: This should be tested through the <EditorPanel /> component instead
  59. const fileShown = fileViewFile(fileFromServer)
  60. renderWithEditorContext(<FileViewHeader file={fileShown} />)
  61. screen.getByText('Imported from', { exact: false })
  62. screen.getByText('Another project', { exact: false })
  63. screen.getByText('/source-entity-path.ext, at 1:30 am Mon, 16th Sep 24', {
  64. exact: false,
  65. })
  66. })
  67. })