suggestedOwners.spec.jsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import {Client} from 'sentry/api';
  3. import SuggestedOwners from 'sentry/components/group/suggestedOwners/suggestedOwners';
  4. import CommitterStore from 'sentry/stores/committerStore';
  5. import MemberListStore from 'sentry/stores/memberListStore';
  6. import TeamStore from 'sentry/stores/teamStore';
  7. describe('SuggestedOwners', function () {
  8. const user = TestStubs.User();
  9. const organization = TestStubs.Organization();
  10. const project = TestStubs.Project();
  11. const event = TestStubs.Event();
  12. const group = TestStubs.Group({firstRelease: {}});
  13. const endpoint = `/projects/${organization.slug}/${project.slug}/events/${event.id}`;
  14. beforeEach(function () {
  15. CommitterStore.init();
  16. TeamStore.init();
  17. MemberListStore.loadInitialData([user, TestStubs.CommitAuthor()]);
  18. Client.addMockResponse({
  19. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  20. body: [],
  21. });
  22. Client.addMockResponse({
  23. url: `/prompts-activity/`,
  24. body: {},
  25. });
  26. Client.addMockResponse({
  27. url: `/organizations/${organization.slug}/code-mappings/`,
  28. query: {project: -1},
  29. method: 'GET',
  30. body: [],
  31. });
  32. });
  33. afterEach(function () {
  34. Client.clearMockResponses();
  35. });
  36. it('Renders suggested owners', async function () {
  37. Client.addMockResponse({
  38. url: `${endpoint}/committers/`,
  39. body: {
  40. committers: [
  41. {
  42. author: TestStubs.CommitAuthor(),
  43. commits: [TestStubs.Commit()],
  44. },
  45. ],
  46. },
  47. });
  48. Client.addMockResponse({
  49. url: `${endpoint}/owners/`,
  50. body: {
  51. owners: [{type: 'user', ...user}],
  52. rules: [[['path', 'sentry/tagstore/*'], [['user', user.email]]]],
  53. },
  54. });
  55. render(<SuggestedOwners project={project} group={group} event={event} />, {
  56. organization,
  57. });
  58. await waitFor(() =>
  59. expect(screen.getAllByTestId('suggested-assignee')).toHaveLength(2)
  60. );
  61. userEvent.hover(screen.getAllByTestId('suggested-assignee')[0]);
  62. });
  63. it('Merges owner matching rules and having suspect commits', async function () {
  64. const author = TestStubs.CommitAuthor();
  65. Client.addMockResponse({
  66. url: `${endpoint}/committers/`,
  67. body: {
  68. committers: [{author, commits: [TestStubs.Commit()]}],
  69. },
  70. });
  71. Client.addMockResponse({
  72. url: `${endpoint}/owners/`,
  73. body: {
  74. owners: [{type: 'user', ...author}],
  75. rules: [[['path', 'sentry/tagstore/*'], [['user', author.email]]]],
  76. },
  77. });
  78. render(<SuggestedOwners project={project} group={group} event={event} />, {
  79. organization,
  80. });
  81. userEvent.hover(await screen.findByTestId('suggested-assignee'));
  82. expect(await screen.findByText('sentry/tagstore/*')).toBeInTheDocument();
  83. expect(screen.getByText('Matching Ownership Rules')).toBeInTheDocument();
  84. });
  85. it('displays two teams when there are committers', async function () {
  86. const team1 = TestStubs.Team({slug: 'team-1', id: '1'});
  87. const team2 = TestStubs.Team({slug: 'team-2', id: '2'});
  88. TeamStore.loadInitialData([team1, team2], false, null);
  89. Client.addMockResponse({
  90. url: `${endpoint}/committers/`,
  91. body: {
  92. committers: [{author: TestStubs.CommitAuthor(), commits: [TestStubs.Commit()]}],
  93. },
  94. });
  95. Client.addMockResponse({
  96. url: `${endpoint}/owners/`,
  97. body: {
  98. owners: [
  99. {type: 'team', id: team1.id, name: team1.slug},
  100. {type: 'team', id: team2.id, name: team2.slug},
  101. ],
  102. rules: [[['path', 'sentry/tagstore/*'], [['team', team1.slug]]]],
  103. },
  104. });
  105. render(<SuggestedOwners project={project} group={group} event={event} />, {
  106. organization,
  107. });
  108. await waitFor(() =>
  109. expect(screen.getAllByTestId('suggested-assignee')).toHaveLength(3)
  110. );
  111. });
  112. it('displays release committers', async function () {
  113. const team1 = TestStubs.Team({slug: 'team-1', id: '1'});
  114. const team2 = TestStubs.Team({slug: 'team-2', id: '2'});
  115. TeamStore.loadInitialData([team1, team2], false, null);
  116. Client.addMockResponse({
  117. url: `${endpoint}/committers/`,
  118. body: {
  119. committers: [],
  120. releaseCommitters: [
  121. {
  122. author: TestStubs.CommitAuthor(),
  123. commits: [TestStubs.Commit()],
  124. release: TestStubs.Release(),
  125. },
  126. ],
  127. },
  128. });
  129. Client.addMockResponse({
  130. url: `${endpoint}/owners/`,
  131. body: {owners: [], rules: []},
  132. });
  133. render(<SuggestedOwners project={project} group={group} event={event} />, {
  134. organization,
  135. });
  136. userEvent.hover(await screen.findByTestId('suggested-assignee'));
  137. expect(await screen.findByText('Suspect Release')).toBeInTheDocument();
  138. expect(screen.getByText('last committed')).toBeInTheDocument();
  139. });
  140. });