groupEventDetails.spec.tsx 19 KB

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