groupEventDetails.spec.tsx 19 KB

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