groupEvents.spec.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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: ReturnType<typeof initializeOrg>['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('pushes new query parameter when searching', async () => {
  136. render(<GroupEvents {...baseProps} location={{...location, query: {}}} />, {
  137. router,
  138. });
  139. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  140. const input = screen.getByPlaceholderText('Search events...');
  141. await userEvent.click(input);
  142. await userEvent.keyboard('foo');
  143. await userEvent.keyboard('{enter}');
  144. await waitFor(() => {
  145. expect(browserHistory.push).toHaveBeenCalledWith(
  146. expect.objectContaining({
  147. query: {query: 'foo'},
  148. })
  149. );
  150. });
  151. });
  152. it('displays event filters and tags', async () => {
  153. MockApiClient.addMockResponse({
  154. url: '/organizations/org-slug/issues/1/tags/',
  155. body: [{key: 'custom_tag', name: 'custom_tag', totalValues: 1}],
  156. });
  157. render(<GroupEvents {...baseProps} location={{...location, query: {}}} />, {
  158. router,
  159. });
  160. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  161. const input = screen.getByPlaceholderText('Search events...');
  162. await userEvent.click(input);
  163. expect(
  164. await screen.findByRole('button', {name: 'Event Filters'})
  165. ).toBeInTheDocument();
  166. expect(screen.getByRole('button', {name: 'Event Tags'})).toBeInTheDocument();
  167. // Should show custom_tag fetched from group tags
  168. expect(screen.getByRole('option', {name: 'custom_tag'})).toBeInTheDocument();
  169. // Should hardcoded event filters
  170. expect(screen.getByRole('option', {name: 'event.type'})).toBeInTheDocument();
  171. });
  172. it('handles environment filtering', async () => {
  173. render(
  174. <GroupEvents
  175. {...baseProps}
  176. location={{...location, query: {environment: ['prod', 'staging']}}}
  177. />,
  178. {router, organization}
  179. );
  180. await waitFor(() => {
  181. expect(screen.getByText('Transaction')).toBeInTheDocument();
  182. });
  183. expect(requests.discover).toHaveBeenCalledWith(
  184. '/organizations/org-slug/events/',
  185. expect.objectContaining({
  186. query: expect.objectContaining({environment: ['prod', 'staging']}),
  187. })
  188. );
  189. });
  190. it('renders events table for performance issue', async () => {
  191. const group = GroupFixture();
  192. group.issueCategory = IssueCategory.PERFORMANCE;
  193. render(
  194. <GroupEvents
  195. {...baseProps}
  196. group={group}
  197. location={{...location, query: {environment: ['prod', 'staging']}}}
  198. />,
  199. {router, organization}
  200. );
  201. expect(requests.discover).toHaveBeenCalledWith(
  202. '/organizations/org-slug/events/',
  203. expect.objectContaining({
  204. query: expect.objectContaining({
  205. query: 'performance.issue_ids:1 event.type:transaction ',
  206. }),
  207. })
  208. );
  209. await waitFor(() => {
  210. expect(screen.getByText('Transaction')).toBeInTheDocument();
  211. });
  212. });
  213. it('renders event and trace link correctly', async () => {
  214. const group = GroupFixture();
  215. group.issueCategory = IssueCategory.PERFORMANCE;
  216. render(
  217. <GroupEvents
  218. {...baseProps}
  219. group={group}
  220. location={{...location, query: {environment: ['prod', 'staging']}}}
  221. />,
  222. {router, organization}
  223. );
  224. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  225. const eventIdATag = screen.getByText('id123').closest('a');
  226. expect(eventIdATag).toHaveAttribute(
  227. 'href',
  228. '/organizations/org-slug/issues/1/events/id123/'
  229. );
  230. });
  231. it('does not make attachments request, async when feature not enabled', async () => {
  232. render(
  233. <GroupEvents
  234. {...baseProps}
  235. location={{...location, query: {environment: ['prod', 'staging']}}}
  236. />,
  237. {router, organization: {...organization, features: []}}
  238. );
  239. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  240. const attachmentsColumn = screen.queryByText('Attachments');
  241. expect(attachmentsColumn).not.toBeInTheDocument();
  242. expect(requests.attachments).not.toHaveBeenCalled();
  243. });
  244. it('does not display attachments column with no attachments', async () => {
  245. render(
  246. <GroupEvents
  247. {...baseProps}
  248. location={{...location, query: {environment: ['prod', 'staging']}}}
  249. />,
  250. {router, organization}
  251. );
  252. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  253. const attachmentsColumn = screen.queryByText('Attachments');
  254. expect(attachmentsColumn).not.toBeInTheDocument();
  255. expect(requests.attachments).toHaveBeenCalled();
  256. });
  257. it('does not display minidump column with no minidumps', async () => {
  258. render(
  259. <GroupEvents
  260. {...baseProps}
  261. location={{...location, query: {environment: ['prod', 'staging']}}}
  262. />,
  263. {router, organization}
  264. );
  265. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  266. const minidumpColumn = screen.queryByText('Minidump');
  267. expect(minidumpColumn).not.toBeInTheDocument();
  268. });
  269. it('displays minidumps', async () => {
  270. requests.attachments = MockApiClient.addMockResponse({
  271. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  272. body: [
  273. {
  274. id: 'id123',
  275. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  276. headers: {
  277. 'Content-Type': 'application/octet-stream',
  278. },
  279. mimetype: 'application/octet-stream',
  280. size: 1294340,
  281. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  282. dateCreated: '2022-09-28T09:04:38.659307Z',
  283. type: 'event.minidump',
  284. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  285. },
  286. ],
  287. });
  288. render(
  289. <GroupEvents
  290. {...baseProps}
  291. location={{...location, query: {environment: ['prod', 'staging']}}}
  292. />,
  293. {router, organization}
  294. );
  295. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  296. const minidumpColumn = screen.queryByText('Minidump');
  297. expect(minidumpColumn).toBeInTheDocument();
  298. });
  299. it('does not display attachments but displays minidump', async () => {
  300. requests.attachments = MockApiClient.addMockResponse({
  301. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  302. body: [
  303. {
  304. id: 'id123',
  305. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  306. headers: {
  307. 'Content-Type': 'application/octet-stream',
  308. },
  309. mimetype: 'application/octet-stream',
  310. size: 1294340,
  311. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  312. dateCreated: '2022-09-28T09:04:38.659307Z',
  313. type: 'event.minidump',
  314. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  315. },
  316. ],
  317. });
  318. render(
  319. <GroupEvents
  320. {...baseProps}
  321. location={{...location, query: {environment: ['prod', 'staging']}}}
  322. />,
  323. {router, organization}
  324. );
  325. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  326. const attachmentsColumn = screen.queryByText('Attachments');
  327. const minidumpColumn = screen.queryByText('Minidump');
  328. expect(attachmentsColumn).not.toBeInTheDocument();
  329. expect(minidumpColumn).toBeInTheDocument();
  330. expect(requests.attachments).toHaveBeenCalled();
  331. });
  332. it('renders events table for error', async () => {
  333. render(
  334. <GroupEvents
  335. {...baseProps}
  336. location={{...location, query: {environment: ['prod', 'staging']}}}
  337. />,
  338. {router, organization}
  339. );
  340. expect(requests.discover).toHaveBeenCalledWith(
  341. '/organizations/org-slug/events/',
  342. expect.objectContaining({
  343. query: expect.objectContaining({
  344. query: 'issue.id:1 ',
  345. field: expect.not.arrayContaining(['attachments', 'minidump']),
  346. }),
  347. })
  348. );
  349. await waitFor(() => {
  350. expect(screen.getByText('Transaction')).toBeInTheDocument();
  351. });
  352. });
  353. it('removes sort if unsupported by the events table', async () => {
  354. render(
  355. <GroupEvents
  356. {...baseProps}
  357. location={{...location, query: {environment: ['prod', 'staging'], sort: 'user'}}}
  358. />,
  359. {router, organization}
  360. );
  361. expect(requests.discover).toHaveBeenCalledWith(
  362. '/organizations/org-slug/events/',
  363. expect.objectContaining({query: expect.not.objectContaining({sort: 'user'})})
  364. );
  365. await waitFor(() => {
  366. expect(screen.getByText('Transaction')).toBeInTheDocument();
  367. });
  368. });
  369. it('only request for a single projectId', async () => {
  370. const group = GroupFixture();
  371. render(
  372. <GroupEvents
  373. {...baseProps}
  374. group={group}
  375. location={{
  376. ...location,
  377. query: {
  378. environment: ['prod', 'staging'],
  379. sort: 'user',
  380. project: [group.project.id, '456'],
  381. },
  382. }}
  383. />,
  384. {router, organization}
  385. );
  386. expect(requests.discover).toHaveBeenCalledWith(
  387. '/organizations/org-slug/events/',
  388. expect.objectContaining({
  389. query: expect.objectContaining({project: [group.project.id]}),
  390. })
  391. );
  392. await waitFor(() => {
  393. expect(screen.getByText('Transaction')).toBeInTheDocument();
  394. });
  395. });
  396. it('shows discover query error message', async () => {
  397. requests.discover = MockApiClient.addMockResponse({
  398. url: '/organizations/org-slug/events/',
  399. statusCode: 500,
  400. body: {
  401. detail: 'Internal Error',
  402. errorId: '69ab396e73704cdba9342ff8dcd59795',
  403. },
  404. });
  405. render(
  406. <GroupEvents
  407. {...baseProps}
  408. location={{...location, query: {environment: ['prod', 'staging']}}}
  409. />,
  410. {router, organization}
  411. );
  412. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  413. expect(screen.getByTestId('loading-error')).toHaveTextContent('Internal Error');
  414. });
  415. it('requests for backend columns if backend project', async () => {
  416. const group = GroupFixture();
  417. group.project.platform = 'node-express';
  418. render(
  419. <GroupEvents
  420. {...baseProps}
  421. group={group}
  422. location={{...location, query: {environment: ['prod', 'staging']}}}
  423. />,
  424. {router, organization}
  425. );
  426. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  427. expect(requests.discover).toHaveBeenCalledWith(
  428. '/organizations/org-slug/events/',
  429. expect.objectContaining({
  430. query: expect.objectContaining({
  431. field: expect.arrayContaining(['url', 'runtime']),
  432. }),
  433. })
  434. );
  435. expect(requests.discover).toHaveBeenCalledWith(
  436. '/organizations/org-slug/events/',
  437. expect.objectContaining({
  438. query: expect.objectContaining({
  439. field: expect.not.arrayContaining(['browser']),
  440. }),
  441. })
  442. );
  443. });
  444. });