index.spec.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. import {Fragment} from 'react';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {ProjectFixture} from 'sentry-fixture/project';
  5. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  6. import GlobalModal from 'sentry/components/globalModal';
  7. import GroupStore from 'sentry/stores/groupStore';
  8. import SelectedGroupStore from 'sentry/stores/selectedGroupStore';
  9. import {IssueCategory} from 'sentry/types';
  10. import * as analytics from 'sentry/utils/analytics';
  11. import {IssueListActions} from 'sentry/views/issueList/actions';
  12. const organization = OrganizationFixture();
  13. const defaultProps = {
  14. allResultsVisible: false,
  15. query: '',
  16. queryCount: 15,
  17. projectId: 'project-slug',
  18. selection: {
  19. projects: [1],
  20. environments: [],
  21. datetime: {start: null, end: null, period: null, utc: true},
  22. },
  23. groupIds: ['1', '2', '3'],
  24. onRealtimeChange: jest.fn(),
  25. onSelectStatsPeriod: jest.fn(),
  26. realtimeActive: false,
  27. statsPeriod: '24h',
  28. onDelete: jest.fn(),
  29. displayReprocessingActions: false,
  30. onSortChange: jest.fn(),
  31. sort: '',
  32. };
  33. function WrappedComponent(props) {
  34. return (
  35. <Fragment>
  36. <GlobalModal />
  37. <IssueListActions {...defaultProps} {...props} />
  38. </Fragment>
  39. );
  40. }
  41. describe('IssueListActions', function () {
  42. afterEach(() => {
  43. jest.restoreAllMocks();
  44. });
  45. beforeEach(() => {
  46. GroupStore.reset();
  47. SelectedGroupStore.reset();
  48. SelectedGroupStore.add(['1', '2', '3']);
  49. MockApiClient.addMockResponse({
  50. url: `/organizations/${organization.slug}/projects/`,
  51. body: [ProjectFixture({id: '1'})],
  52. });
  53. });
  54. describe('Bulk', function () {
  55. describe('Total results greater than bulk limit', function () {
  56. it('after checking "Select all" checkbox, displays bulk select message', async function () {
  57. render(<WrappedComponent queryCount={1500} />);
  58. await userEvent.click(screen.getByRole('checkbox'));
  59. });
  60. it('can bulk select', async function () {
  61. render(<WrappedComponent queryCount={1500} />);
  62. await userEvent.click(screen.getByRole('checkbox'));
  63. await userEvent.click(screen.getByTestId('issue-list-select-all-notice-link'));
  64. });
  65. it('bulk resolves', async function () {
  66. const apiMock = MockApiClient.addMockResponse({
  67. url: '/organizations/org-slug/issues/',
  68. method: 'PUT',
  69. });
  70. render(<WrappedComponent queryCount={1500} />);
  71. await userEvent.click(screen.getByRole('checkbox'));
  72. await userEvent.click(screen.getByTestId('issue-list-select-all-notice-link'));
  73. await userEvent.click(await screen.findByRole('button', {name: 'Resolve'}));
  74. await screen.findByRole('dialog');
  75. await userEvent.click(screen.getByRole('button', {name: 'Bulk resolve issues'}));
  76. expect(apiMock).toHaveBeenCalledWith(
  77. expect.anything(),
  78. expect.objectContaining({
  79. query: {
  80. project: [1],
  81. },
  82. data: {status: 'resolved', statusDetails: {}, substatus: null},
  83. })
  84. );
  85. });
  86. it('bulk sets priority', async function () {
  87. const apiMock = MockApiClient.addMockResponse({
  88. url: '/organizations/org-slug/issues/',
  89. method: 'PUT',
  90. });
  91. render(<WrappedComponent queryCount={1500} />, {
  92. organization: OrganizationFixture({features: ['issue-priority-ui']}),
  93. });
  94. await userEvent.click(screen.getByRole('checkbox'));
  95. await userEvent.click(screen.getByTestId('issue-list-select-all-notice-link'));
  96. await userEvent.click(await screen.findByRole('button', {name: 'Set Priority'}));
  97. await userEvent.click(screen.getByRole('menuitemradio', {name: 'High'}));
  98. expect(
  99. within(screen.getByRole('dialog')).getByText(
  100. 'Are you sure you want to reprioritize to high the first 1,000 issues that match the search?'
  101. )
  102. ).toBeInTheDocument();
  103. await userEvent.click(
  104. screen.getByRole('button', {name: 'Bulk reprioritize issues'})
  105. );
  106. expect(apiMock).toHaveBeenCalledWith(
  107. expect.anything(),
  108. expect.objectContaining({
  109. query: {
  110. project: [1],
  111. },
  112. data: {priority: 'high'},
  113. })
  114. );
  115. });
  116. });
  117. describe('Total results less than bulk limit', function () {
  118. it('after checking "Select all" checkbox, displays bulk select message', async function () {
  119. render(<WrappedComponent queryCount={15} />);
  120. await userEvent.click(screen.getByRole('checkbox'));
  121. });
  122. it('can bulk select', async function () {
  123. render(<WrappedComponent queryCount={15} />);
  124. await userEvent.click(screen.getByRole('checkbox'));
  125. await userEvent.click(screen.getByTestId('issue-list-select-all-notice-link'));
  126. });
  127. it('bulk resolves', async function () {
  128. const apiMock = MockApiClient.addMockResponse({
  129. url: '/organizations/org-slug/issues/',
  130. method: 'PUT',
  131. });
  132. render(<WrappedComponent queryCount={15} />);
  133. await userEvent.click(screen.getByRole('checkbox'));
  134. await userEvent.click(screen.getByTestId('issue-list-select-all-notice-link'));
  135. await userEvent.click(await screen.findByRole('button', {name: 'Resolve'}));
  136. const modal = screen.getByRole('dialog');
  137. await userEvent.click(
  138. within(modal).getByRole('button', {name: 'Bulk resolve issues'})
  139. );
  140. expect(apiMock).toHaveBeenCalledWith(
  141. expect.anything(),
  142. expect.objectContaining({
  143. query: {
  144. project: [1],
  145. },
  146. data: {status: 'resolved', statusDetails: {}, substatus: null},
  147. })
  148. );
  149. });
  150. });
  151. describe('Selected on page', function () {
  152. it('resolves selected items', async function () {
  153. const apiMock = MockApiClient.addMockResponse({
  154. url: '/organizations/org-slug/issues/',
  155. method: 'PUT',
  156. });
  157. jest.spyOn(SelectedGroupStore, 'getSelectedIds').mockReturnValue(new Set(['1']));
  158. render(<WrappedComponent groupIds={['1', '2', '3', '6', '9']} />);
  159. const resolveButton = screen.getByRole('button', {name: 'Resolve'});
  160. expect(resolveButton).toBeEnabled();
  161. await userEvent.click(resolveButton);
  162. expect(apiMock).toHaveBeenCalledWith(
  163. expect.anything(),
  164. expect.objectContaining({
  165. query: {
  166. id: ['1'],
  167. project: [1],
  168. },
  169. data: {status: 'resolved', statusDetails: {}, substatus: null},
  170. })
  171. );
  172. });
  173. });
  174. });
  175. it('can set priority', async function () {
  176. const apiMock = MockApiClient.addMockResponse({
  177. url: '/organizations/org-slug/issues/',
  178. method: 'PUT',
  179. });
  180. jest.spyOn(SelectedGroupStore, 'getSelectedIds').mockReturnValue(new Set(['1']));
  181. render(<WrappedComponent {...defaultProps} />, {
  182. organization: OrganizationFixture({features: ['issue-priority-ui']}),
  183. });
  184. await userEvent.click(screen.getByRole('button', {name: 'Set Priority'}));
  185. await userEvent.click(screen.getByRole('menuitemradio', {name: 'High'}));
  186. expect(apiMock).toHaveBeenCalledWith(
  187. expect.anything(),
  188. expect.objectContaining({
  189. query: {
  190. id: ['1'],
  191. project: [1],
  192. },
  193. data: {priority: 'high'},
  194. })
  195. );
  196. });
  197. it('can archive an issue until escalating', async () => {
  198. const analyticsSpy = jest.spyOn(analytics, 'trackAnalytics');
  199. const apiMock = MockApiClient.addMockResponse({
  200. url: `/organizations/${organization.slug}/issues/`,
  201. method: 'PUT',
  202. });
  203. jest.spyOn(SelectedGroupStore, 'getSelectedIds').mockReturnValue(new Set(['1']));
  204. render(<WrappedComponent {...defaultProps} />, {organization});
  205. await userEvent.click(screen.getByRole('button', {name: 'Archive'}));
  206. expect(apiMock).toHaveBeenCalledWith(
  207. expect.anything(),
  208. expect.objectContaining({
  209. query: {
  210. id: ['1'],
  211. project: [1],
  212. },
  213. data: {
  214. status: 'ignored',
  215. statusDetails: {},
  216. substatus: 'archived_until_escalating',
  217. },
  218. })
  219. );
  220. expect(analyticsSpy).toHaveBeenCalledWith(
  221. 'issues_stream.archived',
  222. expect.objectContaining({
  223. action_substatus: 'archived_until_escalating',
  224. })
  225. );
  226. });
  227. it('can unarchive an issue when the query contains is:archived', async () => {
  228. const apiMock = MockApiClient.addMockResponse({
  229. url: `/organizations/${organization.slug}/issues/`,
  230. method: 'PUT',
  231. });
  232. jest.spyOn(SelectedGroupStore, 'getSelectedIds').mockReturnValue(new Set(['1']));
  233. render(<WrappedComponent {...defaultProps} query="is:archived" />, {
  234. organization,
  235. });
  236. await userEvent.click(screen.getByRole('button', {name: 'Unarchive'}));
  237. expect(apiMock).toHaveBeenCalledWith(
  238. expect.anything(),
  239. expect.objectContaining({
  240. query: expect.objectContaining({id: ['1'], project: [1]}),
  241. data: {status: 'unresolved', statusDetails: {}},
  242. })
  243. );
  244. });
  245. it('can resolve but not merge issues from different projects', async function () {
  246. jest
  247. .spyOn(SelectedGroupStore, 'getSelectedIds')
  248. .mockImplementation(() => new Set(['1', '2', '3']));
  249. jest.spyOn(GroupStore, 'get').mockImplementation(id => {
  250. switch (id) {
  251. case '1':
  252. return GroupFixture({project: ProjectFixture({slug: 'project-1'})});
  253. default:
  254. return GroupFixture({project: ProjectFixture({slug: 'project-2'})});
  255. }
  256. });
  257. render(<WrappedComponent />);
  258. // Can resolve but not merge issues from multiple projects
  259. expect(await screen.findByRole('button', {name: 'Resolve'})).toBeEnabled();
  260. expect(screen.getByRole('button', {name: 'Merge Selected Issues'})).toBeDisabled();
  261. });
  262. describe('mark reviewed', function () {
  263. it('acknowledges group', async function () {
  264. const mockOnActionTaken = jest.fn();
  265. MockApiClient.addMockResponse({
  266. url: '/organizations/org-slug/issues/',
  267. method: 'PUT',
  268. });
  269. jest
  270. .spyOn(SelectedGroupStore, 'getSelectedIds')
  271. .mockImplementation(() => new Set(['1', '2', '3']));
  272. jest.spyOn(GroupStore, 'get').mockImplementation(id => {
  273. return GroupFixture({
  274. id,
  275. inbox: {
  276. date_added: '2020-11-24T13:17:42.248751Z',
  277. reason: 0,
  278. reason_details: null,
  279. },
  280. });
  281. });
  282. render(<WrappedComponent onActionTaken={mockOnActionTaken} />);
  283. const reviewButton = screen.getByRole('button', {name: 'Mark Reviewed'});
  284. expect(reviewButton).toBeEnabled();
  285. await userEvent.click(reviewButton);
  286. expect(mockOnActionTaken).toHaveBeenCalledWith(['1', '2', '3'], {inbox: false});
  287. });
  288. it('mark reviewed disabled for group that is already reviewed', async function () {
  289. SelectedGroupStore.add(['1']);
  290. SelectedGroupStore.toggleSelectAll();
  291. GroupStore.loadInitialData([GroupFixture({id: '1', inbox: null})]);
  292. render(<WrappedComponent {...defaultProps} />);
  293. expect(await screen.findByRole('button', {name: 'Mark Reviewed'})).toBeDisabled();
  294. });
  295. });
  296. describe('sort', function () {
  297. it('calls onSortChange with new sort value', async function () {
  298. const mockOnSortChange = jest.fn();
  299. render(<WrappedComponent onSortChange={mockOnSortChange} />);
  300. await userEvent.click(screen.getByRole('button', {name: 'Last Seen'}));
  301. await userEvent.click(screen.getByText(/Number of events/));
  302. expect(mockOnSortChange).toHaveBeenCalledWith('freq');
  303. });
  304. });
  305. describe('performance issues', function () {
  306. it('disables options that are not supported for performance issues', async () => {
  307. jest
  308. .spyOn(SelectedGroupStore, 'getSelectedIds')
  309. .mockImplementation(() => new Set(['1', '2']));
  310. jest.spyOn(GroupStore, 'get').mockImplementation(id => {
  311. switch (id) {
  312. case '1':
  313. return GroupFixture({
  314. issueCategory: IssueCategory.ERROR,
  315. });
  316. default:
  317. return GroupFixture({
  318. issueCategory: IssueCategory.PERFORMANCE,
  319. });
  320. }
  321. });
  322. render(<WrappedComponent />);
  323. // Resolve and ignore are supported
  324. expect(screen.getByRole('button', {name: 'Resolve'})).toBeEnabled();
  325. expect(screen.getByRole('button', {name: 'Archive'})).toBeEnabled();
  326. // Merge is not supported and should be disabled
  327. expect(screen.getByRole('button', {name: 'Merge Selected Issues'})).toBeDisabled();
  328. // Open overflow menu
  329. await userEvent.click(screen.getByRole('button', {name: 'More issue actions'}));
  330. // 'Add to Bookmarks' is supported
  331. expect(
  332. screen.getByRole('menuitemradio', {name: 'Add to Bookmarks'})
  333. ).not.toHaveAttribute('aria-disabled');
  334. // Deleting is not supported and menu item should be disabled
  335. expect(screen.getByRole('menuitemradio', {name: 'Delete'})).toHaveAttribute(
  336. 'aria-disabled',
  337. 'true'
  338. );
  339. });
  340. describe('bulk action performance issues', function () {
  341. const orgWithPerformanceIssues = OrganizationFixture({
  342. features: ['performance-issues'],
  343. });
  344. it('silently filters out performance issues when bulk deleting', async function () {
  345. const bulkDeleteMock = MockApiClient.addMockResponse({
  346. url: '/organizations/org-slug/issues/',
  347. method: 'DELETE',
  348. });
  349. render(
  350. <Fragment>
  351. <GlobalModal />
  352. <IssueListActions {...defaultProps} query="is:unresolved" queryCount={100} />
  353. </Fragment>,
  354. {organization: orgWithPerformanceIssues}
  355. );
  356. await userEvent.click(screen.getByRole('checkbox'));
  357. await userEvent.click(screen.getByTestId('issue-list-select-all-notice-link'));
  358. await userEvent.click(
  359. await screen.findByRole('button', {name: 'More issue actions'})
  360. );
  361. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Delete'}));
  362. const modal = screen.getByRole('dialog');
  363. expect(
  364. within(modal).getByText(/deleting performance issues is not yet supported/i)
  365. ).toBeInTheDocument();
  366. await userEvent.click(
  367. within(modal).getByRole('button', {name: 'Bulk delete issues'})
  368. );
  369. expect(bulkDeleteMock).toHaveBeenCalledWith(
  370. expect.anything(),
  371. expect.objectContaining({
  372. query: expect.objectContaining({
  373. query: 'is:unresolved issue.category:error',
  374. }),
  375. })
  376. );
  377. });
  378. it('silently filters out performance issues when bulk merging', async function () {
  379. const bulkMergeMock = MockApiClient.addMockResponse({
  380. url: '/organizations/org-slug/issues/',
  381. method: 'PUT',
  382. });
  383. // Ensure that all issues have the same project so we can merge
  384. jest
  385. .spyOn(GroupStore, 'get')
  386. .mockReturnValue(GroupFixture({project: ProjectFixture({slug: 'project-1'})}));
  387. render(
  388. <Fragment>
  389. <GlobalModal />
  390. <IssueListActions {...defaultProps} query="is:unresolved" queryCount={100} />
  391. </Fragment>,
  392. {organization: orgWithPerformanceIssues}
  393. );
  394. await userEvent.click(screen.getByRole('checkbox'));
  395. await userEvent.click(screen.getByTestId('issue-list-select-all-notice-link'));
  396. await userEvent.click(
  397. screen.getByRole('button', {name: 'Merge Selected Issues'})
  398. );
  399. const modal = screen.getByRole('dialog');
  400. expect(
  401. within(modal).getByText(/merging performance issues is not yet supported/i)
  402. ).toBeInTheDocument();
  403. await userEvent.click(
  404. within(modal).getByRole('button', {name: 'Bulk merge issues'})
  405. );
  406. expect(bulkMergeMock).toHaveBeenCalledWith(
  407. expect.anything(),
  408. expect.objectContaining({
  409. query: expect.objectContaining({
  410. query: 'is:unresolved issue.category:error',
  411. }),
  412. })
  413. );
  414. });
  415. });
  416. });
  417. });