groupEventDetails.spec.tsx 17 KB

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