groupEventDetails.spec.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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: undefined,
  238. });
  239. MockApiClient.addMockResponse({
  240. url: `/organizations/${organization.slug}/has-mobile-app-events/`,
  241. body: null,
  242. });
  243. MockApiClient.addMockResponse({
  244. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/grouping-info/`,
  245. body: {},
  246. });
  247. MockApiClient.addMockResponse({
  248. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  249. body: [],
  250. });
  251. MockApiClient.addMockResponse({
  252. url: `/organizations/${organization.slug}/code-mappings/`,
  253. method: 'GET',
  254. body: [],
  255. });
  256. MockApiClient.addMockResponse({
  257. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/actionable-items/`,
  258. body: {
  259. errors: [],
  260. },
  261. });
  262. // Sentry related mocks
  263. MockApiClient.addMockResponse({
  264. url: '/sentry-apps/',
  265. body: [],
  266. });
  267. MockApiClient.addMockResponse({
  268. url: `/organizations/${organization.slug}/sentry-apps/`,
  269. body: [],
  270. });
  271. MockApiClient.addMockResponse({
  272. url: `/organizations/${organization.slug}/sentry-app-installations/`,
  273. body: [],
  274. });
  275. MockApiClient.addMockResponse({
  276. url: `/organizations/${organization.slug}/sentry-app-components/`,
  277. body: [],
  278. match: [MockApiClient.matchQuery({projectId: project.id})],
  279. });
  280. MockApiClient.addMockResponse({
  281. url: '/projects/org-slug/project-slug/',
  282. body: project,
  283. });
  284. MockApiClient.addMockResponse({
  285. url: '/organizations/org-slug/users/',
  286. body: [],
  287. });
  288. MockApiClient.addMockResponse({
  289. url: '/organizations/org-slug/projects/',
  290. body: [project],
  291. });
  292. MockApiClient.addMockResponse({
  293. url: `/customers/org-slug/policies/`,
  294. body: {},
  295. });
  296. MockApiClient.addMockResponse({
  297. url: `/organizations/${organization.slug}/issues/${group.id}/first-last-release/`,
  298. method: 'GET',
  299. });
  300. MockApiClient.addMockResponse({
  301. url: `/organizations/${organization.slug}/events/`,
  302. body: {
  303. data: [],
  304. meta: {fields: {}, units: {}},
  305. },
  306. });
  307. };
  308. describe('groupEventDetails', () => {
  309. beforeEach(() => {
  310. MockApiClient.clearMockResponses();
  311. });
  312. afterEach(function () {
  313. MockApiClient.clearMockResponses();
  314. jest.mocked(browserHistory.replace).mockClear();
  315. });
  316. it('redirects on switching to an invalid environment selection for event', async function () {
  317. const props = makeDefaultMockData();
  318. mockGroupApis(props.organization, props.project, props.group, props.event);
  319. const {rerender} = render(<TestComponent {...props} />);
  320. expect(browserHistory.replace).not.toHaveBeenCalled();
  321. rerender(<TestComponent query={{environment: ['prod']}} />);
  322. await waitFor(() => expect(browserHistory.replace).toHaveBeenCalled());
  323. });
  324. it('does not redirect when switching to a valid 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: []}} />);
  330. expect(await screen.findByTestId('group-event-details')).toBeInTheDocument();
  331. expect(browserHistory.replace).not.toHaveBeenCalled();
  332. });
  333. it('displays error on event error', async function () {
  334. const props = makeDefaultMockData();
  335. mockGroupApis(
  336. props.organization,
  337. props.project,
  338. props.group,
  339. EventFixture({
  340. size: 1,
  341. dateCreated: '2019-03-20T00:00:00.000Z',
  342. errors: [],
  343. entries: [],
  344. tags: [{key: 'environment', value: 'dev'}],
  345. previousEventID: 'prev-event-id',
  346. nextEventID: 'next-event-id',
  347. })
  348. );
  349. render(<TestComponent event={undefined} eventError />);
  350. expect(
  351. await screen.findByText(/events for this issue could not be found/)
  352. ).toBeInTheDocument();
  353. });
  354. it('renders the Span Evidence and Resources section for Performance Issues', async function () {
  355. const props = makeDefaultMockData();
  356. const group: Group = GroupFixture({
  357. issueCategory: IssueCategory.PERFORMANCE,
  358. issueType: IssueType.PERFORMANCE_N_PLUS_ONE_DB_QUERIES,
  359. });
  360. const transaction = EventFixture({
  361. entries: [{type: EntryType.SPANS, data: []}],
  362. });
  363. mockGroupApis(
  364. props.organization,
  365. props.project,
  366. props.group,
  367. EventFixture({
  368. size: 1,
  369. dateCreated: '2019-03-20T00:00:00.000Z',
  370. errors: [],
  371. entries: [],
  372. tags: [{key: 'environment', value: 'dev'}],
  373. previousEventID: 'prev-event-id',
  374. nextEventID: 'next-event-id',
  375. })
  376. );
  377. render(<TestComponent group={group} event={transaction} />, {
  378. organization: props.organization,
  379. });
  380. expect(
  381. await screen.findByRole('heading', {
  382. name: /span evidence/i,
  383. })
  384. ).toBeInTheDocument();
  385. expect(
  386. screen.getByRole('heading', {
  387. name: /resources/i,
  388. })
  389. ).toBeInTheDocument();
  390. });
  391. it('renders the Function Evidence and Resources section for Profile Issues', async function () {
  392. const props = makeDefaultMockData();
  393. const group: Group = GroupFixture({
  394. issueCategory: IssueCategory.PERFORMANCE,
  395. issueType: IssueType.PROFILE_FILE_IO_MAIN_THREAD,
  396. });
  397. const transaction = EventFixture({
  398. entries: [],
  399. occurrence: {
  400. evidenceDisplay: [],
  401. evidenceData: {
  402. templateName: 'profile',
  403. },
  404. type: 2001,
  405. },
  406. });
  407. mockGroupApis(
  408. props.organization,
  409. props.project,
  410. props.group,
  411. EventFixture({
  412. size: 1,
  413. dateCreated: '2019-03-20T00:00:00.000Z',
  414. errors: [],
  415. entries: [],
  416. tags: [{key: 'environment', value: 'dev'}],
  417. previousEventID: 'prev-event-id',
  418. nextEventID: 'next-event-id',
  419. })
  420. );
  421. render(<TestComponent group={group} event={transaction} />, {});
  422. expect(
  423. await screen.findByRole('heading', {
  424. name: /function evidence/i,
  425. })
  426. ).toBeInTheDocument();
  427. expect(
  428. screen.getByRole('heading', {
  429. name: /resources/i,
  430. })
  431. ).toBeInTheDocument();
  432. });
  433. it('renders event tags ui', async () => {
  434. const props = makeDefaultMockData();
  435. mockGroupApis(props.organization, props.project, props.group, props.event);
  436. render(<TestComponent group={props.group} event={props.event} />, {});
  437. expect(await screen.findByText('Event ID:')).toBeInTheDocument();
  438. expect(screen.queryByTestId('context-summary')).not.toBeInTheDocument();
  439. expect(screen.getByTestId('event-tags')).toBeInTheDocument();
  440. const highlights = screen.getByTestId('event-highlights');
  441. expect(
  442. within(highlights).getByRole('button', {name: 'View All'})
  443. ).toBeInTheDocument();
  444. expect(within(highlights).getByRole('button', {name: 'Edit'})).toBeInTheDocument();
  445. // No highlights setup
  446. expect(
  447. within(highlights).getByRole('button', {name: 'Add Highlights'})
  448. ).toBeInTheDocument();
  449. expect(screen.getByText("There's nothing here...")).toBeInTheDocument();
  450. });
  451. });
  452. describe('EventCause', () => {
  453. beforeEach(() => {
  454. MockApiClient.clearMockResponses();
  455. });
  456. afterEach(function () {
  457. MockApiClient.clearMockResponses();
  458. jest.mocked(browserHistory.replace).mockClear();
  459. });
  460. it('renders suspect commit', async function () {
  461. const props = makeDefaultMockData(
  462. undefined,
  463. ProjectFixture({firstEvent: EventFixture().dateCreated})
  464. );
  465. mockGroupApis(
  466. props.organization,
  467. props.project,
  468. props.group,
  469. EventFixture({
  470. size: 1,
  471. dateCreated: '2019-03-20T00:00:00.000Z',
  472. errors: [],
  473. entries: [],
  474. tags: [{key: 'environment', value: 'dev'}],
  475. previousEventID: 'prev-event-id',
  476. nextEventID: 'next-event-id',
  477. })
  478. );
  479. MockApiClient.addMockResponse({
  480. url: `/projects/${props.organization.slug}/${props.project.slug}/events/${props.event.id}/committers/`,
  481. body: {
  482. committers: [
  483. {
  484. commits: [CommitFixture({author: CommitAuthorFixture()})],
  485. author: CommitAuthorFixture(),
  486. },
  487. ],
  488. },
  489. });
  490. render(<TestComponent project={props.project} />);
  491. expect(await screen.findByTestId(/suspect-commit/)).toBeInTheDocument();
  492. });
  493. });
  494. describe('Platform Integrations', () => {
  495. let componentsRequest;
  496. beforeEach(() => {
  497. MockApiClient.clearMockResponses();
  498. });
  499. it('loads Integration UI components', async () => {
  500. const props = makeDefaultMockData();
  501. const unpublishedIntegration = SentryAppFixture({status: 'unpublished'});
  502. const internalIntegration = SentryAppFixture({status: 'internal'});
  503. const unpublishedInstall = SentryAppInstallationFixture({
  504. app: {
  505. slug: unpublishedIntegration.slug,
  506. uuid: unpublishedIntegration.uuid,
  507. },
  508. });
  509. const internalInstall = SentryAppInstallationFixture({
  510. app: {
  511. slug: internalIntegration.slug,
  512. uuid: internalIntegration.uuid,
  513. },
  514. });
  515. mockGroupApis(
  516. props.organization,
  517. props.project,
  518. props.group,
  519. EventFixture({
  520. size: 1,
  521. dateCreated: '2019-03-20T00:00:00.000Z',
  522. errors: [],
  523. entries: [],
  524. tags: [{key: 'environment', value: 'dev'}],
  525. previousEventID: 'prev-event-id',
  526. nextEventID: 'next-event-id',
  527. })
  528. );
  529. const component = SentryAppComponentFixture({
  530. sentryApp: {
  531. uuid: unpublishedIntegration.uuid,
  532. slug: unpublishedIntegration.slug,
  533. name: unpublishedIntegration.name,
  534. },
  535. });
  536. MockApiClient.addMockResponse({
  537. url: `/organizations/${props.organization.slug}/sentry-app-installations/`,
  538. body: [unpublishedInstall, internalInstall],
  539. });
  540. componentsRequest = MockApiClient.addMockResponse({
  541. url: `/organizations/${props.organization.slug}/sentry-app-components/`,
  542. body: [component],
  543. match: [MockApiClient.matchQuery({projectId: props.project.id})],
  544. });
  545. render(<TestComponent />);
  546. expect(await screen.findByText('Sample App Issue')).toBeInTheDocument();
  547. expect(componentsRequest).toHaveBeenCalled();
  548. });
  549. describe('ANR Root Cause', () => {
  550. beforeEach(() => {
  551. MockApiClient.clearMockResponses();
  552. });
  553. it('shows anr root cause', async () => {
  554. const {organization} = initializeOrg();
  555. const props = makeDefaultMockData({
  556. ...organization,
  557. features: ['anr-improvements'],
  558. });
  559. mockGroupApis(
  560. props.organization,
  561. props.project,
  562. props.group,
  563. props.event,
  564. mockedTrace(props.project)
  565. );
  566. render(<TestComponent group={props.group} event={props.event} />, {
  567. organization: props.organization,
  568. });
  569. expect(
  570. await screen.findByRole('heading', {
  571. name: /suspect root cause/i,
  572. })
  573. ).toBeInTheDocument();
  574. expect(screen.getByText('File IO on Main Thread')).toBeInTheDocument();
  575. });
  576. it('does not render root issues section if related perf issues do not exist', async () => {
  577. const {organization} = initializeOrg();
  578. const props = makeDefaultMockData({
  579. ...organization,
  580. features: ['anr-improvements'],
  581. });
  582. const trace = mockedTrace(props.project);
  583. mockGroupApis(props.organization, props.project, props.group, props.event, {
  584. ...trace,
  585. performance_issues: [],
  586. });
  587. render(<TestComponent group={props.group} event={props.event} />, {
  588. organization: props.organization,
  589. });
  590. // mechanism: ANR
  591. expect(await screen.findByText('ANR')).toBeInTheDocument();
  592. expect(
  593. screen.queryByRole('heading', {
  594. name: /suspect root issues/i,
  595. })
  596. ).not.toBeInTheDocument();
  597. expect(screen.queryByText('File IO on Main Thread')).not.toBeInTheDocument();
  598. });
  599. });
  600. });