groupEvents.spec.tsx 14 KB

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