groupEventDetails.spec.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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 LocationFixture from 'sentry-fixture/locationFixture';
  7. import RouterContextFixture from 'sentry-fixture/routerContextFixture';
  8. import {SentryApp} from 'sentry-fixture/sentryApp';
  9. import {SentryAppComponent} from 'sentry-fixture/sentryAppComponent';
  10. import {initializeOrg} from 'sentry-test/initializeOrg';
  11. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  12. import {EntryType, Event, Group, IssueCategory, IssueType} from 'sentry/types';
  13. import {Organization} from 'sentry/types/organization';
  14. import {Project} from 'sentry/types/project';
  15. import {QuickTraceEvent} from 'sentry/utils/performance/quickTrace/types';
  16. import GroupEventDetails, {
  17. GroupEventDetailsProps,
  18. } from 'sentry/views/issueDetails/groupEventDetails/groupEventDetails';
  19. import {ReprocessingStatus} from 'sentry/views/issueDetails/utils';
  20. import {RouteContext} from 'sentry/views/routeContext';
  21. const TRACE_ID = '797cda4e24844bdc90e0efe741616047';
  22. const makeDefaultMockData = (
  23. organization?: Organization,
  24. project?: Project,
  25. environments?: string[]
  26. ): {
  27. event: Event;
  28. group: Group;
  29. organization: Organization;
  30. project: Project;
  31. router: InjectedRouter;
  32. } => {
  33. return {
  34. organization: organization ?? initializeOrg().organization,
  35. project: project ?? initializeOrg().project,
  36. group: TestStubs.Group(),
  37. router: TestStubs.router({
  38. location: LocationFixture({
  39. query: {
  40. environment: environments,
  41. },
  42. }),
  43. }),
  44. event: EventFixture({
  45. size: 1,
  46. dateCreated: '2019-03-20T00:00:00.000Z',
  47. errors: [],
  48. entries: [],
  49. tags: [
  50. {key: 'environment', value: 'dev'},
  51. {key: 'mechanism', value: 'ANR'},
  52. ],
  53. contexts: {
  54. trace: {
  55. trace_id: TRACE_ID,
  56. span_id: 'b0e6f15b45c36b12',
  57. op: 'ui.action.click',
  58. type: 'trace',
  59. },
  60. },
  61. }),
  62. };
  63. };
  64. function TestComponent(
  65. props: Partial<GroupEventDetailsProps> & {environments?: string[]}
  66. ) {
  67. const {organization, project, group, event, router} = makeDefaultMockData(
  68. props.organization,
  69. props.project,
  70. props.environments ?? ['dev']
  71. );
  72. const mergedProps: GroupEventDetailsProps = {
  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/`,
  241. body: [],
  242. match: [MockApiClient.matchQuery({projectId: project.id})],
  243. });
  244. MockApiClient.addMockResponse({
  245. url: '/projects/org-slug/project-slug/',
  246. body: project,
  247. });
  248. MockApiClient.addMockResponse({
  249. url: '/organizations/org-slug/users/',
  250. body: [],
  251. });
  252. MockApiClient.addMockResponse({
  253. url: '/organizations/org-slug/projects/',
  254. body: [project],
  255. });
  256. MockApiClient.addMockResponse({
  257. url: `/customers/org-slug/policies/`,
  258. body: {},
  259. });
  260. MockApiClient.addMockResponse({
  261. url: `/organizations/${organization.slug}/issues/${group.id}/first-last-release/`,
  262. method: 'GET',
  263. });
  264. };
  265. describe('groupEventDetails', () => {
  266. beforeEach(() => {
  267. MockApiClient.clearMockResponses();
  268. });
  269. afterEach(function () {
  270. MockApiClient.clearMockResponses();
  271. (browserHistory.replace as jest.Mock).mockClear();
  272. });
  273. it('redirects on switching to an invalid environment selection for event', async function () {
  274. const props = makeDefaultMockData();
  275. mockGroupApis(props.organization, props.project, props.group, props.event);
  276. const {rerender} = render(<TestComponent {...props} />, {
  277. organization: props.organization,
  278. });
  279. expect(browserHistory.replace).not.toHaveBeenCalled();
  280. rerender(<TestComponent environments={['prod']} />);
  281. await waitFor(() => expect(browserHistory.replace).toHaveBeenCalled());
  282. });
  283. it('does not redirect when switching to a valid environment selection for event', async function () {
  284. const props = makeDefaultMockData();
  285. mockGroupApis(props.organization, props.project, props.group, props.event);
  286. const {rerender} = render(<TestComponent {...props} />, {
  287. organization: props.organization,
  288. });
  289. expect(browserHistory.replace).not.toHaveBeenCalled();
  290. rerender(<TestComponent environments={[]} />);
  291. expect(await screen.findByTestId('group-event-details')).toBeInTheDocument();
  292. expect(browserHistory.replace).not.toHaveBeenCalled();
  293. });
  294. it('displays error on event error', async function () {
  295. const props = makeDefaultMockData();
  296. mockGroupApis(
  297. props.organization,
  298. props.project,
  299. props.group,
  300. EventFixture({
  301. size: 1,
  302. dateCreated: '2019-03-20T00:00:00.000Z',
  303. errors: [],
  304. entries: [],
  305. tags: [{key: 'environment', value: 'dev'}],
  306. previousEventID: 'prev-event-id',
  307. nextEventID: 'next-event-id',
  308. })
  309. );
  310. render(<TestComponent event={undefined} eventError />, {
  311. organization: props.organization,
  312. });
  313. expect(
  314. await screen.findByText(/events for this issue could not be found/)
  315. ).toBeInTheDocument();
  316. });
  317. it('renders the Span Evidence and Resources section for Performance Issues', async function () {
  318. const props = makeDefaultMockData();
  319. const group: Group = TestStubs.Group({
  320. issueCategory: IssueCategory.PERFORMANCE,
  321. issueType: IssueType.PERFORMANCE_N_PLUS_ONE_DB_QUERIES,
  322. });
  323. const transaction = EventFixture({
  324. entries: [{type: EntryType.SPANS, data: []}],
  325. });
  326. mockGroupApis(
  327. props.organization,
  328. props.project,
  329. props.group,
  330. EventFixture({
  331. size: 1,
  332. dateCreated: '2019-03-20T00:00:00.000Z',
  333. errors: [],
  334. entries: [],
  335. tags: [{key: 'environment', value: 'dev'}],
  336. previousEventID: 'prev-event-id',
  337. nextEventID: 'next-event-id',
  338. })
  339. );
  340. const routerContext = RouterContextFixture();
  341. render(<TestComponent group={group} event={transaction} />, {
  342. organization: props.organization,
  343. context: routerContext,
  344. });
  345. expect(
  346. await screen.findByRole('heading', {
  347. name: /span evidence/i,
  348. })
  349. ).toBeInTheDocument();
  350. expect(
  351. screen.getByRole('heading', {
  352. name: /resources/i,
  353. })
  354. ).toBeInTheDocument();
  355. });
  356. it('renders the Function Evidence and Resources section for Profile Issues', async function () {
  357. const props = makeDefaultMockData();
  358. const group: Group = TestStubs.Group({
  359. issueCategory: IssueCategory.PERFORMANCE,
  360. issueType: IssueType.PROFILE_FILE_IO_MAIN_THREAD,
  361. });
  362. const transaction = EventFixture({
  363. entries: [],
  364. occurrence: {
  365. evidenceDisplay: [],
  366. evidenceData: {
  367. templateName: 'profile',
  368. },
  369. type: 2001,
  370. },
  371. });
  372. mockGroupApis(
  373. props.organization,
  374. props.project,
  375. props.group,
  376. EventFixture({
  377. size: 1,
  378. dateCreated: '2019-03-20T00:00:00.000Z',
  379. errors: [],
  380. entries: [],
  381. tags: [{key: 'environment', value: 'dev'}],
  382. previousEventID: 'prev-event-id',
  383. nextEventID: 'next-event-id',
  384. })
  385. );
  386. const routerContext = RouterContextFixture();
  387. render(<TestComponent group={group} event={transaction} />, {
  388. organization: props.organization,
  389. context: routerContext,
  390. });
  391. expect(
  392. await screen.findByRole('heading', {
  393. name: /function evidence/i,
  394. })
  395. ).toBeInTheDocument();
  396. expect(
  397. screen.getByRole('heading', {
  398. name: /resources/i,
  399. })
  400. ).toBeInTheDocument();
  401. });
  402. });
  403. describe('EventCause', () => {
  404. beforeEach(() => {
  405. MockApiClient.clearMockResponses();
  406. });
  407. afterEach(function () {
  408. MockApiClient.clearMockResponses();
  409. (browserHistory.replace as jest.Mock).mockClear();
  410. });
  411. it('renders suspect commit', async function () {
  412. const props = makeDefaultMockData(
  413. undefined,
  414. TestStubs.Project({firstEvent: EventFixture()})
  415. );
  416. mockGroupApis(
  417. props.organization,
  418. props.project,
  419. props.group,
  420. EventFixture({
  421. size: 1,
  422. dateCreated: '2019-03-20T00:00:00.000Z',
  423. errors: [],
  424. entries: [],
  425. tags: [{key: 'environment', value: 'dev'}],
  426. previousEventID: 'prev-event-id',
  427. nextEventID: 'next-event-id',
  428. })
  429. );
  430. MockApiClient.addMockResponse({
  431. url: `/projects/${props.organization.slug}/${props.project.slug}/events/${props.event.id}/committers/`,
  432. body: {
  433. committers: [
  434. {
  435. commits: [Commit({author: CommitAuthor()})],
  436. author: CommitAuthor(),
  437. },
  438. ],
  439. },
  440. });
  441. render(<TestComponent project={props.project} />, {organization: props.organization});
  442. expect(await screen.findByTestId(/suspect-commit/)).toBeInTheDocument();
  443. });
  444. });
  445. describe('Platform Integrations', () => {
  446. let componentsRequest;
  447. beforeEach(() => {
  448. MockApiClient.clearMockResponses();
  449. });
  450. it('loads Integration UI components', async () => {
  451. const props = makeDefaultMockData();
  452. const unpublishedIntegration = SentryApp({status: 'unpublished'});
  453. const internalIntegration = SentryApp({status: 'internal'});
  454. const unpublishedInstall = TestStubs.SentryAppInstallation({
  455. app: {
  456. slug: unpublishedIntegration.slug,
  457. uuid: unpublishedIntegration.uuid,
  458. },
  459. });
  460. const internalInstall = TestStubs.SentryAppInstallation({
  461. app: {
  462. slug: internalIntegration.slug,
  463. uuid: internalIntegration.uuid,
  464. },
  465. });
  466. mockGroupApis(
  467. props.organization,
  468. props.project,
  469. props.group,
  470. EventFixture({
  471. size: 1,
  472. dateCreated: '2019-03-20T00:00:00.000Z',
  473. errors: [],
  474. entries: [],
  475. tags: [{key: 'environment', value: 'dev'}],
  476. previousEventID: 'prev-event-id',
  477. nextEventID: 'next-event-id',
  478. })
  479. );
  480. const component = SentryAppComponent({
  481. sentryApp: {
  482. uuid: unpublishedIntegration.uuid,
  483. slug: unpublishedIntegration.slug,
  484. name: unpublishedIntegration.name,
  485. },
  486. });
  487. MockApiClient.addMockResponse({
  488. url: `/organizations/${props.organization.slug}/sentry-app-installations/`,
  489. body: [unpublishedInstall, internalInstall],
  490. });
  491. componentsRequest = MockApiClient.addMockResponse({
  492. url: `/organizations/${props.organization.slug}/sentry-app-components/`,
  493. body: [component],
  494. match: [MockApiClient.matchQuery({projectId: props.project.id})],
  495. });
  496. render(<TestComponent />, {organization: props.organization});
  497. expect(await screen.findByText('Sample App Issue')).toBeInTheDocument();
  498. expect(componentsRequest).toHaveBeenCalled();
  499. });
  500. describe('ANR Root Cause', () => {
  501. beforeEach(() => {
  502. MockApiClient.clearMockResponses();
  503. });
  504. it('shows anr root cause', async () => {
  505. const {organization} = initializeOrg();
  506. const props = makeDefaultMockData({
  507. ...organization,
  508. features: ['anr-improvements'],
  509. });
  510. mockGroupApis(
  511. props.organization,
  512. props.project,
  513. props.group,
  514. props.event,
  515. mockedTrace(props.project)
  516. );
  517. const routerContext = RouterContextFixture();
  518. render(<TestComponent group={props.group} event={props.event} />, {
  519. organization: props.organization,
  520. context: routerContext,
  521. });
  522. expect(
  523. await screen.findByRole('heading', {
  524. name: /suspect root cause/i,
  525. })
  526. ).toBeInTheDocument();
  527. expect(screen.getByText('File IO on Main Thread')).toBeInTheDocument();
  528. });
  529. it('does not render root issues section if related perf issues do not exist', async () => {
  530. const {organization} = initializeOrg();
  531. const props = makeDefaultMockData({
  532. ...organization,
  533. features: ['anr-improvements'],
  534. });
  535. const trace = mockedTrace(props.project);
  536. mockGroupApis(props.organization, props.project, props.group, props.event, {
  537. ...trace,
  538. performance_issues: [],
  539. });
  540. const routerContext = RouterContextFixture();
  541. render(<TestComponent group={props.group} event={props.event} />, {
  542. organization: props.organization,
  543. context: routerContext,
  544. });
  545. // mechanism: ANR
  546. expect(await screen.findByText('ANR')).toBeInTheDocument();
  547. expect(
  548. screen.queryByRole('heading', {
  549. name: /suspect root issues/i,
  550. })
  551. ).not.toBeInTheDocument();
  552. expect(screen.queryByText('File IO on Main Thread')).not.toBeInTheDocument();
  553. });
  554. });
  555. });