file-view-header.test.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. describe('<FileViewHeader/>', function () {
  8. const urlFile = {
  9. name: 'example.tex',
  10. linkedFileData: {
  11. url: 'https://overleaf.com',
  12. provider: 'url',
  13. },
  14. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  15. }
  16. const projectFile = {
  17. name: 'example.tex',
  18. linkedFileData: {
  19. v1_source_doc_id: 'v1-source-id',
  20. source_project_id: 'source-project-id',
  21. source_entity_path: '/source-entity-path.ext',
  22. provider: 'project_file',
  23. importer_id: USER_ID,
  24. },
  25. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  26. }
  27. const projectOutputFile = {
  28. name: 'example.pdf',
  29. linkedFileData: {
  30. v1_source_doc_id: 'v1-source-id',
  31. source_output_file_path: '/source-entity-path.ext',
  32. provider: 'project_output_file',
  33. },
  34. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  35. }
  36. beforeEach(function () {
  37. fetchMock.removeRoutes().clearHistory()
  38. })
  39. describe('header text', function () {
  40. it('Renders the correct text for a file with the url provider', function () {
  41. renderWithEditorContext(<FileViewHeader file={urlFile} />)
  42. screen.getByText('Imported from', { exact: false })
  43. screen.getByText('at 3:24 am Wed, 17th Feb 21', {
  44. exact: false,
  45. })
  46. })
  47. it('Renders the correct text for a file with the project_file provider', function () {
  48. renderWithEditorContext(<FileViewHeader file={projectFile} />)
  49. screen.getByText('Imported from', { exact: false })
  50. screen.getByText('Another project', { exact: false })
  51. screen.getByText('/source-entity-path.ext, at 3:24 am Wed, 17th Feb 21', {
  52. exact: false,
  53. })
  54. })
  55. it('Renders the correct text for a file with the project_output_file provider', function () {
  56. renderWithEditorContext(
  57. <FileViewHeader
  58. file={projectOutputFile}
  59. storeReferencesKeys={() => {}}
  60. />
  61. )
  62. screen.getByText('Imported from the output of', { exact: false })
  63. screen.getByText('Another project', { exact: false })
  64. screen.getByText('/source-entity-path.ext, at 3:24 am Wed, 17th Feb 21', {
  65. exact: false,
  66. })
  67. })
  68. })
  69. describe('The download button', function () {
  70. it('exists', function () {
  71. renderWithEditorContext(<FileViewHeader file={urlFile} />)
  72. screen.getByText('Download')
  73. })
  74. })
  75. it('should use importedAt as timestamp when present in the linked file data', function () {
  76. const fileFromServer = {
  77. name: 'example.tex',
  78. linkedFileData: {
  79. v1_source_doc_id: 'v1-source-id',
  80. source_project_id: 'source-project-id',
  81. source_entity_path: '/source-entity-path.ext',
  82. provider: 'project_file',
  83. importer_id: USER_ID,
  84. importedAt: new Date(2024, 8, 16, 1, 30).getTime(),
  85. },
  86. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  87. }
  88. // FIXME: This should be tested through the <EditorAndPdf /> component instead
  89. const fileShown = fileViewFile(fileFromServer)
  90. renderWithEditorContext(<FileViewHeader file={fileShown} />)
  91. screen.getByText('Imported from', { exact: false })
  92. screen.getByText('Another project', { exact: false })
  93. screen.getByText('/source-entity-path.ext, at 1:30 am Mon, 16th Sep 24', {
  94. exact: false,
  95. })
  96. })
  97. })