project-list-title.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { render, screen } from '@testing-library/react'
  2. import { Filter } from '../../../../../frontend/js/features/project-list/context/project-list-context'
  3. import { Tag } from '../../../../../app/src/Features/Tags/types'
  4. import ProjectListTitle from '../../../../../frontend/js/features/project-list/components/title/project-list-title'
  5. describe('<ProjectListTitle />', function () {
  6. type TestCase = {
  7. filter: Filter
  8. selectedTag: Tag | undefined
  9. expectedText: string
  10. selectedTagId: string | undefined
  11. }
  12. const testCases: Array<TestCase> = [
  13. // Filter, without tag
  14. {
  15. filter: 'all',
  16. selectedTag: undefined,
  17. expectedText: 'all projects',
  18. selectedTagId: undefined,
  19. },
  20. {
  21. filter: 'owned',
  22. selectedTag: undefined,
  23. expectedText: 'your projects',
  24. selectedTagId: undefined,
  25. },
  26. {
  27. filter: 'shared',
  28. selectedTag: undefined,
  29. expectedText: 'shared with you',
  30. selectedTagId: undefined,
  31. },
  32. {
  33. filter: 'archived',
  34. selectedTag: undefined,
  35. expectedText: 'archived projects',
  36. selectedTagId: undefined,
  37. },
  38. {
  39. filter: 'trashed',
  40. selectedTag: undefined,
  41. expectedText: 'trashed projects',
  42. selectedTagId: undefined,
  43. },
  44. // Tags
  45. {
  46. filter: 'all',
  47. selectedTag: undefined,
  48. expectedText: 'uncategorized',
  49. selectedTagId: 'uncategorized',
  50. },
  51. {
  52. filter: 'all',
  53. selectedTag: { _id: '', user_id: '', name: 'sometag' },
  54. expectedText: 'sometag',
  55. selectedTagId: '',
  56. },
  57. {
  58. filter: 'shared',
  59. selectedTag: { _id: '', user_id: '', name: 'othertag' },
  60. expectedText: 'othertag',
  61. selectedTagId: '',
  62. },
  63. ]
  64. for (const testCase of testCases) {
  65. it(`renders the title text for filter: ${testCase.filter}, tag: ${testCase?.selectedTag?.name}`, function () {
  66. render(
  67. <ProjectListTitle
  68. filter={testCase.filter}
  69. selectedTag={testCase.selectedTag}
  70. selectedTagId={testCase.selectedTagId}
  71. />
  72. )
  73. screen.getByText(new RegExp(testCase.expectedText, 'i'))
  74. })
  75. }
  76. })