file-view-header.test.jsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. describe('<FileViewHeader/>', function () {
  7. const urlFile = {
  8. name: 'example.tex',
  9. linkedFileData: {
  10. url: 'https://overleaf.com',
  11. provider: 'url',
  12. },
  13. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  14. }
  15. const projectFile = {
  16. name: 'example.tex',
  17. linkedFileData: {
  18. v1_source_doc_id: 'v1-source-id',
  19. source_project_id: 'source-project-id',
  20. source_entity_path: '/source-entity-path.ext',
  21. provider: 'project_file',
  22. importer_id: USER_ID,
  23. },
  24. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  25. }
  26. const projectOutputFile = {
  27. name: 'example.pdf',
  28. linkedFileData: {
  29. v1_source_doc_id: 'v1-source-id',
  30. source_output_file_path: '/source-entity-path.ext',
  31. provider: 'project_output_file',
  32. },
  33. created: new Date(2021, 1, 17, 3, 24).toISOString(),
  34. }
  35. beforeEach(function () {
  36. fetchMock.reset()
  37. })
  38. describe('header text', function () {
  39. it('Renders the correct text for a file with the url provider', function () {
  40. renderWithEditorContext(<FileViewHeader file={urlFile} />)
  41. screen.getByText('Imported from', { exact: false })
  42. screen.getByText('at 3:24 am Wed, 17th Feb 21', {
  43. exact: false,
  44. })
  45. })
  46. it('Renders the correct text for a file with the project_file provider', function () {
  47. renderWithEditorContext(<FileViewHeader file={projectFile} />)
  48. screen.getByText('Imported from', { exact: false })
  49. screen.getByText('Another project', { exact: false })
  50. screen.getByText('/source-entity-path.ext, at 3:24 am Wed, 17th Feb 21', {
  51. exact: false,
  52. })
  53. })
  54. it('Renders the correct text for a file with the project_output_file provider', function () {
  55. renderWithEditorContext(
  56. <FileViewHeader
  57. file={projectOutputFile}
  58. storeReferencesKeys={() => {}}
  59. />
  60. )
  61. screen.getByText('Imported from the output of', { exact: false })
  62. screen.getByText('Another project', { exact: false })
  63. screen.getByText('/source-entity-path.ext, at 3:24 am Wed, 17th Feb 21', {
  64. exact: false,
  65. })
  66. })
  67. })
  68. describe('The download button', function () {
  69. it('exists', function () {
  70. renderWithEditorContext(<FileViewHeader file={urlFile} />)
  71. screen.getByText('Download', { exact: false })
  72. })
  73. })
  74. })