overview.actions.spec.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. import {Fragment} from 'react';
  2. import {GlobalSelectionFixture} from 'sentry-fixture/globalSelection';
  3. import {GroupFixture} from 'sentry-fixture/group';
  4. import {GroupStatsFixture} from 'sentry-fixture/groupStats';
  5. import {LocationFixture} from 'sentry-fixture/locationFixture';
  6. import {OrganizationFixture} from 'sentry-fixture/organization';
  7. import {ProjectFixture} from 'sentry-fixture/project';
  8. import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
  9. import {TagsFixture} from 'sentry-fixture/tags';
  10. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  11. import Indicators from 'sentry/components/indicators';
  12. import GroupStore from 'sentry/stores/groupStore';
  13. import IssueListCacheStore from 'sentry/stores/IssueListCacheStore';
  14. import SelectedGroupStore from 'sentry/stores/selectedGroupStore';
  15. import TagStore from 'sentry/stores/tagStore';
  16. import {PriorityLevel} from 'sentry/types';
  17. import IssueListOverview from 'sentry/views/issueList/overview';
  18. const DEFAULT_LINKS_HEADER =
  19. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575731:0:1>; rel="previous"; results="false"; cursor="1443575731:0:1", ' +
  20. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575000:0:0>; rel="next"; results="true"; cursor="1443575000:0:0"';
  21. describe('IssueListOverview (actions)', function () {
  22. const project = ProjectFixture({
  23. id: '3559',
  24. name: 'Foo Project',
  25. slug: 'project-slug',
  26. firstEvent: new Date().toISOString(),
  27. });
  28. const tags = TagsFixture();
  29. const groupStats = GroupStatsFixture();
  30. const api = new MockApiClient();
  31. const organization = OrganizationFixture({features: ['issue-priority-ui']});
  32. beforeEach(function () {
  33. MockApiClient.clearMockResponses();
  34. GroupStore.reset();
  35. SelectedGroupStore.reset();
  36. IssueListCacheStore.reset();
  37. MockApiClient.addMockResponse({
  38. url: '/organizations/org-slug/issues-stats/',
  39. body: [groupStats],
  40. });
  41. MockApiClient.addMockResponse({
  42. url: '/organizations/org-slug/searches/',
  43. body: [],
  44. });
  45. MockApiClient.addMockResponse({
  46. url: '/organizations/org-slug/recent-searches/',
  47. body: [],
  48. });
  49. MockApiClient.addMockResponse({
  50. url: '/organizations/org-slug/recent-searches/',
  51. method: 'POST',
  52. body: [],
  53. });
  54. MockApiClient.addMockResponse({
  55. url: '/organizations/org-slug/issues-count/',
  56. method: 'GET',
  57. body: [{}],
  58. });
  59. MockApiClient.addMockResponse({
  60. url: '/organizations/org-slug/processingissues/',
  61. method: 'GET',
  62. body: [],
  63. });
  64. MockApiClient.addMockResponse({
  65. url: '/organizations/org-slug/tags/',
  66. method: 'GET',
  67. body: [],
  68. });
  69. MockApiClient.addMockResponse({
  70. url: '/organizations/org-slug/users/',
  71. method: 'GET',
  72. body: [],
  73. });
  74. MockApiClient.addMockResponse({
  75. url: '/organizations/org-slug/sent-first-event/',
  76. body: {sentFirstEvent: true},
  77. });
  78. MockApiClient.addMockResponse({
  79. url: '/organizations/org-slug/projects/',
  80. body: [],
  81. });
  82. TagStore.init?.();
  83. });
  84. const defaultProps = {
  85. api,
  86. savedSearchLoading: false,
  87. savedSearches: [],
  88. useOrgSavedSearches: true,
  89. selection: GlobalSelectionFixture(),
  90. organization,
  91. tags: [
  92. tags.reduce((acc, tag) => {
  93. acc[tag.key] = tag;
  94. return acc;
  95. }),
  96. ],
  97. savedSearch: null,
  98. selectedSearchId: null,
  99. ...RouteComponentPropsFixture({
  100. location: LocationFixture({
  101. query: {query: 'is:unresolved issue.priority:[high,medium]'},
  102. }),
  103. params: {orgId: organization.slug, projectId: project.slug, searchId: undefined},
  104. }),
  105. };
  106. describe('status', function () {
  107. const group1 = GroupFixture({
  108. id: '1',
  109. culprit: 'Group 1',
  110. shortId: 'JAVASCRIPT-1',
  111. });
  112. const group2 = GroupFixture({
  113. id: '2',
  114. culprit: 'Group 2',
  115. shortId: 'JAVASCRIPT-2',
  116. });
  117. beforeEach(() => {
  118. MockApiClient.addMockResponse({
  119. url: '/organizations/org-slug/issues/',
  120. body: [group1, group2],
  121. headers: {Link: DEFAULT_LINKS_HEADER},
  122. });
  123. });
  124. it('removes issues after resolving', async function () {
  125. const updateIssueMock = MockApiClient.addMockResponse({
  126. url: '/organizations/org-slug/issues/',
  127. method: 'PUT',
  128. });
  129. render(<IssueListOverview {...defaultProps} />, {organization});
  130. const groups = await screen.findAllByTestId('group');
  131. await userEvent.click(
  132. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  133. );
  134. expect(screen.getByText('Group 1')).toBeInTheDocument();
  135. expect(screen.getByText('Group 2')).toBeInTheDocument();
  136. // After action, will refetch so need to mock that response
  137. MockApiClient.addMockResponse({
  138. url: '/organizations/org-slug/issues/',
  139. body: [group2],
  140. headers: {Link: DEFAULT_LINKS_HEADER},
  141. });
  142. await userEvent.click(screen.getByRole('button', {name: 'Resolve'}));
  143. expect(updateIssueMock).toHaveBeenCalledWith(
  144. '/organizations/org-slug/issues/',
  145. expect.objectContaining({
  146. query: expect.objectContaining({id: ['1']}),
  147. data: {status: 'resolved', statusDetails: {}, substatus: null},
  148. })
  149. );
  150. expect(screen.queryByText('Group 1')).not.toBeInTheDocument();
  151. expect(screen.getByText('Group 2')).toBeInTheDocument();
  152. });
  153. it('can undo resolve action', async function () {
  154. const updateIssueMock = MockApiClient.addMockResponse({
  155. url: '/organizations/org-slug/issues/',
  156. method: 'PUT',
  157. });
  158. render(
  159. <Fragment>
  160. <IssueListOverview {...defaultProps} />
  161. <Indicators />
  162. </Fragment>,
  163. {organization}
  164. );
  165. const groups = await screen.findAllByTestId('group');
  166. await userEvent.click(
  167. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  168. );
  169. expect(screen.getByText('Group 1')).toBeInTheDocument();
  170. expect(screen.getByText('Group 2')).toBeInTheDocument();
  171. // After action, will refetch so need to mock that response
  172. MockApiClient.addMockResponse({
  173. url: '/organizations/org-slug/issues/',
  174. body: [group2],
  175. headers: {Link: DEFAULT_LINKS_HEADER},
  176. });
  177. await userEvent.click(screen.getByRole('button', {name: 'Resolve'}));
  178. expect(updateIssueMock).toHaveBeenCalledWith(
  179. '/organizations/org-slug/issues/',
  180. expect.objectContaining({
  181. query: expect.objectContaining({id: ['1']}),
  182. data: {status: 'resolved', statusDetails: {}, substatus: null},
  183. })
  184. );
  185. expect(screen.queryByText('Group 1')).not.toBeInTheDocument();
  186. expect(screen.getByText('Group 2')).toBeInTheDocument();
  187. // Should show a toast message
  188. expect(screen.getByText('Resolved JAVASCRIPT-1')).toBeInTheDocument();
  189. // Clicking the undo button makes a call to set the status back to unresolved
  190. MockApiClient.addMockResponse({
  191. url: '/organizations/org-slug/issues/',
  192. body: [group1, group2],
  193. headers: {Link: DEFAULT_LINKS_HEADER},
  194. });
  195. await userEvent.click(screen.getByRole('button', {name: 'Undo'}));
  196. expect(updateIssueMock).toHaveBeenLastCalledWith(
  197. '/organizations/org-slug/issues/',
  198. expect.objectContaining({
  199. query: expect.objectContaining({id: ['1']}),
  200. data: {status: 'unresolved', statusDetails: {}},
  201. })
  202. );
  203. expect(await screen.findByText('Group 1')).toBeInTheDocument();
  204. });
  205. });
  206. describe('mark reviewed', function () {
  207. const group1 = GroupFixture({
  208. id: '1',
  209. culprit: 'Group 1',
  210. shortId: 'JAVASCRIPT-1',
  211. inbox: {},
  212. });
  213. const group2 = GroupFixture({
  214. id: '2',
  215. culprit: 'Group 2',
  216. shortId: 'JAVASCRIPT-2',
  217. inbox: {},
  218. });
  219. beforeEach(() => {
  220. MockApiClient.addMockResponse({
  221. url: '/organizations/org-slug/issues/',
  222. body: [group1, group2],
  223. headers: {Link: DEFAULT_LINKS_HEADER},
  224. });
  225. });
  226. it('removes issues after making reviewed (when on for review tab)', async function () {
  227. const updateIssueMock = MockApiClient.addMockResponse({
  228. url: '/organizations/org-slug/issues/',
  229. method: 'PUT',
  230. });
  231. render(
  232. <IssueListOverview
  233. {...defaultProps}
  234. {...RouteComponentPropsFixture({
  235. location: LocationFixture({
  236. query: {query: 'is:for_review'},
  237. }),
  238. params: {
  239. orgId: organization.slug,
  240. projectId: project.slug,
  241. searchId: undefined,
  242. },
  243. })}
  244. />,
  245. {organization}
  246. );
  247. const groups = await screen.findAllByTestId('group');
  248. await userEvent.click(
  249. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  250. );
  251. expect(screen.getByText('Group 1')).toBeInTheDocument();
  252. expect(screen.getByText('Group 2')).toBeInTheDocument();
  253. // After action, will refetch so need to mock that response
  254. MockApiClient.addMockResponse({
  255. url: '/organizations/org-slug/issues/',
  256. body: [group2],
  257. headers: {Link: DEFAULT_LINKS_HEADER},
  258. });
  259. await userEvent.click(screen.getByRole('button', {name: 'Mark Reviewed'}));
  260. expect(updateIssueMock).toHaveBeenCalledWith(
  261. '/organizations/org-slug/issues/',
  262. expect.objectContaining({
  263. query: expect.objectContaining({id: ['1']}),
  264. data: {inbox: false},
  265. })
  266. );
  267. expect(screen.queryByText('Group 1')).not.toBeInTheDocument();
  268. expect(screen.getByText('Group 2')).toBeInTheDocument();
  269. });
  270. });
  271. describe('priority', function () {
  272. const medPriorityGroup = GroupFixture({
  273. id: '1',
  274. priority: PriorityLevel.MEDIUM,
  275. culprit: 'Medium priority issue',
  276. });
  277. const highPriorityGroup = GroupFixture({
  278. id: '2',
  279. priority: PriorityLevel.HIGH,
  280. culprit: 'High priority issue',
  281. });
  282. beforeEach(() => {
  283. MockApiClient.addMockResponse({
  284. url: '/organizations/org-slug/issues/',
  285. body: [medPriorityGroup, highPriorityGroup],
  286. headers: {Link: DEFAULT_LINKS_HEADER},
  287. });
  288. });
  289. it('removes issues after reprioritizing (when excluding priorities)', async function () {
  290. const updateIssueMock = MockApiClient.addMockResponse({
  291. url: '/organizations/org-slug/issues/',
  292. method: 'PUT',
  293. });
  294. render(<IssueListOverview {...defaultProps} />, {organization});
  295. const groups = await screen.findAllByTestId('group');
  296. await userEvent.click(
  297. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  298. );
  299. expect(screen.getByText('Medium priority issue')).toBeInTheDocument();
  300. // After action, will refetch so need to mock that response
  301. MockApiClient.addMockResponse({
  302. url: '/organizations/org-slug/issues/',
  303. body: [highPriorityGroup],
  304. headers: {Link: DEFAULT_LINKS_HEADER},
  305. });
  306. await userEvent.click(screen.getByRole('button', {name: /more issue actions/i}));
  307. await userEvent.hover(screen.getByRole('menuitemradio', {name: /priority/i}));
  308. await userEvent.click(screen.getByRole('menuitemradio', {name: /low/i}));
  309. expect(updateIssueMock).toHaveBeenCalledWith(
  310. '/organizations/org-slug/issues/',
  311. expect.objectContaining({
  312. query: expect.objectContaining({id: ['1']}),
  313. data: {priority: PriorityLevel.LOW},
  314. })
  315. );
  316. expect(screen.queryByText('Medium priority issue')).not.toBeInTheDocument();
  317. });
  318. it('does not remove issues after reprioritizing (when query includes all priorities)', async function () {
  319. const updateIssueMock = MockApiClient.addMockResponse({
  320. url: '/organizations/org-slug/issues/',
  321. method: 'PUT',
  322. });
  323. render(
  324. <IssueListOverview
  325. {...defaultProps}
  326. {...RouteComponentPropsFixture({
  327. location: LocationFixture({
  328. query: {query: 'is:unresolved'},
  329. }),
  330. params: {
  331. orgId: organization.slug,
  332. projectId: project.slug,
  333. searchId: undefined,
  334. },
  335. })}
  336. />,
  337. {organization}
  338. );
  339. const groups = await screen.findAllByTestId('group');
  340. await userEvent.click(
  341. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  342. );
  343. expect(screen.getByText('Medium priority issue')).toBeInTheDocument();
  344. await userEvent.click(screen.getByRole('button', {name: /more issue actions/i}));
  345. await userEvent.hover(screen.getByRole('menuitemradio', {name: /priority/i}));
  346. await userEvent.click(screen.getByRole('menuitemradio', {name: /low/i}));
  347. expect(updateIssueMock).toHaveBeenCalledWith(
  348. '/organizations/org-slug/issues/',
  349. expect.objectContaining({
  350. query: expect.objectContaining({id: ['1']}),
  351. data: {priority: PriorityLevel.LOW},
  352. })
  353. );
  354. expect(screen.getByText('Medium priority issue')).toBeInTheDocument();
  355. });
  356. });
  357. });