index.spec.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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-ui']};
  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 resolve but not merge issues from different projects', function () {
  229. jest
  230. .spyOn(SelectedGroupStore, 'getSelectedIds')
  231. .mockImplementation(() => new Set(['1', '2', '3']));
  232. jest.spyOn(GroupStore, 'get').mockImplementation(id => {
  233. switch (id) {
  234. case '1':
  235. return TestStubs.Group({project: TestStubs.Project({slug: 'project-1'})});
  236. default:
  237. return TestStubs.Group({project: TestStubs.Project({slug: 'project-2'})});
  238. }
  239. });
  240. render(<WrappedComponent />);
  241. // Can resolve but not merge issues from multiple projects
  242. expect(screen.getByRole('button', {name: 'Resolve'})).toBeEnabled();
  243. expect(screen.getByRole('button', {name: 'Merge Selected Issues'})).toBeDisabled();
  244. });
  245. describe('mark reviewed', function () {
  246. it('acknowledges group', async function () {
  247. const mockOnMarkReviewed = jest.fn();
  248. MockApiClient.addMockResponse({
  249. url: '/organizations/org-slug/issues/',
  250. method: 'PUT',
  251. });
  252. jest
  253. .spyOn(SelectedGroupStore, 'getSelectedIds')
  254. .mockImplementation(() => new Set(['1', '2', '3']));
  255. jest.spyOn(GroupStore, 'get').mockImplementation(id => {
  256. return TestStubs.Group({
  257. id,
  258. inbox: {
  259. date_added: '2020-11-24T13:17:42.248751Z',
  260. reason: 0,
  261. reason_details: null,
  262. },
  263. });
  264. });
  265. render(<WrappedComponent onMarkReviewed={mockOnMarkReviewed} />);
  266. const reviewButton = screen.getByRole('button', {name: 'Mark Reviewed'});
  267. expect(reviewButton).toBeEnabled();
  268. await userEvent.click(reviewButton);
  269. expect(mockOnMarkReviewed).toHaveBeenCalledWith(['1', '2', '3']);
  270. });
  271. it('mark reviewed disabled for group that is already reviewed', function () {
  272. SelectedGroupStore.add(['1']);
  273. SelectedGroupStore.toggleSelectAll();
  274. GroupStore.loadInitialData([TestStubs.Group({id: '1', inbox: null})]);
  275. render(<WrappedComponent {...defaultProps} />);
  276. expect(screen.getByRole('button', {name: 'Mark Reviewed'})).toBeDisabled();
  277. });
  278. it('hides mark reviewed button with escalating-issues-ui flag', function () {
  279. render(<WrappedComponent {...defaultProps} />, {
  280. organization: {...organization, features: ['escalating-issues-ui']},
  281. });
  282. expect(
  283. screen.queryByRole('button', {name: 'Mark Reviewed'})
  284. ).not.toBeInTheDocument();
  285. });
  286. });
  287. describe('sort', function () {
  288. it('calls onSortChange with new sort value', async function () {
  289. const mockOnSortChange = jest.fn();
  290. render(<WrappedComponent onSortChange={mockOnSortChange} />);
  291. await userEvent.click(screen.getByRole('button', {name: 'Last Seen'}));
  292. await userEvent.click(screen.getByText(/Number of events/));
  293. expect(mockOnSortChange).toHaveBeenCalledWith('freq');
  294. });
  295. });
  296. describe('performance issues', function () {
  297. it('disables options that are not supported for performance issues', async () => {
  298. jest
  299. .spyOn(SelectedGroupStore, 'getSelectedIds')
  300. .mockImplementation(() => new Set(['1', '2']));
  301. jest.spyOn(GroupStore, 'get').mockImplementation(id => {
  302. switch (id) {
  303. case '1':
  304. return TestStubs.Group({
  305. issueCategory: IssueCategory.ERROR,
  306. });
  307. default:
  308. return TestStubs.Group({
  309. issueCategory: IssueCategory.PERFORMANCE,
  310. });
  311. }
  312. });
  313. render(<WrappedComponent />);
  314. // Resolve and ignore are supported
  315. expect(screen.getByRole('button', {name: 'Resolve'})).toBeEnabled();
  316. expect(screen.getByRole('button', {name: 'Ignore'})).toBeEnabled();
  317. // Merge is not supported and should be disabled
  318. expect(screen.getByRole('button', {name: 'Merge Selected Issues'})).toBeDisabled();
  319. // Open overflow menu
  320. await userEvent.click(screen.getByRole('button', {name: 'More issue actions'}));
  321. // 'Add to Bookmarks' is supported
  322. expect(
  323. screen.getByRole('menuitemradio', {name: 'Add to Bookmarks'})
  324. ).not.toHaveAttribute('aria-disabled');
  325. // Deleting is not supported and menu item should be disabled
  326. expect(screen.getByRole('menuitemradio', {name: 'Delete'})).toHaveAttribute(
  327. 'aria-disabled',
  328. 'true'
  329. );
  330. });
  331. describe('bulk action performance issues', function () {
  332. const orgWithPerformanceIssues = TestStubs.Organization({
  333. features: ['performance-issues'],
  334. });
  335. it('silently filters out performance issues when bulk deleting', async function () {
  336. const bulkDeleteMock = MockApiClient.addMockResponse({
  337. url: '/organizations/org-slug/issues/',
  338. method: 'DELETE',
  339. });
  340. render(
  341. <Fragment>
  342. <GlobalModal />
  343. <IssueListActions {...defaultProps} query="is:unresolved" queryCount={100} />
  344. </Fragment>,
  345. {organization: orgWithPerformanceIssues}
  346. );
  347. await userEvent.click(screen.getByRole('checkbox'));
  348. await userEvent.click(screen.getByTestId('issue-list-select-all-notice-link'));
  349. await userEvent.click(screen.getByRole('button', {name: 'More issue actions'}));
  350. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Delete'}));
  351. const modal = screen.getByRole('dialog');
  352. expect(
  353. within(modal).getByText(/deleting performance issues is not yet supported/i)
  354. ).toBeInTheDocument();
  355. await userEvent.click(
  356. within(modal).getByRole('button', {name: 'Bulk delete issues'})
  357. );
  358. expect(bulkDeleteMock).toHaveBeenCalledWith(
  359. expect.anything(),
  360. expect.objectContaining({
  361. query: expect.objectContaining({
  362. query: 'is:unresolved issue.category:error',
  363. }),
  364. })
  365. );
  366. });
  367. it('silently filters out performance issues when bulk merging', async function () {
  368. const bulkMergeMock = MockApiClient.addMockResponse({
  369. url: '/organizations/org-slug/issues/',
  370. method: 'PUT',
  371. });
  372. // Ensure that all issues have the same project so we can merge
  373. jest
  374. .spyOn(GroupStore, 'get')
  375. .mockReturnValue(
  376. TestStubs.Group({project: TestStubs.Project({slug: 'project-1'})})
  377. );
  378. render(
  379. <Fragment>
  380. <GlobalModal />
  381. <IssueListActions {...defaultProps} query="is:unresolved" queryCount={100} />
  382. </Fragment>,
  383. {organization: orgWithPerformanceIssues}
  384. );
  385. await userEvent.click(screen.getByRole('checkbox'));
  386. await userEvent.click(screen.getByTestId('issue-list-select-all-notice-link'));
  387. await userEvent.click(
  388. screen.getByRole('button', {name: 'Merge Selected Issues'})
  389. );
  390. const modal = screen.getByRole('dialog');
  391. expect(
  392. within(modal).getByText(/merging performance issues is not yet supported/i)
  393. ).toBeInTheDocument();
  394. // Wait for ProjectStore to update before closing the modal
  395. await act(tick);
  396. await userEvent.click(
  397. within(modal).getByRole('button', {name: 'Bulk merge issues'})
  398. );
  399. expect(bulkMergeMock).toHaveBeenCalledWith(
  400. expect.anything(),
  401. expect.objectContaining({
  402. query: expect.objectContaining({
  403. query: 'is:unresolved issue.category:error',
  404. }),
  405. })
  406. );
  407. });
  408. });
  409. });
  410. });