project-list-title.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }
  11. const testCases: Array<TestCase> = [
  12. // Filter, without tag
  13. {
  14. filter: 'all',
  15. selectedTag: undefined,
  16. expectedText: 'all projects',
  17. },
  18. {
  19. filter: 'owned',
  20. selectedTag: undefined,
  21. expectedText: 'your projects',
  22. },
  23. {
  24. filter: 'shared',
  25. selectedTag: undefined,
  26. expectedText: 'shared with you',
  27. },
  28. {
  29. filter: 'archived',
  30. selectedTag: undefined,
  31. expectedText: 'archived projects',
  32. },
  33. {
  34. filter: 'trashed',
  35. selectedTag: undefined,
  36. expectedText: 'trashed projects',
  37. },
  38. // Tags
  39. {
  40. filter: 'all',
  41. selectedTag: { _id: '', user_id: '', name: 'sometag' },
  42. expectedText: 'sometag',
  43. },
  44. {
  45. filter: 'shared',
  46. selectedTag: { _id: '', user_id: '', name: 'othertag' },
  47. expectedText: 'othertag',
  48. },
  49. ]
  50. for (const testCase of testCases) {
  51. it(`renders the title text for filter: ${testCase.filter}, tag: ${testCase?.selectedTag?.name}`, function () {
  52. render(
  53. <ProjectListTitle
  54. filter={testCase.filter}
  55. selectedTag={testCase.selectedTag}
  56. />
  57. )
  58. screen.getByText(new RegExp(testCase.expectedText, 'i'))
  59. })
  60. }
  61. })