groupEvents.spec.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. import {browserHistory} from 'react-router';
  2. import {Location} from 'history';
  3. import {GroupFixture} from 'sentry-fixture/group';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {
  6. render,
  7. screen,
  8. userEvent,
  9. waitForElementToBeRemoved,
  10. } from 'sentry-test/reactTestingLibrary';
  11. import {Group, IssueCategory, Organization} from 'sentry/types';
  12. import GroupEvents from 'sentry/views/issueDetails/groupEvents';
  13. let location: Location;
  14. describe('groupEvents', () => {
  15. const requests: {[requestName: string]: jest.Mock} = {};
  16. const baseProps = Object.freeze({
  17. params: {orgId: 'orgId', groupId: '1'},
  18. route: {},
  19. routeParams: {},
  20. router: {} as any,
  21. routes: [],
  22. location: {},
  23. group: GroupFixture() 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(<GroupEvents {...baseProps} location={{...location, query: {}}} />, {
  113. context: routerContext,
  114. organization,
  115. });
  116. expect(await screen.findByText('id123')).toBeInTheDocument();
  117. // Transaction
  118. expect(screen.getByText('/api')).toBeInTheDocument();
  119. // Environment
  120. expect(screen.getByText('prod')).toBeInTheDocument();
  121. // Release
  122. expect(screen.getByText('1.2.3')).toBeInTheDocument();
  123. // User email
  124. expect(screen.getByText('sentry@sentry.sentry')).toBeInTheDocument();
  125. });
  126. it('handles search', async () => {
  127. render(<GroupEvents {...baseProps} location={{...location, query: {}}} />, {
  128. context: routerContext,
  129. organization,
  130. });
  131. const list = [
  132. {searchTerm: '', expectedQuery: ''},
  133. {searchTerm: 'test', expectedQuery: 'test'},
  134. {searchTerm: 'environment:production test', expectedQuery: 'test'},
  135. ];
  136. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  137. const input = screen.getByPlaceholderText('Search for events, users, tags, and more');
  138. for (const item of list) {
  139. await userEvent.clear(input);
  140. await userEvent.paste(`${item.searchTerm}`);
  141. await userEvent.keyboard('[Enter>]');
  142. expect(browserHistory.push).toHaveBeenCalledWith(
  143. expect.objectContaining({
  144. query: {query: item.expectedQuery},
  145. })
  146. );
  147. }
  148. });
  149. it('handles environment filtering', () => {
  150. render(
  151. <GroupEvents
  152. {...baseProps}
  153. location={{...location, query: {environment: ['prod', 'staging']}}}
  154. />,
  155. {context: routerContext, organization}
  156. );
  157. expect(requests.discover).toHaveBeenCalledWith(
  158. '/organizations/org-slug/events/',
  159. expect.objectContaining({
  160. query: expect.objectContaining({environment: ['prod', 'staging']}),
  161. })
  162. );
  163. });
  164. it('renders events table for performance issue', () => {
  165. const group = GroupFixture();
  166. group.issueCategory = IssueCategory.PERFORMANCE;
  167. render(
  168. <GroupEvents
  169. {...baseProps}
  170. group={group}
  171. location={{...location, query: {environment: ['prod', 'staging']}}}
  172. />,
  173. {context: routerContext, organization}
  174. );
  175. expect(requests.discover).toHaveBeenCalledWith(
  176. '/organizations/org-slug/events/',
  177. expect.objectContaining({
  178. query: expect.objectContaining({
  179. query: 'performance.issue_ids:1 event.type:transaction ',
  180. }),
  181. })
  182. );
  183. const perfEventsColumn = screen.getByText('transaction');
  184. expect(perfEventsColumn).toBeInTheDocument();
  185. });
  186. it('renders event and trace link correctly', async () => {
  187. const group = GroupFixture();
  188. group.issueCategory = IssueCategory.PERFORMANCE;
  189. render(
  190. <GroupEvents
  191. {...baseProps}
  192. group={group}
  193. location={{...location, query: {environment: ['prod', 'staging']}}}
  194. />,
  195. {context: routerContext, organization}
  196. );
  197. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  198. const eventIdATag = screen.getByText('id123').closest('a');
  199. expect(eventIdATag).toHaveAttribute(
  200. 'href',
  201. '/organizations/org-slug/issues/1/events/id123/'
  202. );
  203. });
  204. it('does not make attachments request, async when feature not enabled', async () => {
  205. render(
  206. <GroupEvents
  207. {...baseProps}
  208. location={{...location, query: {environment: ['prod', 'staging']}}}
  209. />,
  210. {context: routerContext, organization: {...organization, features: []}}
  211. );
  212. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  213. const attachmentsColumn = screen.queryByText('attachments');
  214. expect(attachmentsColumn).not.toBeInTheDocument();
  215. expect(requests.attachments).not.toHaveBeenCalled();
  216. });
  217. it('does not display attachments column with no attachments', async () => {
  218. render(
  219. <GroupEvents
  220. {...baseProps}
  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).toHaveBeenCalled();
  229. });
  230. it('does not display minidump column with no minidumps', async () => {
  231. render(
  232. <GroupEvents
  233. {...baseProps}
  234. location={{...location, query: {environment: ['prod', 'staging']}}}
  235. />,
  236. {context: routerContext, organization}
  237. );
  238. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  239. const minidumpColumn = screen.queryByText('minidump');
  240. expect(minidumpColumn).not.toBeInTheDocument();
  241. });
  242. it('displays minidumps', async () => {
  243. requests.attachments = MockApiClient.addMockResponse({
  244. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  245. body: [
  246. {
  247. id: 'id123',
  248. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  249. headers: {
  250. 'Content-Type': 'application/octet-stream',
  251. },
  252. mimetype: 'application/octet-stream',
  253. size: 1294340,
  254. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  255. dateCreated: '2022-09-28T09:04:38.659307Z',
  256. type: 'event.minidump',
  257. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  258. },
  259. ],
  260. });
  261. render(
  262. <GroupEvents
  263. {...baseProps}
  264. location={{...location, query: {environment: ['prod', 'staging']}}}
  265. />,
  266. {context: routerContext, organization}
  267. );
  268. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  269. const minidumpColumn = screen.queryByText('minidump');
  270. expect(minidumpColumn).toBeInTheDocument();
  271. });
  272. it('does not display attachments but displays minidump', async () => {
  273. requests.attachments = MockApiClient.addMockResponse({
  274. url: '/api/0/issues/1/attachments/?per_page=50&types=event.minidump&event_id=id123',
  275. body: [
  276. {
  277. id: 'id123',
  278. name: 'dc42a8b9-fc22-4de1-8a29-45b3006496d8.dmp',
  279. headers: {
  280. 'Content-Type': 'application/octet-stream',
  281. },
  282. mimetype: 'application/octet-stream',
  283. size: 1294340,
  284. sha1: '742127552a1191f71fcf6ba7bc5afa0a837350e2',
  285. dateCreated: '2022-09-28T09:04:38.659307Z',
  286. type: 'event.minidump',
  287. event_id: 'd54cb9246ee241ffbdb39bf7a9fafbb7',
  288. },
  289. ],
  290. });
  291. render(
  292. <GroupEvents
  293. {...baseProps}
  294. location={{...location, query: {environment: ['prod', 'staging']}}}
  295. />,
  296. {context: routerContext, organization}
  297. );
  298. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  299. const attachmentsColumn = screen.queryByText('attachments');
  300. const minidumpColumn = screen.queryByText('minidump');
  301. expect(attachmentsColumn).not.toBeInTheDocument();
  302. expect(minidumpColumn).toBeInTheDocument();
  303. expect(requests.attachments).toHaveBeenCalled();
  304. });
  305. it('renders events table for error', () => {
  306. render(
  307. <GroupEvents
  308. {...baseProps}
  309. location={{...location, query: {environment: ['prod', 'staging']}}}
  310. />,
  311. {context: routerContext, organization}
  312. );
  313. expect(requests.discover).toHaveBeenCalledWith(
  314. '/organizations/org-slug/events/',
  315. expect.objectContaining({
  316. query: expect.objectContaining({
  317. query: 'issue.id:1 ',
  318. field: expect.not.arrayContaining(['attachments', 'minidump']),
  319. }),
  320. })
  321. );
  322. const perfEventsColumn = screen.getByText('transaction');
  323. expect(perfEventsColumn).toBeInTheDocument();
  324. });
  325. it('removes sort if unsupported by the events table', () => {
  326. render(
  327. <GroupEvents
  328. {...baseProps}
  329. location={{...location, query: {environment: ['prod', 'staging'], sort: 'user'}}}
  330. />,
  331. {context: routerContext, organization}
  332. );
  333. expect(requests.discover).toHaveBeenCalledWith(
  334. '/organizations/org-slug/events/',
  335. expect.objectContaining({query: expect.not.objectContaining({sort: 'user'})})
  336. );
  337. });
  338. it('only request for a single projectId', () => {
  339. const group = GroupFixture();
  340. render(
  341. <GroupEvents
  342. {...baseProps}
  343. group={group}
  344. location={{
  345. ...location,
  346. query: {
  347. environment: ['prod', 'staging'],
  348. sort: 'user',
  349. project: [group.project.id, '456'],
  350. },
  351. }}
  352. />,
  353. {context: routerContext, organization}
  354. );
  355. expect(requests.discover).toHaveBeenCalledWith(
  356. '/organizations/org-slug/events/',
  357. expect.objectContaining({
  358. query: expect.objectContaining({project: [group.project.id]}),
  359. })
  360. );
  361. });
  362. it('shows discover query error message', async () => {
  363. requests.discover = MockApiClient.addMockResponse({
  364. url: '/organizations/org-slug/events/',
  365. statusCode: 500,
  366. body: {
  367. detail: 'Internal Error',
  368. errorId: '69ab396e73704cdba9342ff8dcd59795',
  369. },
  370. });
  371. render(
  372. <GroupEvents
  373. {...baseProps}
  374. location={{...location, query: {environment: ['prod', 'staging']}}}
  375. />,
  376. {context: routerContext, organization}
  377. );
  378. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  379. expect(screen.getByTestId('loading-error')).toHaveTextContent('Internal Error');
  380. });
  381. it('requests for backend columns if backend project', async () => {
  382. const group = GroupFixture();
  383. group.project.platform = 'node-express';
  384. render(
  385. <GroupEvents
  386. {...baseProps}
  387. group={group}
  388. location={{...location, query: {environment: ['prod', 'staging']}}}
  389. />,
  390. {context: routerContext, organization}
  391. );
  392. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  393. expect(requests.discover).toHaveBeenCalledWith(
  394. '/organizations/org-slug/events/',
  395. expect.objectContaining({
  396. query: expect.objectContaining({
  397. field: expect.arrayContaining(['url', 'runtime']),
  398. }),
  399. })
  400. );
  401. expect(requests.discover).toHaveBeenCalledWith(
  402. '/organizations/org-slug/events/',
  403. expect.objectContaining({
  404. query: expect.objectContaining({
  405. field: expect.not.arrayContaining(['browser']),
  406. }),
  407. })
  408. );
  409. });
  410. });