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