file-view-refresh-error.test.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { render, screen } from '@testing-library/react'
  2. import FileViewRefreshError from '@/features/file-view/components/file-view-refresh-error'
  3. import type { BinaryFile } from '@/features/file-view/types/binary-file'
  4. import { expect } from 'chai'
  5. describe('<FileViewRefreshError />', function () {
  6. describe('<FileViewMendeleyOrZoteroRefreshError />', function () {
  7. it('shows correct error message for mendeley', async function () {
  8. const mendeleyFile: BinaryFile<'mendeley'> = {
  9. id: '123abc',
  10. _id: '123abc',
  11. linkedFileData: {
  12. provider: 'mendeley',
  13. importer_id: 'user123456',
  14. },
  15. created: new Date(2023, 1, 17, 3, 24),
  16. name: 'references.bib',
  17. type: 'file',
  18. selected: true,
  19. }
  20. render(
  21. <FileViewRefreshError
  22. file={mendeleyFile}
  23. refreshError="error_message"
  24. />
  25. )
  26. screen.getByText(/Something’s not right!/)
  27. screen.getByText(
  28. /It looks like you need to re-link your Mendeley account./
  29. )
  30. const goToSettingsLink = screen.getByRole('link', {
  31. name: 'Go to settings',
  32. })
  33. expect(goToSettingsLink.getAttribute('href')).to.equal('/user/settings')
  34. })
  35. it('shows correct error message for zotero', async function () {
  36. const zoteroFile: BinaryFile<'zotero'> = {
  37. id: '123abc',
  38. _id: '123abc',
  39. linkedFileData: {
  40. provider: 'zotero',
  41. importer_id: 'user123456',
  42. },
  43. created: new Date(2023, 1, 17, 3, 24),
  44. name: 'references.bib',
  45. type: 'file',
  46. selected: true,
  47. }
  48. render(
  49. <FileViewRefreshError file={zoteroFile} refreshError="error_message" />
  50. )
  51. screen.getByText(/Something’s not right!/)
  52. screen.getByText(/It looks like you need to re-link your Zotero account./)
  53. const goToSettingsLink = screen.getByRole('link', {
  54. name: 'Go to settings',
  55. })
  56. expect(goToSettingsLink.getAttribute('href')).to.equal('/user/settings')
  57. })
  58. })
  59. describe('<FileViewDefaultRefreshError />', function () {
  60. it('shows correct error message', function () {
  61. const anotherProjectFile: BinaryFile<'project_file'> = {
  62. id: '123abc',
  63. _id: '123abc',
  64. linkedFileData: {
  65. provider: 'project_file',
  66. source_project_id: 'some-id',
  67. source_entity_path: '/path/',
  68. },
  69. created: new Date(2023, 1, 17, 3, 24),
  70. name: 'frog.jpg',
  71. type: 'file',
  72. selected: true,
  73. }
  74. render(
  75. <FileViewRefreshError
  76. file={anotherProjectFile}
  77. refreshError="An error message"
  78. />
  79. )
  80. screen.getByText('Access Denied: An error message')
  81. })
  82. })
  83. })