index.spec.jsx 14 KB

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