useOwnerOptions.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import {ProjectFixture} from 'sentry-fixture/project';
  2. import {TeamFixture} from 'sentry-fixture/team';
  3. import {UserFixture} from 'sentry-fixture/user';
  4. import {renderHook} from 'sentry-test/reactTestingLibrary';
  5. import {useOwnerOptions} from './useOwnerOptions';
  6. describe('useOwnerOptions', () => {
  7. const mockUsers = [UserFixture()];
  8. const mockTeams = [TeamFixture()];
  9. it('includes members and teams', () => {
  10. const {result} = renderHook(useOwnerOptions, {
  11. initialProps: {
  12. teams: mockTeams,
  13. members: mockUsers,
  14. },
  15. });
  16. expect(result.current).toEqual([
  17. {
  18. label: 'My Teams',
  19. options: [
  20. {
  21. label: '#team-slug',
  22. value: 'team:1',
  23. leadingItems: expect.anything(),
  24. },
  25. ],
  26. },
  27. {
  28. label: 'Members',
  29. options: [
  30. {
  31. label: 'Foo Bar',
  32. value: 'user:1',
  33. leadingItems: expect.anything(),
  34. },
  35. ],
  36. },
  37. {label: 'Other Teams', options: []},
  38. {label: 'Disabled Teams', options: []},
  39. ]);
  40. });
  41. it('separates my teams and other teams', () => {
  42. const teams = [
  43. TeamFixture(),
  44. TeamFixture({id: '2', slug: 'other-team', isMember: false}),
  45. ];
  46. const {result} = renderHook(useOwnerOptions, {
  47. initialProps: {teams},
  48. });
  49. expect(result.current).toEqual([
  50. {
  51. label: 'My Teams',
  52. options: [
  53. {
  54. label: '#team-slug',
  55. value: 'team:1',
  56. leadingItems: expect.anything(),
  57. },
  58. ],
  59. },
  60. {
  61. label: 'Members',
  62. options: [],
  63. },
  64. {
  65. label: 'Other Teams',
  66. options: [
  67. {
  68. label: '#other-team',
  69. value: 'team:2',
  70. leadingItems: expect.anything(),
  71. },
  72. ],
  73. },
  74. {label: 'Disabled Teams', options: []},
  75. ]);
  76. });
  77. it('disables teams not associated with the projects', () => {
  78. const project1 = ProjectFixture();
  79. const project2 = ProjectFixture({id: '2', slug: 'other-project'});
  80. const teamWithProject1 = TeamFixture({projects: [project1], slug: 'my-team'});
  81. const teamWithProject2 = TeamFixture({
  82. id: '2',
  83. projects: [project2],
  84. slug: 'other-team',
  85. isMember: false,
  86. });
  87. const teamWithoutProject = TeamFixture({id: '3', slug: 'disabled-team'});
  88. const teams = [teamWithProject1, teamWithProject2, teamWithoutProject];
  89. const {result} = renderHook(useOwnerOptions, {
  90. initialProps: {
  91. memberOfProjectSlugs: [project1.slug, project2.slug],
  92. teams,
  93. },
  94. });
  95. expect(result.current).toEqual([
  96. {
  97. label: 'My Teams',
  98. options: [
  99. {
  100. label: '#my-team',
  101. value: 'team:1',
  102. leadingItems: expect.anything(),
  103. },
  104. ],
  105. },
  106. {
  107. label: 'Members',
  108. options: [],
  109. },
  110. {
  111. label: 'Other Teams',
  112. options: [
  113. {
  114. label: '#other-team',
  115. value: 'team:2',
  116. leadingItems: expect.anything(),
  117. },
  118. ],
  119. },
  120. {
  121. label: 'Disabled Teams',
  122. options: [
  123. {
  124. label: '#disabled-team',
  125. value: 'team:3',
  126. leadingItems: expect.anything(),
  127. disabled: true,
  128. tooltip: '#disabled-team is not a member of the selected projects',
  129. tooltipOptions: {position: 'left'},
  130. },
  131. ],
  132. },
  133. ]);
  134. });
  135. });