groupEventDetails.spec.tsx 17 KB

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