groupEventDetails.spec.tsx 20 KB

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