groupEventDetails.spec.tsx 20 KB

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