groupEventDetails.spec.tsx 19 KB

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