index.spec.jsx 16 KB

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