overview.actions.spec.tsx 14 KB

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