groupActivity.spec.jsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {act} from 'sentry-test/reactTestingLibrary';
  4. import NoteInput from 'sentry/components/activity/note/input';
  5. import ConfigStore from 'sentry/stores/configStore';
  6. import GroupStore from 'sentry/stores/groupStore';
  7. import OrganizationStore from 'sentry/stores/organizationStore';
  8. import ProjectsStore from 'sentry/stores/projectsStore';
  9. import TeamStore from 'sentry/stores/teamStore';
  10. import {GroupActivity} from 'sentry/views/organizationGroupDetails/groupActivity';
  11. describe('GroupActivity', function () {
  12. let project;
  13. beforeEach(function () {
  14. project = TestStubs.Project();
  15. act(() => ProjectsStore.loadInitialData([project]));
  16. jest.spyOn(ConfigStore, 'get').mockImplementation(key => {
  17. if (key === 'user') {
  18. return {
  19. id: '123',
  20. };
  21. }
  22. return {};
  23. });
  24. });
  25. function createWrapper({activity, organization: additionalOrg} = {}) {
  26. const group = TestStubs.Group({
  27. id: '1337',
  28. activity: activity || [
  29. {type: 'note', id: 'note-1', data: {text: 'Test Note'}, user: TestStubs.User()},
  30. ],
  31. project,
  32. });
  33. const {organization, routerContext} = initializeOrg({
  34. organization: additionalOrg,
  35. group,
  36. });
  37. act(() => TeamStore.loadInitialData([TestStubs.Team({id: '999', slug: 'no-team'})]));
  38. act(() => OrganizationStore.onUpdate(organization, {replace: true}));
  39. return mountWithTheme(
  40. <GroupActivity
  41. api={new MockApiClient()}
  42. params={{orgId: 'org-slug'}}
  43. group={group}
  44. organization={organization}
  45. />,
  46. routerContext
  47. );
  48. }
  49. it('renders a NoteInput', function () {
  50. const wrapper = createWrapper();
  51. expect(wrapper.find(NoteInput)).toHaveLength(1);
  52. });
  53. it('renders a marked reviewed activity', function () {
  54. const wrapper = createWrapper({
  55. activity: [
  56. {type: 'mark_reviewed', id: 'reviewed-1', data: {}, user: TestStubs.User()},
  57. ],
  58. });
  59. expect(wrapper.find('GroupActivityItem').text()).toContain(
  60. 'marked this issue as reviewed'
  61. );
  62. });
  63. it('renders a assigned to self activity', function () {
  64. const user = TestStubs.User({id: '301', name: 'Mark'});
  65. const wrapper = createWrapper({
  66. activity: [
  67. {
  68. data: {
  69. assignee: user.id,
  70. assigneeEmail: user.email,
  71. assigneeType: 'user',
  72. },
  73. dateCreated: '2021-10-01T15:31:38.950115Z',
  74. id: '117',
  75. type: 'assigned',
  76. user,
  77. },
  78. ],
  79. });
  80. expect(wrapper.find('GroupActivityItem').text()).toContain(
  81. 'assigned this issue to themselves'
  82. );
  83. });
  84. it('resolved in commit with no releases', function () {
  85. const wrapper = createWrapper({
  86. activity: [
  87. {
  88. type: 'set_resolved_in_commit',
  89. id: '123',
  90. data: {
  91. author: 'hello',
  92. commit: {
  93. id: 'komal-commit',
  94. repository: {},
  95. releases: [],
  96. },
  97. },
  98. user: TestStubs.User(),
  99. },
  100. ],
  101. });
  102. expect(wrapper.find('GroupActivityItem').text()).toContain(
  103. 'Foo Bar marked this issue as resolved in komal-commit'
  104. );
  105. });
  106. it('resolved in commit with one release', function () {
  107. const wrapper = createWrapper({
  108. activity: [
  109. {
  110. type: 'set_resolved_in_commit',
  111. id: '123',
  112. data: {
  113. author: 'hello',
  114. commit: {
  115. id: 'komal-commit',
  116. repository: {},
  117. releases: [
  118. {
  119. dateCreated: '2022-05-01',
  120. dateReleased: '2022-05-02',
  121. version: 'random',
  122. },
  123. ],
  124. },
  125. },
  126. user: TestStubs.User(),
  127. },
  128. ],
  129. });
  130. expect(wrapper.find('GroupActivityItem').text()).toContain(
  131. 'Foo Bar marked this issue as resolved in komal-commit This commit was released in random'
  132. );
  133. });
  134. it('resolved in commit with multiple releases', function () {
  135. const wrapper = createWrapper({
  136. activity: [
  137. {
  138. type: 'set_resolved_in_commit',
  139. id: '123',
  140. data: {
  141. commit: {
  142. id: 'komal-commit',
  143. repository: {},
  144. releases: [
  145. {
  146. dateCreated: '2022-05-01',
  147. dateReleased: '2022-05-02',
  148. version: 'random',
  149. },
  150. {
  151. dateCreated: '2022-06-01',
  152. dateReleased: '2022-06-02',
  153. version: 'newest',
  154. },
  155. {
  156. dateCreated: '2021-08-03',
  157. dateReleased: '2021-08-03',
  158. version: 'oldest-release',
  159. },
  160. {
  161. dateCreated: '2022-04-21',
  162. dateReleased: '2022-04-21',
  163. version: 'randomTwo',
  164. },
  165. ],
  166. },
  167. },
  168. user: TestStubs.User(),
  169. },
  170. ],
  171. });
  172. expect(wrapper.find('GroupActivityItem').text()).toContain(
  173. 'Foo Bar marked this issue as resolved in komal-commit This commit was released in oldest-release and 3 others'
  174. );
  175. });
  176. it('requests assignees that are not in the team store', async function () {
  177. const team = TestStubs.Team({id: '123', name: 'workflow'});
  178. const teamRequest = MockApiClient.addMockResponse({
  179. url: `/organizations/org-slug/teams/`,
  180. body: [team],
  181. });
  182. const wrapper = createWrapper({
  183. activity: [
  184. {
  185. id: '123',
  186. user: null,
  187. type: 'assigned',
  188. data: {
  189. assignee: team.id,
  190. assigneeEmail: null,
  191. assigneeType: 'team',
  192. },
  193. dateCreated: '2021-10-28T13:40:10.634821Z',
  194. },
  195. ],
  196. });
  197. await act(() => tick());
  198. wrapper.update();
  199. expect(teamRequest).toHaveBeenCalledTimes(1);
  200. expect(wrapper.find('GroupActivityItem').text()).toContain(
  201. 'assigned this issue to #team-slug'
  202. );
  203. });
  204. describe('Delete', function () {
  205. let wrapper;
  206. let deleteMock;
  207. beforeEach(function () {
  208. deleteMock = MockApiClient.addMockResponse({
  209. url: '/issues/1337/comments/note-1/',
  210. method: 'DELETE',
  211. });
  212. wrapper = createWrapper();
  213. });
  214. it('should do nothing if not present in GroupStore', function () {
  215. jest.spyOn(GroupStore, 'removeActivity').mockImplementation(() => -1); // not found
  216. // Would rather call simulate on the actual component but it's in a styled component
  217. // that is only visible on hover
  218. wrapper.find('NoteHeader').prop('onDelete')();
  219. expect(deleteMock).not.toHaveBeenCalled();
  220. });
  221. it('should remove remove the item from the GroupStore make a DELETE API request', function () {
  222. jest.spyOn(GroupStore, 'removeActivity').mockImplementation(() => 1);
  223. // Would rather call simulate on the actual component but it's in a styled component
  224. // that is only visible on hover
  225. wrapper.find('NoteHeader').prop('onDelete')();
  226. expect(deleteMock).toHaveBeenCalledTimes(1);
  227. });
  228. });
  229. });