groupEvents.spec.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. import type {Location} from 'history';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {
  5. render,
  6. screen,
  7. userEvent,
  8. waitFor,
  9. waitForElementToBeRemoved,
  10. } from 'sentry-test/reactTestingLibrary';
  11. import type {Group} from 'sentry/types/group';
  12. import {IssueCategory} from 'sentry/types/group';
  13. import type {Organization} from 'sentry/types/organization';
  14. import {browserHistory} from 'sentry/utils/browserHistory';
  15. import GroupEvents from 'sentry/views/issueDetails/groupEvents';
  16. let location: Location;
  17. describe('groupEvents', () => {
  18. const requests: {[requestName: string]: jest.Mock} = {};
  19. const baseProps = Object.freeze({
  20. params: {orgId: 'orgId', groupId: '1'},
  21. route: {},
  22. routeParams: {},
  23. router: {} as any,
  24. routes: [],
  25. location: {},
  26. environments: [],
  27. group: GroupFixture() as Group,
  28. });
  29. let organization: Organization;
  30. let router;
  31. beforeEach(() => {
  32. browserHistory.push = jest.fn();
  33. ({organization, router} = initializeOrg({
  34. organization: {
  35. features: ['event-attachments'],
  36. },
  37. } as any));
  38. location = {
  39. pathname: '/organizations/org-slug/issues/123/events/',
  40. search: '',
  41. hash: '',
  42. action: 'REPLACE',
  43. key: 'okjkey',
  44. state: '',
  45. query: {
  46. query: '',
  47. },
  48. };
  49. requests.discover = MockApiClient.addMockResponse({
  50. url: '/organizations/org-slug/events/',
  51. headers: {
  52. Link: `<https://sentry.io/api/0/issues/1/events/?limit=50&cursor=0:0:1>; rel="previous"; results="true"; cursor="0:0:1", <https://sentry.io/api/0/issues/1/events/?limit=50&cursor=0:200:0>; rel="next"; results="true"; cursor="0:200:0"`,
  53. },
  54. body: {
  55. data: [
  56. {
  57. timestamp: '2022-09-11T15:01:10+00:00',
  58. transaction: '/api',
  59. release: 'backend@1.2.3',
  60. 'transaction.duration': 1803,
  61. environment: 'prod',
  62. 'user.display': 'sentry@sentry.sentry',
  63. id: 'id123',
  64. trace: 'trace123',
  65. 'project.name': 'project123',
  66. },
  67. ],
  68. meta: {
  69. fields: {
  70. timestamp: 'date',
  71. transaction: 'string',
  72. release: 'string',
  73. 'transaction.duration': 'duration',
  74. environment: 'string',
  75. 'user.display': 'string',
  76. id: 'string',
  77. trace: 'string',
  78. 'project.name': 'string',
  79. },
  80. units: {
  81. timestamp: null,
  82. transaction: null,
  83. release: null,
  84. 'transaction.duration': 'millisecond',
  85. environment: null,
  86. 'user.display': null,
  87. id: null,
  88. trace: null,
  89. 'project.name': null,
  90. },
  91. isMetricsData: false,
  92. tips: {query: null, columns: null},
  93. },
  94. },
  95. });
  96. requests.attachments = MockApiClient.addMockResponse({
  97. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  98. body: [],
  99. });
  100. requests.recentSearches = MockApiClient.addMockResponse({
  101. method: 'POST',
  102. url: '/organizations/org-slug/recent-searches/',
  103. body: [],
  104. });
  105. requests.latestEvent = MockApiClient.addMockResponse({
  106. method: 'GET',
  107. url: '/issues/1/events/latest/',
  108. body: {},
  109. });
  110. requests.tags = MockApiClient.addMockResponse({
  111. method: 'GET',
  112. url: '/organizations/org-slug/issues/1/tags/',
  113. body: [],
  114. });
  115. });
  116. afterEach(() => {
  117. MockApiClient.clearMockResponses();
  118. jest.clearAllMocks();
  119. });
  120. it('fetches and renders a table of events', async () => {
  121. render(<GroupEvents {...baseProps} location={{...location, query: {}}} />, {
  122. router,
  123. organization,
  124. });
  125. expect(await screen.findByText('id123')).toBeInTheDocument();
  126. // Transaction
  127. expect(screen.getByText('/api')).toBeInTheDocument();
  128. // Environment
  129. expect(screen.getByText('prod')).toBeInTheDocument();
  130. // Release
  131. expect(screen.getByText('1.2.3')).toBeInTheDocument();
  132. // User email
  133. expect(screen.getByText('sentry@sentry.sentry')).toBeInTheDocument();
  134. });
  135. it('handles search', async () => {
  136. render(<GroupEvents {...baseProps} location={{...location, query: {}}} />, {
  137. router,
  138. organization,
  139. });
  140. const list = [
  141. {searchTerm: '', expectedQuery: ''},
  142. {searchTerm: 'test', expectedQuery: 'test'},
  143. {searchTerm: 'environment:production test', expectedQuery: 'test'},
  144. ];
  145. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  146. const input = screen.getByPlaceholderText('Search for events, users, tags, and more');
  147. for (const item of list) {
  148. await userEvent.clear(input);
  149. await userEvent.paste(`${item.searchTerm}`);
  150. await userEvent.keyboard('[Enter>]');
  151. expect(browserHistory.push).toHaveBeenCalledWith(
  152. expect.objectContaining({
  153. query: {query: item.expectedQuery},
  154. })
  155. );
  156. }
  157. });
  158. it('pushes new query parameter when searching (issue-stream-search-query-builder)', async () => {
  159. render(<GroupEvents {...baseProps} location={{...location, query: {}}} />, {
  160. router,
  161. organization: {...organization, features: ['issue-stream-search-query-builder']},
  162. });
  163. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  164. const input = screen.getByPlaceholderText('Search events...');
  165. await userEvent.click(input);
  166. await userEvent.keyboard('foo');
  167. await userEvent.keyboard('{enter}');
  168. await waitFor(() => {
  169. expect(browserHistory.push).toHaveBeenCalledWith(
  170. expect.objectContaining({
  171. query: {query: 'foo'},
  172. })
  173. );
  174. });
  175. });
  176. it('displays event filters and tags (issue-stream-search-query-builder)', async () => {
  177. MockApiClient.addMockResponse({
  178. url: '/organizations/org-slug/issues/1/tags/',
  179. body: [{key: 'custom_tag', name: 'custom_tag', totalValues: 1}],
  180. });
  181. render(<GroupEvents {...baseProps} location={{...location, query: {}}} />, {
  182. router,
  183. organization: {...organization, features: ['issue-stream-search-query-builder']},
  184. });
  185. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  186. const input = screen.getByPlaceholderText('Search events...');
  187. await userEvent.click(input);
  188. expect(
  189. await screen.findByRole('button', {name: 'Event Filters'})
  190. ).toBeInTheDocument();
  191. expect(screen.getByRole('button', {name: 'Event Tags'})).toBeInTheDocument();
  192. // Should show custom_tag fetched from group tags
  193. expect(screen.getByRole('option', {name: 'custom_tag'})).toBeInTheDocument();
  194. // Should hardcoded event filters
  195. expect(screen.getByRole('option', {name: 'event.type'})).toBeInTheDocument();
  196. });
  197. it('handles environment filtering', async () => {
  198. render(
  199. <GroupEvents
  200. {...baseProps}
  201. location={{...location, query: {environment: ['prod', 'staging']}}}
  202. />,
  203. {router, organization}
  204. );
  205. await waitFor(() => {
  206. expect(screen.getByText('transaction')).toBeInTheDocument();
  207. });
  208. expect(requests.discover).toHaveBeenCalledWith(
  209. '/organizations/org-slug/events/',
  210. expect.objectContaining({
  211. query: expect.objectContaining({environment: ['prod', 'staging']}),
  212. })
  213. );
  214. });
  215. it('renders events table for performance issue', async () => {
  216. const group = GroupFixture();
  217. group.issueCategory = IssueCategory.PERFORMANCE;
  218. render(
  219. <GroupEvents
  220. {...baseProps}
  221. group={group}
  222. location={{...location, query: {environment: ['prod', 'staging']}}}
  223. />,
  224. {router, organization}
  225. );
  226. expect(requests.discover).toHaveBeenCalledWith(
  227. '/organizations/org-slug/events/',
  228. expect.objectContaining({
  229. query: expect.objectContaining({
  230. query: 'performance.issue_ids:1 event.type:transaction ',
  231. }),
  232. })
  233. );
  234. await waitFor(() => {
  235. expect(screen.getByText('transaction')).toBeInTheDocument();
  236. });
  237. });
  238. it('renders event and trace link correctly', async () => {
  239. const group = GroupFixture();
  240. group.issueCategory = IssueCategory.PERFORMANCE;
  241. render(
  242. <GroupEvents
  243. {...baseProps}
  244. group={group}
  245. location={{...location, query: {environment: ['prod', 'staging']}}}
  246. />,
  247. {router, organization}
  248. );
  249. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  250. const eventIdATag = screen.getByText('id123').closest('a');
  251. expect(eventIdATag).toHaveAttribute(
  252. 'href',
  253. '/organizations/org-slug/issues/1/events/id123/'
  254. );
  255. });
  256. it('does not make attachments request, async when feature not enabled', async () => {
  257. render(
  258. <GroupEvents
  259. {...baseProps}
  260. location={{...location, query: {environment: ['prod', 'staging']}}}
  261. />,
  262. {router, organization: {...organization, features: []}}
  263. );
  264. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  265. const attachmentsColumn = screen.queryByText('attachments');
  266. expect(attachmentsColumn).not.toBeInTheDocument();
  267. expect(requests.attachments).not.toHaveBeenCalled();
  268. });
  269. it('does not display attachments column with no attachments', async () => {
  270. render(
  271. <GroupEvents
  272. {...baseProps}
  273. location={{...location, query: {environment: ['prod', 'staging']}}}
  274. />,
  275. {router, organization}
  276. );
  277. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  278. const attachmentsColumn = screen.queryByText('attachments');
  279. expect(attachmentsColumn).not.toBeInTheDocument();
  280. expect(requests.attachments).toHaveBeenCalled();
  281. });
  282. it('does not display minidump column with no minidumps', async () => {
  283. render(
  284. <GroupEvents
  285. {...baseProps}
  286. location={{...location, query: {environment: ['prod', 'staging']}}}
  287. />,
  288. {router, organization}
  289. );
  290. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  291. const minidumpColumn = screen.queryByText('minidump');
  292. expect(minidumpColumn).not.toBeInTheDocument();
  293. });
  294. it('displays minidumps', async () => {
  295. requests.attachments = MockApiClient.addMockResponse({
  296. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  297. body: [
  298. {
  299. id: 'id123',
  300. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  301. headers: {
  302. 'Content-Type': 'application/octet-stream',
  303. },
  304. mimetype: 'application/octet-stream',
  305. size: 1294340,
  306. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  307. dateCreated: '2022-09-28T09:04:38.659307Z',
  308. type: 'event.minidump',
  309. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  310. },
  311. ],
  312. });
  313. render(
  314. <GroupEvents
  315. {...baseProps}
  316. location={{...location, query: {environment: ['prod', 'staging']}}}
  317. />,
  318. {router, organization}
  319. );
  320. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  321. const minidumpColumn = screen.queryByText('minidump');
  322. expect(minidumpColumn).toBeInTheDocument();
  323. });
  324. it('does not display attachments but displays minidump', async () => {
  325. requests.attachments = MockApiClient.addMockResponse({
  326. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  327. body: [
  328. {
  329. id: 'id123',
  330. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  331. headers: {
  332. 'Content-Type': 'application/octet-stream',
  333. },
  334. mimetype: 'application/octet-stream',
  335. size: 1294340,
  336. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  337. dateCreated: '2022-09-28T09:04:38.659307Z',
  338. type: 'event.minidump',
  339. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  340. },
  341. ],
  342. });
  343. render(
  344. <GroupEvents
  345. {...baseProps}
  346. location={{...location, query: {environment: ['prod', 'staging']}}}
  347. />,
  348. {router, organization}
  349. );
  350. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  351. const attachmentsColumn = screen.queryByText('attachments');
  352. const minidumpColumn = screen.queryByText('minidump');
  353. expect(attachmentsColumn).not.toBeInTheDocument();
  354. expect(minidumpColumn).toBeInTheDocument();
  355. expect(requests.attachments).toHaveBeenCalled();
  356. });
  357. it('renders events table for error', async () => {
  358. render(
  359. <GroupEvents
  360. {...baseProps}
  361. location={{...location, query: {environment: ['prod', 'staging']}}}
  362. />,
  363. {router, organization}
  364. );
  365. expect(requests.discover).toHaveBeenCalledWith(
  366. '/organizations/org-slug/events/',
  367. expect.objectContaining({
  368. query: expect.objectContaining({
  369. query: 'issue.id:1 ',
  370. field: expect.not.arrayContaining(['attachments', 'minidump']),
  371. }),
  372. })
  373. );
  374. await waitFor(() => {
  375. expect(screen.getByText('transaction')).toBeInTheDocument();
  376. });
  377. });
  378. it('removes sort if unsupported by the events table', async () => {
  379. render(
  380. <GroupEvents
  381. {...baseProps}
  382. location={{...location, query: {environment: ['prod', 'staging'], sort: 'user'}}}
  383. />,
  384. {router, organization}
  385. );
  386. expect(requests.discover).toHaveBeenCalledWith(
  387. '/organizations/org-slug/events/',
  388. expect.objectContaining({query: expect.not.objectContaining({sort: 'user'})})
  389. );
  390. await waitFor(() => {
  391. expect(screen.getByText('transaction')).toBeInTheDocument();
  392. });
  393. });
  394. it('only request for a single projectId', async () => {
  395. const group = GroupFixture();
  396. render(
  397. <GroupEvents
  398. {...baseProps}
  399. group={group}
  400. location={{
  401. ...location,
  402. query: {
  403. environment: ['prod', 'staging'],
  404. sort: 'user',
  405. project: [group.project.id, '456'],
  406. },
  407. }}
  408. />,
  409. {router, organization}
  410. );
  411. expect(requests.discover).toHaveBeenCalledWith(
  412. '/organizations/org-slug/events/',
  413. expect.objectContaining({
  414. query: expect.objectContaining({project: [group.project.id]}),
  415. })
  416. );
  417. await waitFor(() => {
  418. expect(screen.getByText('transaction')).toBeInTheDocument();
  419. });
  420. });
  421. it('shows discover query error message', async () => {
  422. requests.discover = MockApiClient.addMockResponse({
  423. url: '/organizations/org-slug/events/',
  424. statusCode: 500,
  425. body: {
  426. detail: 'Internal Error',
  427. errorId: '69ab396e73704cdba9342ff8dcd59795',
  428. },
  429. });
  430. render(
  431. <GroupEvents
  432. {...baseProps}
  433. location={{...location, query: {environment: ['prod', 'staging']}}}
  434. />,
  435. {router, organization}
  436. );
  437. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  438. expect(screen.getByTestId('loading-error')).toHaveTextContent('Internal Error');
  439. });
  440. it('requests for backend columns if backend project', async () => {
  441. const group = GroupFixture();
  442. group.project.platform = 'node-express';
  443. render(
  444. <GroupEvents
  445. {...baseProps}
  446. group={group}
  447. location={{...location, query: {environment: ['prod', 'staging']}}}
  448. />,
  449. {router, organization}
  450. );
  451. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  452. expect(requests.discover).toHaveBeenCalledWith(
  453. '/organizations/org-slug/events/',
  454. expect.objectContaining({
  455. query: expect.objectContaining({
  456. field: expect.arrayContaining(['url', 'runtime']),
  457. }),
  458. })
  459. );
  460. expect(requests.discover).toHaveBeenCalledWith(
  461. '/organizations/org-slug/events/',
  462. expect.objectContaining({
  463. query: expect.objectContaining({
  464. field: expect.not.arrayContaining(['browser']),
  465. }),
  466. })
  467. );
  468. });
  469. });