suggestedOwners.spec.jsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import SuggestedOwners from 'app/components/group/suggestedOwners/suggestedOwners';
  4. import MemberListStore from 'app/stores/memberListStore';
  5. import CommitterStore from 'app/stores/committerStore';
  6. import {Client} from 'app/api';
  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 routerContext = TestStubs.routerContext([
  14. {
  15. organization,
  16. },
  17. ]);
  18. const endpoint = `/projects/${organization.slug}/${project.slug}/events/${event.id}`;
  19. beforeEach(function () {
  20. MemberListStore.loadInitialData([user, TestStubs.CommitAuthor()]);
  21. });
  22. afterEach(function () {
  23. Client.clearMockResponses();
  24. CommitterStore.reset();
  25. });
  26. it('Renders suggested owners', async function () {
  27. Client.addMockResponse({
  28. url: `${endpoint}/committers/`,
  29. body: {
  30. committers: [
  31. {
  32. author: TestStubs.CommitAuthor(),
  33. commits: [TestStubs.Commit()],
  34. },
  35. ],
  36. },
  37. });
  38. Client.addMockResponse({
  39. url: `${endpoint}/owners/`,
  40. body: {
  41. owners: [{type: 'user', ...user}],
  42. rules: [[['path', 'sentry/tagstore/*'], [['user', user.email]]]],
  43. },
  44. });
  45. const wrapper = mountWithTheme(
  46. <SuggestedOwners project={project} group={group} event={event} />,
  47. routerContext
  48. );
  49. await tick();
  50. await tick(); // Run Store.load and fire Action.loadSuccess
  51. await tick(); // Run Store.loadSuccess
  52. wrapper.update();
  53. expect(wrapper.find('ActorAvatar')).toHaveLength(2);
  54. // One includes committers, the other includes ownership rules
  55. expect(
  56. wrapper
  57. .find('SuggestedOwnerHovercard')
  58. .map(node => node.props())
  59. .some(p => p.commits === undefined && p.rules !== undefined)
  60. ).toBe(true);
  61. expect(
  62. wrapper
  63. .find('SuggestedOwnerHovercard')
  64. .map(node => node.props())
  65. .some(p => p.commits !== undefined && p.rules === undefined)
  66. ).toBe(true);
  67. });
  68. it('does not call committers endpoint if `group.firstRelease` does not exist', async function () {
  69. const committers = Client.addMockResponse({
  70. url: `${endpoint}/committers/`,
  71. body: {
  72. committers: [
  73. {
  74. author: TestStubs.CommitAuthor(),
  75. commits: [TestStubs.Commit()],
  76. },
  77. ],
  78. },
  79. });
  80. Client.addMockResponse({
  81. url: `${endpoint}/owners/`,
  82. body: {
  83. owners: [{type: 'user', ...user}],
  84. rules: [[['path', 'sentry/tagstore/*'], [['user', user.email]]]],
  85. },
  86. });
  87. const wrapper = mountWithTheme(
  88. <SuggestedOwners project={project} group={TestStubs.Group()} event={event} />,
  89. routerContext
  90. );
  91. await tick();
  92. await tick(); // Run Store.load and fire Action.loadSuccess
  93. await tick(); // Run Store.loadSuccess
  94. wrapper.update();
  95. expect(committers).not.toHaveBeenCalled();
  96. expect(wrapper.find('ActorAvatar')).toHaveLength(1);
  97. });
  98. it('Merges owner matching rules and having suspect commits', async function () {
  99. const author = TestStubs.CommitAuthor();
  100. Client.addMockResponse({
  101. url: `${endpoint}/committers/`,
  102. body: {
  103. committers: [{author, commits: [TestStubs.Commit()]}],
  104. },
  105. });
  106. Client.addMockResponse({
  107. url: `${endpoint}/owners/`,
  108. body: {
  109. owners: [{type: 'user', ...author}],
  110. rules: [[['path', 'sentry/tagstore/*'], [['user', author.email]]]],
  111. },
  112. });
  113. const wrapper = mountWithTheme(
  114. <SuggestedOwners project={project} group={group} event={event} />,
  115. routerContext
  116. );
  117. await tick();
  118. await tick(); // Run Store.load and fire Action.loadSuccess
  119. await tick(); // Run Store.loadSuccess
  120. wrapper.update();
  121. expect(wrapper.find('ActorAvatar')).toHaveLength(1);
  122. const hovercardProps = wrapper.find('SuggestedOwnerHovercard').props();
  123. expect(hovercardProps.commits).not.toBeUndefined();
  124. expect(hovercardProps.rules).not.toBeUndefined();
  125. });
  126. });