groupEvents.spec.tsx 14 KB

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