groupEventDetails.spec.tsx 19 KB

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