overview.actions.spec.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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';
  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. location: LocationFixture({
  107. query: {query: 'is:unresolved issue.priority:[high,medium]'},
  108. }),
  109. params: {orgId: organization.slug, projectId: project.slug, searchId: undefined},
  110. }),
  111. };
  112. describe('status', function () {
  113. const group1 = GroupFixture({
  114. id: '1',
  115. culprit: 'Group 1',
  116. shortId: 'JAVASCRIPT-1',
  117. });
  118. const group2 = GroupFixture({
  119. id: '2',
  120. culprit: 'Group 2',
  121. shortId: 'JAVASCRIPT-2',
  122. });
  123. beforeEach(() => {
  124. MockApiClient.addMockResponse({
  125. url: '/organizations/org-slug/issues/',
  126. body: [group1, group2],
  127. headers: {Link: DEFAULT_LINKS_HEADER},
  128. });
  129. });
  130. it('removes issues after resolving', async function () {
  131. const updateIssueMock = MockApiClient.addMockResponse({
  132. url: '/organizations/org-slug/issues/',
  133. method: 'PUT',
  134. });
  135. render(<IssueListOverview {...defaultProps} />, {organization});
  136. const groups = await screen.findAllByTestId('group');
  137. await userEvent.click(
  138. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  139. );
  140. expect(screen.getByText('Group 1')).toBeInTheDocument();
  141. expect(screen.getByText('Group 2')).toBeInTheDocument();
  142. // After action, will refetch so need to mock that response
  143. MockApiClient.addMockResponse({
  144. url: '/organizations/org-slug/issues/',
  145. body: [group2],
  146. headers: {Link: DEFAULT_LINKS_HEADER},
  147. });
  148. await userEvent.click(await screen.findByRole('button', {name: 'Resolve'}));
  149. expect(updateIssueMock).toHaveBeenCalledWith(
  150. '/organizations/org-slug/issues/',
  151. expect.objectContaining({
  152. query: expect.objectContaining({id: ['1']}),
  153. data: {status: 'resolved', statusDetails: {}, substatus: null},
  154. })
  155. );
  156. expect(screen.queryByText('Group 1')).not.toBeInTheDocument();
  157. expect(screen.getByText('Group 2')).toBeInTheDocument();
  158. });
  159. it('can undo resolve action', async function () {
  160. const updateIssueMock = MockApiClient.addMockResponse({
  161. url: '/organizations/org-slug/issues/',
  162. method: 'PUT',
  163. });
  164. render(
  165. <Fragment>
  166. <IssueListOverview {...defaultProps} />
  167. <Indicators />
  168. </Fragment>,
  169. {organization}
  170. );
  171. const groups = await screen.findAllByTestId('group');
  172. await userEvent.click(
  173. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  174. );
  175. expect(screen.getByText('Group 1')).toBeInTheDocument();
  176. expect(screen.getByText('Group 2')).toBeInTheDocument();
  177. // After action, will refetch so need to mock that response
  178. MockApiClient.addMockResponse({
  179. url: '/organizations/org-slug/issues/',
  180. body: [group2],
  181. headers: {Link: DEFAULT_LINKS_HEADER},
  182. });
  183. await userEvent.click(await screen.findByRole('button', {name: 'Resolve'}));
  184. expect(updateIssueMock).toHaveBeenCalledWith(
  185. '/organizations/org-slug/issues/',
  186. expect.objectContaining({
  187. query: expect.objectContaining({id: ['1']}),
  188. data: {status: 'resolved', statusDetails: {}, substatus: null},
  189. })
  190. );
  191. expect(screen.queryByText('Group 1')).not.toBeInTheDocument();
  192. expect(screen.getByText('Group 2')).toBeInTheDocument();
  193. // Should show a toast message
  194. expect(screen.getByText('Resolved JAVASCRIPT-1')).toBeInTheDocument();
  195. // Clicking the undo button makes a call to set the status back to unresolved
  196. MockApiClient.addMockResponse({
  197. url: '/organizations/org-slug/issues/',
  198. body: [group1, group2],
  199. headers: {Link: DEFAULT_LINKS_HEADER},
  200. });
  201. await userEvent.click(screen.getByRole('button', {name: 'Undo'}));
  202. expect(updateIssueMock).toHaveBeenLastCalledWith(
  203. '/organizations/org-slug/issues/',
  204. expect.objectContaining({
  205. query: expect.objectContaining({id: ['1']}),
  206. data: {status: 'unresolved', statusDetails: {}},
  207. })
  208. );
  209. expect(await screen.findByText('Group 1')).toBeInTheDocument();
  210. });
  211. });
  212. describe('mark reviewed', function () {
  213. const group1 = GroupFixture({
  214. id: '1',
  215. culprit: 'Group 1',
  216. shortId: 'JAVASCRIPT-1',
  217. inbox: {},
  218. });
  219. const group2 = GroupFixture({
  220. id: '2',
  221. culprit: 'Group 2',
  222. shortId: 'JAVASCRIPT-2',
  223. inbox: {},
  224. });
  225. beforeEach(() => {
  226. MockApiClient.addMockResponse({
  227. url: '/organizations/org-slug/issues/',
  228. body: [group1, group2],
  229. headers: {Link: DEFAULT_LINKS_HEADER},
  230. });
  231. });
  232. it('removes issues after making reviewed (when on for review tab)', async function () {
  233. const updateIssueMock = MockApiClient.addMockResponse({
  234. url: '/organizations/org-slug/issues/',
  235. method: 'PUT',
  236. });
  237. render(
  238. <IssueListOverview
  239. {...defaultProps}
  240. {...RouteComponentPropsFixture({
  241. location: LocationFixture({
  242. query: {query: 'is:for_review'},
  243. }),
  244. params: {
  245. orgId: organization.slug,
  246. projectId: project.slug,
  247. searchId: undefined,
  248. },
  249. })}
  250. />,
  251. {organization}
  252. );
  253. const groups = await screen.findAllByTestId('group');
  254. await userEvent.click(
  255. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  256. );
  257. expect(screen.getByText('Group 1')).toBeInTheDocument();
  258. expect(screen.getByText('Group 2')).toBeInTheDocument();
  259. // After action, will refetch so need to mock that response
  260. MockApiClient.addMockResponse({
  261. url: '/organizations/org-slug/issues/',
  262. body: [group2],
  263. headers: {Link: DEFAULT_LINKS_HEADER},
  264. });
  265. await userEvent.click(
  266. await screen.findByRole('button', {name: 'More issue actions'})
  267. );
  268. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Mark Reviewed'}));
  269. expect(updateIssueMock).toHaveBeenCalledWith(
  270. '/organizations/org-slug/issues/',
  271. expect.objectContaining({
  272. query: expect.objectContaining({id: ['1']}),
  273. data: {inbox: false},
  274. })
  275. );
  276. expect(screen.queryByText('Group 1')).not.toBeInTheDocument();
  277. expect(screen.getByText('Group 2')).toBeInTheDocument();
  278. });
  279. });
  280. describe('priority', function () {
  281. const medPriorityGroup = GroupFixture({
  282. id: '1',
  283. priority: PriorityLevel.MEDIUM,
  284. culprit: 'Medium priority issue',
  285. });
  286. const highPriorityGroup = GroupFixture({
  287. id: '2',
  288. priority: PriorityLevel.HIGH,
  289. culprit: 'High priority issue',
  290. });
  291. beforeEach(() => {
  292. MockApiClient.addMockResponse({
  293. url: '/organizations/org-slug/issues/',
  294. body: [medPriorityGroup, highPriorityGroup],
  295. headers: {Link: DEFAULT_LINKS_HEADER},
  296. });
  297. });
  298. it('removes issues after bulk reprioritizing (when excluding priorities)', async function () {
  299. const updateIssueMock = MockApiClient.addMockResponse({
  300. url: '/organizations/org-slug/issues/',
  301. method: 'PUT',
  302. });
  303. render(<IssueListOverview {...defaultProps} />, {organization});
  304. const groups = await screen.findAllByTestId('group');
  305. await userEvent.click(
  306. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  307. );
  308. expect(screen.getByText('Medium priority issue')).toBeInTheDocument();
  309. // After action, will refetch so need to mock that response
  310. MockApiClient.addMockResponse({
  311. url: '/organizations/org-slug/issues/',
  312. body: [highPriorityGroup],
  313. headers: {Link: DEFAULT_LINKS_HEADER},
  314. });
  315. await userEvent.click(await screen.findByRole('button', {name: /set priority/i}));
  316. await userEvent.click(screen.getByRole('menuitemradio', {name: /low/i}));
  317. expect(updateIssueMock).toHaveBeenCalledWith(
  318. '/organizations/org-slug/issues/',
  319. expect.objectContaining({
  320. query: expect.objectContaining({id: ['1']}),
  321. data: {priority: PriorityLevel.LOW},
  322. })
  323. );
  324. expect(screen.queryByText('Medium priority issue')).not.toBeInTheDocument();
  325. });
  326. it('removes issues after reprioritizing single issue (when excluding priorities)', async function () {
  327. MockApiClient.addMockResponse({
  328. url: '/organizations/org-slug/prompts-activity/',
  329. body: {data: {dismissed_ts: null}},
  330. });
  331. const updateIssueMock = MockApiClient.addMockResponse({
  332. url: '/organizations/org-slug/issues/',
  333. method: 'PUT',
  334. });
  335. render(<IssueListOverview {...defaultProps} />, {organization});
  336. expect(screen.getByText('Medium priority issue')).toBeInTheDocument();
  337. // After action, will refetch so need to mock that response
  338. MockApiClient.addMockResponse({
  339. url: '/organizations/org-slug/issues/',
  340. body: [highPriorityGroup],
  341. headers: {Link: DEFAULT_LINKS_HEADER},
  342. });
  343. await userEvent.click(screen.getByText('Med'));
  344. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Low'}));
  345. await waitFor(() => {
  346. expect(updateIssueMock).toHaveBeenCalledWith(
  347. '/organizations/org-slug/issues/',
  348. expect.objectContaining({
  349. query: expect.objectContaining({id: ['1']}),
  350. data: {priority: PriorityLevel.LOW},
  351. })
  352. );
  353. });
  354. expect(screen.queryByText('Medium priority issue')).not.toBeInTheDocument();
  355. });
  356. it('does not remove issues after bulk reprioritizing (when query includes all priorities)', async function () {
  357. const updateIssueMock = MockApiClient.addMockResponse({
  358. url: '/organizations/org-slug/issues/',
  359. method: 'PUT',
  360. });
  361. render(
  362. <IssueListOverview
  363. {...defaultProps}
  364. {...RouteComponentPropsFixture({
  365. location: LocationFixture({
  366. query: {query: 'is:unresolved'},
  367. }),
  368. params: {
  369. orgId: organization.slug,
  370. projectId: project.slug,
  371. searchId: undefined,
  372. },
  373. })}
  374. />,
  375. {organization}
  376. );
  377. const groups = await screen.findAllByTestId('group');
  378. await userEvent.click(
  379. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  380. );
  381. expect(screen.getByText('Medium priority issue')).toBeInTheDocument();
  382. await userEvent.click(await screen.findByRole('button', {name: /set priority/i}));
  383. await userEvent.click(screen.getByRole('menuitemradio', {name: /low/i}));
  384. expect(updateIssueMock).toHaveBeenCalledWith(
  385. '/organizations/org-slug/issues/',
  386. expect.objectContaining({
  387. query: expect.objectContaining({id: ['1']}),
  388. data: {priority: PriorityLevel.LOW},
  389. })
  390. );
  391. expect(screen.getByText('Medium priority issue')).toBeInTheDocument();
  392. });
  393. });
  394. });