groupActivity.spec.jsx 7.5 KB

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