groupEventDetails.spec.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. import type {InjectedRouter} from 'react-router';
  2. import type {Location} from 'history';
  3. import {CommitFixture} from 'sentry-fixture/commit';
  4. import {CommitAuthorFixture} from 'sentry-fixture/commitAuthor';
  5. import {EventFixture} from 'sentry-fixture/event';
  6. import {GroupFixture} from 'sentry-fixture/group';
  7. import {LocationFixture} from 'sentry-fixture/locationFixture';
  8. import {ProjectFixture} from 'sentry-fixture/project';
  9. import {RouterFixture} from 'sentry-fixture/routerFixture';
  10. import {SentryAppFixture} from 'sentry-fixture/sentryApp';
  11. import {SentryAppComponentFixture} from 'sentry-fixture/sentryAppComponent';
  12. import {SentryAppInstallationFixture} from 'sentry-fixture/sentryAppInstallation';
  13. import {initializeOrg} from 'sentry-test/initializeOrg';
  14. import {render, screen, waitFor, within} from 'sentry-test/reactTestingLibrary';
  15. import type {Event, Group} from 'sentry/types';
  16. import {EntryType, IssueCategory, IssueType} from 'sentry/types';
  17. import type {Organization} from 'sentry/types/organization';
  18. import type {Project} from 'sentry/types/project';
  19. import {browserHistory} from 'sentry/utils/browserHistory';
  20. import type {QuickTraceEvent} from 'sentry/utils/performance/quickTrace/types';
  21. import type {GroupEventDetailsProps} from 'sentry/views/issueDetails/groupEventDetails/groupEventDetails';
  22. import GroupEventDetails from 'sentry/views/issueDetails/groupEventDetails/groupEventDetails';
  23. import {ReprocessingStatus} from 'sentry/views/issueDetails/utils';
  24. import {RouteContext} from 'sentry/views/routeContext';
  25. const TRACE_ID = '797cda4e24844bdc90e0efe741616047';
  26. const makeDefaultMockData = (
  27. organization?: Organization,
  28. project?: Project,
  29. query?: Record<string, string | string[]>
  30. ): {
  31. event: Event;
  32. group: Group;
  33. organization: Organization;
  34. project: Project;
  35. router: InjectedRouter;
  36. } => {
  37. return {
  38. organization: organization ?? initializeOrg().organization,
  39. project: project ?? initializeOrg().project,
  40. group: GroupFixture(),
  41. router: RouterFixture({
  42. location: LocationFixture({
  43. query: query ?? {},
  44. }),
  45. }),
  46. event: EventFixture({
  47. size: 1,
  48. dateCreated: '2019-03-20T00:00:00.000Z',
  49. errors: [],
  50. entries: [],
  51. tags: [
  52. {key: 'environment', value: 'dev'},
  53. {key: 'mechanism', value: 'ANR'},
  54. ],
  55. contexts: {
  56. app: {
  57. app_start_time: '2021-08-31T15:14:21Z',
  58. device_app_hash: '0b77c3f2567d65fe816e1fa7013779fbe3b51633',
  59. build_type: 'test',
  60. app_identifier: 'io.sentry.sample.iOS-Swift',
  61. app_name: 'iOS-Swift',
  62. app_version: '7.2.3',
  63. app_build: '390',
  64. app_id: 'B2690307-FDD1-3D34-AA1E-E280A9C2406C',
  65. type: 'app',
  66. },
  67. device: {
  68. family: 'iOS',
  69. model: 'iPhone13,4',
  70. model_id: 'D54pAP',
  71. memory_size: 5987008512,
  72. free_memory: 154435584,
  73. usable_memory: 4706893824,
  74. storage_size: 127881465856,
  75. boot_time: '2021-08-29T06:05:51Z',
  76. timezone: 'CEST',
  77. type: 'device',
  78. },
  79. os: {
  80. name: 'iOS',
  81. version: '14.7.1',
  82. build: '18G82',
  83. kernel_version:
  84. 'Darwin Kernel Version 20.6.0: Mon Jun 21 21:23:35 PDT 2021; root:xnu-7195.140.42~10/RELEASE_ARM64_T8101',
  85. rooted: false,
  86. type: 'os',
  87. },
  88. trace: {
  89. trace_id: TRACE_ID,
  90. span_id: 'b0e6f15b45c36b12',
  91. op: 'ui.action.click',
  92. type: 'trace',
  93. },
  94. },
  95. }),
  96. };
  97. };
  98. function TestComponent(
  99. props: Partial<GroupEventDetailsProps> & {query?: Record<string, string | string[]>}
  100. ) {
  101. const {organization, project, group, event, router} = makeDefaultMockData(
  102. props.organization,
  103. props.project,
  104. props.query ?? {environment: ['dev']}
  105. );
  106. const mergedProps: GroupEventDetailsProps = {
  107. group,
  108. event,
  109. project,
  110. organization,
  111. params: {groupId: group.id, eventId: '1'},
  112. router,
  113. location: {} as Location<any>,
  114. route: {},
  115. eventError: props.eventError ?? false,
  116. groupReprocessingStatus:
  117. props.groupReprocessingStatus ?? ReprocessingStatus.NO_STATUS,
  118. onRetry: props?.onRetry ?? jest.fn(),
  119. loadingEvent: props.loadingEvent ?? false,
  120. routes: [],
  121. routeParams: {},
  122. ...props,
  123. };
  124. return (
  125. <RouteContext.Provider
  126. value={{
  127. router,
  128. location: router.location,
  129. params: router.params,
  130. routes: router.routes,
  131. }}
  132. >
  133. <GroupEventDetails {...mergedProps} />
  134. </RouteContext.Provider>
  135. );
  136. }
  137. const mockedTrace = (project: Project) => {
  138. return {
  139. event_id: '8806ea4691c24fc7b1c77ecd78df574f',
  140. span_id: 'b0e6f15b45c36b12',
  141. transaction: 'MainActivity.add_attachment',
  142. 'transaction.duration': 1000,
  143. 'transaction.op': 'navigation',
  144. project_id: parseInt(project.id, 10),
  145. project_slug: project.slug,
  146. parent_span_id: null,
  147. parent_event_id: null,
  148. generation: 0,
  149. errors: [
  150. {
  151. event_id: 'c6971a73454646338bc3ec80c70f8891',
  152. issue_id: 104,
  153. span: 'b0e6f15b45c36b12',
  154. project_id: parseInt(project.id, 10),
  155. project_slug: project.slug,
  156. title: 'ApplicationNotResponding: ANR for at least 5000 ms.',
  157. message: 'ANR for at least 5000 ms.',
  158. level: 'error',
  159. issue: '',
  160. },
  161. ],
  162. performance_issues: [
  163. {
  164. event_id: '8806ea4691c24fc7b1c77ecd78df574f',
  165. issue_id: 110,
  166. issue_short_id: 'SENTRY-ANDROID-1R',
  167. span: ['b0e6f15b45c36b12'],
  168. suspect_spans: ['89930aab9a0314d4'],
  169. project_id: parseInt(project.id, 10),
  170. project_slug: project.slug,
  171. title: 'File IO on Main Thread',
  172. message: 'File IO on Main Thread',
  173. level: 'info',
  174. culprit: 'MainActivity.add_attachment',
  175. type: 1008,
  176. end: 1678290375.15056,
  177. start: 1678290374.150562,
  178. },
  179. ],
  180. timestamp: 1678290375.150561,
  181. start_timestamp: 1678290374.150561,
  182. children: [],
  183. } as QuickTraceEvent;
  184. };
  185. const mockGroupApis = (
  186. organization: Organization,
  187. project: Project,
  188. group: Group,
  189. event: Event,
  190. trace?: QuickTraceEvent
  191. ) => {
  192. MockApiClient.addMockResponse({
  193. url: `/organizations/${organization.slug}/issues/${group.id}/`,
  194. body: group,
  195. });
  196. MockApiClient.addMockResponse({
  197. url: `/projects/${organization.slug}/${project.slug}/issues/`,
  198. method: 'PUT',
  199. });
  200. MockApiClient.addMockResponse({
  201. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  202. body: {committers: []},
  203. });
  204. MockApiClient.addMockResponse({
  205. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/owners/`,
  206. body: {owners: [], rules: []},
  207. });
  208. MockApiClient.addMockResponse({
  209. url: `/organizations/${organization.slug}/issues/${group.id}/tags/`,
  210. body: [],
  211. });
  212. MockApiClient.addMockResponse({
  213. url: `/organizations/${organization.slug}/events-trace/${TRACE_ID}/`,
  214. body: trace
  215. ? {transactions: [trace], orphan_errors: []}
  216. : {transactions: [], orphan_errors: []},
  217. });
  218. MockApiClient.addMockResponse({
  219. url: `/organizations/${organization.slug}/events-trace-light/${TRACE_ID}/`,
  220. body: trace
  221. ? {transactions: [trace], orphan_errors: []}
  222. : {transactions: [], orphan_errors: []},
  223. });
  224. MockApiClient.addMockResponse({
  225. url: `/organizations/${organization.slug}/issues/${group.id}/integrations/`,
  226. body: [],
  227. });
  228. MockApiClient.addMockResponse({
  229. url: `/organizations/${organization.slug}/issues/${group.id}/external-issues/`,
  230. });
  231. MockApiClient.addMockResponse({
  232. url: `/organizations/${organization.slug}/issues/${group.id}/current-release/`,
  233. body: {currentRelease: null},
  234. });
  235. MockApiClient.addMockResponse({
  236. url: `/organizations/${organization.slug}/prompts-activity/`,
  237. body: {data: {}, features: {['issue_feedback_hidden']: {}}},
  238. });
  239. MockApiClient.addMockResponse({
  240. url: `/organizations/${organization.slug}/prompts-activity/`,
  241. method: 'PUT',
  242. });
  243. MockApiClient.addMockResponse({
  244. url: `/organizations/${organization.slug}/has-mobile-app-events/`,
  245. body: null,
  246. });
  247. MockApiClient.addMockResponse({
  248. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/grouping-info/`,
  249. body: {},
  250. });
  251. MockApiClient.addMockResponse({
  252. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  253. body: [],
  254. });
  255. MockApiClient.addMockResponse({
  256. url: `/organizations/${organization.slug}/code-mappings/`,
  257. method: 'GET',
  258. body: [],
  259. });
  260. MockApiClient.addMockResponse({
  261. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/actionable-items/`,
  262. body: {
  263. errors: [],
  264. },
  265. });
  266. // Sentry related mocks
  267. MockApiClient.addMockResponse({
  268. url: '/sentry-apps/',
  269. body: [],
  270. });
  271. MockApiClient.addMockResponse({
  272. url: `/organizations/${organization.slug}/sentry-apps/`,
  273. body: [],
  274. });
  275. MockApiClient.addMockResponse({
  276. url: `/organizations/${organization.slug}/sentry-app-installations/`,
  277. body: [],
  278. });
  279. MockApiClient.addMockResponse({
  280. url: `/organizations/${organization.slug}/sentry-app-components/`,
  281. body: [],
  282. match: [MockApiClient.matchQuery({projectId: project.id})],
  283. });
  284. MockApiClient.addMockResponse({
  285. url: '/projects/org-slug/project-slug/',
  286. body: project,
  287. });
  288. MockApiClient.addMockResponse({
  289. url: '/organizations/org-slug/users/',
  290. body: [],
  291. });
  292. MockApiClient.addMockResponse({
  293. url: '/organizations/org-slug/projects/',
  294. body: [project],
  295. });
  296. MockApiClient.addMockResponse({
  297. url: `/customers/org-slug/policies/`,
  298. body: {},
  299. });
  300. MockApiClient.addMockResponse({
  301. url: `/organizations/${organization.slug}/issues/${group.id}/first-last-release/`,
  302. method: 'GET',
  303. });
  304. MockApiClient.addMockResponse({
  305. url: `/organizations/${organization.slug}/events/`,
  306. body: {
  307. data: [],
  308. meta: {fields: {}, units: {}},
  309. },
  310. });
  311. MockApiClient.addMockResponse({
  312. url: `/projects/${organization.slug}/${project.slug}/`,
  313. body: project,
  314. });
  315. };
  316. describe('groupEventDetails', () => {
  317. beforeEach(() => {
  318. MockApiClient.clearMockResponses();
  319. });
  320. afterEach(function () {
  321. MockApiClient.clearMockResponses();
  322. jest.mocked(browserHistory.replace).mockClear();
  323. });
  324. it('redirects on switching to an invalid environment selection for event', async function () {
  325. const props = makeDefaultMockData();
  326. mockGroupApis(props.organization, props.project, props.group, props.event);
  327. const {rerender} = render(<TestComponent {...props} />);
  328. expect(browserHistory.replace).not.toHaveBeenCalled();
  329. rerender(<TestComponent query={{environment: ['prod']}} />);
  330. await waitFor(() => expect(browserHistory.replace).toHaveBeenCalled());
  331. });
  332. it('does not redirect when switching to a valid environment selection for event', async function () {
  333. const props = makeDefaultMockData();
  334. mockGroupApis(props.organization, props.project, props.group, props.event);
  335. const {rerender} = render(<TestComponent {...props} />);
  336. expect(browserHistory.replace).not.toHaveBeenCalled();
  337. rerender(<TestComponent query={{environment: []}} />);
  338. expect(await screen.findByTestId('group-event-details')).toBeInTheDocument();
  339. expect(browserHistory.replace).not.toHaveBeenCalled();
  340. });
  341. it('displays error on event error', async function () {
  342. const props = makeDefaultMockData();
  343. mockGroupApis(
  344. props.organization,
  345. props.project,
  346. props.group,
  347. EventFixture({
  348. size: 1,
  349. dateCreated: '2019-03-20T00:00:00.000Z',
  350. errors: [],
  351. entries: [],
  352. tags: [{key: 'environment', value: 'dev'}],
  353. previousEventID: 'prev-event-id',
  354. nextEventID: 'next-event-id',
  355. })
  356. );
  357. render(<TestComponent event={undefined} eventError />);
  358. expect(
  359. await screen.findByText(/events for this issue could not be found/)
  360. ).toBeInTheDocument();
  361. });
  362. it('renders the Span Evidence and Resources section for Performance Issues', async function () {
  363. const props = makeDefaultMockData();
  364. const group: Group = GroupFixture({
  365. issueCategory: IssueCategory.PERFORMANCE,
  366. issueType: IssueType.PERFORMANCE_N_PLUS_ONE_DB_QUERIES,
  367. });
  368. const transaction = EventFixture({
  369. entries: [{type: EntryType.SPANS, data: []}],
  370. });
  371. mockGroupApis(
  372. props.organization,
  373. props.project,
  374. props.group,
  375. EventFixture({
  376. size: 1,
  377. dateCreated: '2019-03-20T00:00:00.000Z',
  378. errors: [],
  379. entries: [],
  380. tags: [{key: 'environment', value: 'dev'}],
  381. previousEventID: 'prev-event-id',
  382. nextEventID: 'next-event-id',
  383. })
  384. );
  385. render(<TestComponent group={group} event={transaction} />, {
  386. organization: props.organization,
  387. });
  388. expect(
  389. await screen.findByRole('heading', {
  390. name: /span evidence/i,
  391. })
  392. ).toBeInTheDocument();
  393. expect(
  394. screen.getByRole('heading', {
  395. name: /resources/i,
  396. })
  397. ).toBeInTheDocument();
  398. });
  399. it('renders the Function Evidence and Resources section for Profile Issues', async function () {
  400. const props = makeDefaultMockData();
  401. const group: Group = GroupFixture({
  402. issueCategory: IssueCategory.PERFORMANCE,
  403. issueType: IssueType.PROFILE_FILE_IO_MAIN_THREAD,
  404. });
  405. const transaction = EventFixture({
  406. entries: [],
  407. occurrence: {
  408. evidenceDisplay: [],
  409. evidenceData: {
  410. templateName: 'profile',
  411. },
  412. type: 2001,
  413. },
  414. });
  415. mockGroupApis(
  416. props.organization,
  417. props.project,
  418. props.group,
  419. EventFixture({
  420. size: 1,
  421. dateCreated: '2019-03-20T00:00:00.000Z',
  422. errors: [],
  423. entries: [],
  424. tags: [{key: 'environment', value: 'dev'}],
  425. previousEventID: 'prev-event-id',
  426. nextEventID: 'next-event-id',
  427. })
  428. );
  429. render(<TestComponent group={group} event={transaction} />, {});
  430. expect(
  431. await screen.findByRole('heading', {
  432. name: /function evidence/i,
  433. })
  434. ).toBeInTheDocument();
  435. expect(
  436. screen.getByRole('heading', {
  437. name: /resources/i,
  438. })
  439. ).toBeInTheDocument();
  440. });
  441. it('renders event tags ui', async () => {
  442. const props = makeDefaultMockData();
  443. mockGroupApis(props.organization, props.project, props.group, props.event);
  444. render(<TestComponent group={props.group} event={props.event} />, {});
  445. expect(await screen.findByText('Event ID:')).toBeInTheDocument();
  446. expect(screen.queryByTestId('context-summary')).not.toBeInTheDocument();
  447. expect(screen.getByTestId('event-tags')).toBeInTheDocument();
  448. const highlights = screen.getByTestId('event-highlights');
  449. expect(
  450. within(highlights).getByRole('button', {name: 'View All'})
  451. ).toBeInTheDocument();
  452. expect(within(highlights).getByRole('button', {name: 'Edit'})).toBeInTheDocument();
  453. // No highlights setup
  454. expect(
  455. within(highlights).getByRole('button', {name: 'Add Highlights'})
  456. ).toBeInTheDocument();
  457. expect(screen.getByText("There's nothing here...")).toBeInTheDocument();
  458. });
  459. });
  460. describe('EventCause', () => {
  461. beforeEach(() => {
  462. MockApiClient.clearMockResponses();
  463. });
  464. afterEach(function () {
  465. MockApiClient.clearMockResponses();
  466. jest.mocked(browserHistory.replace).mockClear();
  467. });
  468. it('renders suspect commit', async function () {
  469. const props = makeDefaultMockData(
  470. undefined,
  471. ProjectFixture({firstEvent: EventFixture().dateCreated})
  472. );
  473. mockGroupApis(
  474. props.organization,
  475. props.project,
  476. props.group,
  477. EventFixture({
  478. size: 1,
  479. dateCreated: '2019-03-20T00:00:00.000Z',
  480. errors: [],
  481. entries: [],
  482. tags: [{key: 'environment', value: 'dev'}],
  483. previousEventID: 'prev-event-id',
  484. nextEventID: 'next-event-id',
  485. })
  486. );
  487. MockApiClient.addMockResponse({
  488. url: `/projects/${props.organization.slug}/${props.project.slug}/events/${props.event.id}/committers/`,
  489. body: {
  490. committers: [
  491. {
  492. commits: [CommitFixture({author: CommitAuthorFixture()})],
  493. author: CommitAuthorFixture(),
  494. },
  495. ],
  496. },
  497. });
  498. render(<TestComponent project={props.project} />);
  499. expect(await screen.findByTestId(/suspect-commit/)).toBeInTheDocument();
  500. });
  501. });
  502. describe('Platform Integrations', () => {
  503. let componentsRequest;
  504. beforeEach(() => {
  505. MockApiClient.clearMockResponses();
  506. });
  507. it('loads Integration UI components', async () => {
  508. const props = makeDefaultMockData();
  509. const unpublishedIntegration = SentryAppFixture({status: 'unpublished'});
  510. const internalIntegration = SentryAppFixture({status: 'internal'});
  511. const unpublishedInstall = SentryAppInstallationFixture({
  512. app: {
  513. slug: unpublishedIntegration.slug,
  514. uuid: unpublishedIntegration.uuid,
  515. },
  516. });
  517. const internalInstall = SentryAppInstallationFixture({
  518. app: {
  519. slug: internalIntegration.slug,
  520. uuid: internalIntegration.uuid,
  521. },
  522. });
  523. mockGroupApis(
  524. props.organization,
  525. props.project,
  526. props.group,
  527. EventFixture({
  528. size: 1,
  529. dateCreated: '2019-03-20T00:00:00.000Z',
  530. errors: [],
  531. entries: [],
  532. tags: [{key: 'environment', value: 'dev'}],
  533. previousEventID: 'prev-event-id',
  534. nextEventID: 'next-event-id',
  535. })
  536. );
  537. const component = SentryAppComponentFixture({
  538. sentryApp: {
  539. uuid: unpublishedIntegration.uuid,
  540. slug: unpublishedIntegration.slug,
  541. name: unpublishedIntegration.name,
  542. },
  543. });
  544. MockApiClient.addMockResponse({
  545. url: `/organizations/${props.organization.slug}/sentry-app-installations/`,
  546. body: [unpublishedInstall, internalInstall],
  547. });
  548. componentsRequest = MockApiClient.addMockResponse({
  549. url: `/organizations/${props.organization.slug}/sentry-app-components/`,
  550. body: [component],
  551. match: [MockApiClient.matchQuery({projectId: props.project.id})],
  552. });
  553. render(<TestComponent />);
  554. expect(await screen.findByText('Sample App Issue')).toBeInTheDocument();
  555. expect(componentsRequest).toHaveBeenCalled();
  556. });
  557. describe('ANR Root Cause', () => {
  558. beforeEach(() => {
  559. MockApiClient.clearMockResponses();
  560. });
  561. it('shows anr root cause', async () => {
  562. const {organization} = initializeOrg();
  563. const props = makeDefaultMockData({
  564. ...organization,
  565. features: ['anr-improvements'],
  566. });
  567. mockGroupApis(
  568. props.organization,
  569. props.project,
  570. props.group,
  571. props.event,
  572. mockedTrace(props.project)
  573. );
  574. render(<TestComponent group={props.group} event={props.event} />, {
  575. organization: props.organization,
  576. });
  577. expect(
  578. await screen.findByRole('heading', {
  579. name: /suspect root cause/i,
  580. })
  581. ).toBeInTheDocument();
  582. expect(screen.getByText('File IO on Main Thread')).toBeInTheDocument();
  583. });
  584. it('does not render root issues section if related perf issues do not exist', async () => {
  585. const {organization} = initializeOrg();
  586. const props = makeDefaultMockData({
  587. ...organization,
  588. features: ['anr-improvements'],
  589. });
  590. const trace = mockedTrace(props.project);
  591. mockGroupApis(props.organization, props.project, props.group, props.event, {
  592. ...trace,
  593. performance_issues: [],
  594. });
  595. render(<TestComponent group={props.group} event={props.event} />, {
  596. organization: props.organization,
  597. });
  598. // mechanism: ANR
  599. expect(await screen.findByText('ANR')).toBeInTheDocument();
  600. expect(
  601. screen.queryByRole('heading', {
  602. name: /suspect root issues/i,
  603. })
  604. ).not.toBeInTheDocument();
  605. expect(screen.queryByText('File IO on Main Thread')).not.toBeInTheDocument();
  606. });
  607. });
  608. });