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 {SentryApp} from 'sentry-fixture/sentryApp';
  6. import {SentryAppComponent} from 'sentry-fixture/sentryAppComponent';
  7. import {initializeOrg} from 'sentry-test/initializeOrg';
  8. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  9. import {EntryType, Event, Group, IssueCategory, IssueType} from 'sentry/types';
  10. import {Organization} from 'sentry/types/organization';
  11. import {Project} from 'sentry/types/project';
  12. import {QuickTraceEvent} from 'sentry/utils/performance/quickTrace/types';
  13. import GroupEventDetails, {
  14. GroupEventDetailsProps,
  15. } from 'sentry/views/issueDetails/groupEventDetails/groupEventDetails';
  16. import {ReprocessingStatus} from 'sentry/views/issueDetails/utils';
  17. import {RouteContext} from 'sentry/views/routeContext';
  18. const TRACE_ID = '797cda4e24844bdc90e0efe741616047';
  19. const makeDefaultMockData = (
  20. organization?: Organization,
  21. project?: Project,
  22. environments?: string[]
  23. ): {
  24. event: Event;
  25. group: Group;
  26. organization: Organization;
  27. project: Project;
  28. router: InjectedRouter;
  29. } => {
  30. return {
  31. organization: organization ?? initializeOrg().organization,
  32. project: project ?? initializeOrg().project,
  33. group: TestStubs.Group(),
  34. router: TestStubs.router({
  35. location: TestStubs.location({
  36. query: {
  37. environment: environments,
  38. },
  39. }),
  40. }),
  41. event: TestStubs.Event({
  42. size: 1,
  43. dateCreated: '2019-03-20T00:00:00.000Z',
  44. errors: [],
  45. entries: [],
  46. tags: [
  47. {key: 'environment', value: 'dev'},
  48. {key: 'mechanism', value: 'ANR'},
  49. ],
  50. contexts: {
  51. trace: {
  52. trace_id: TRACE_ID,
  53. span_id: 'b0e6f15b45c36b12',
  54. op: 'ui.action.click',
  55. type: 'trace',
  56. },
  57. },
  58. }),
  59. };
  60. };
  61. function TestComponent(
  62. props: Partial<GroupEventDetailsProps> & {environments?: string[]}
  63. ) {
  64. const {organization, project, group, event, router} = makeDefaultMockData(
  65. props.organization,
  66. props.project,
  67. props.environments ?? ['dev']
  68. );
  69. const mergedProps: GroupEventDetailsProps = {
  70. api: new MockApiClient(),
  71. group,
  72. event,
  73. project,
  74. organization,
  75. params: {groupId: group.id, eventId: '1'},
  76. router,
  77. location: {} as Location<any>,
  78. route: {},
  79. eventError: props.eventError ?? false,
  80. groupReprocessingStatus:
  81. props.groupReprocessingStatus ?? ReprocessingStatus.NO_STATUS,
  82. onRetry: props?.onRetry ?? jest.fn(),
  83. loadingEvent: props.loadingEvent ?? false,
  84. routes: [],
  85. routeParams: {},
  86. ...props,
  87. };
  88. return (
  89. <RouteContext.Provider
  90. value={{
  91. router,
  92. location: router.location,
  93. params: router.params,
  94. routes: router.routes,
  95. }}
  96. >
  97. <GroupEventDetails {...mergedProps} />;
  98. </RouteContext.Provider>
  99. );
  100. }
  101. const mockedTrace = (project: Project) => {
  102. return {
  103. event_id: '8806ea4691c24fc7b1c77ecd78df574f',
  104. span_id: 'b0e6f15b45c36b12',
  105. transaction: 'MainActivity.add_attachment',
  106. 'transaction.duration': 1000,
  107. 'transaction.op': 'navigation',
  108. project_id: parseInt(project.id, 10),
  109. project_slug: project.slug,
  110. parent_span_id: null,
  111. parent_event_id: null,
  112. generation: 0,
  113. errors: [
  114. {
  115. event_id: 'c6971a73454646338bc3ec80c70f8891',
  116. issue_id: 104,
  117. span: 'b0e6f15b45c36b12',
  118. project_id: parseInt(project.id, 10),
  119. project_slug: project.slug,
  120. title: 'ApplicationNotResponding: ANR for at least 5000 ms.',
  121. level: 'error',
  122. issue: '',
  123. },
  124. ],
  125. performance_issues: [
  126. {
  127. event_id: '8806ea4691c24fc7b1c77ecd78df574f',
  128. issue_id: 110,
  129. issue_short_id: 'SENTRY-ANDROID-1R',
  130. span: ['b0e6f15b45c36b12'],
  131. suspect_spans: ['89930aab9a0314d4'],
  132. project_id: parseInt(project.id, 10),
  133. project_slug: project.slug,
  134. title: '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. trace?: QuickTraceEvent
  153. ) => {
  154. MockApiClient.addMockResponse({
  155. url: `/organizations/${organization.slug}/issues/${group.id}/`,
  156. body: group,
  157. });
  158. MockApiClient.addMockResponse({
  159. url: `/projects/${organization.slug}/${project.slug}/issues/`,
  160. method: 'PUT',
  161. });
  162. MockApiClient.addMockResponse({
  163. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  164. body: {committers: []},
  165. });
  166. MockApiClient.addMockResponse({
  167. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/owners/`,
  168. body: {owners: [], rules: []},
  169. });
  170. MockApiClient.addMockResponse({
  171. url: `/organizations/${organization.slug}/issues/${group.id}/tags/`,
  172. body: [],
  173. });
  174. MockApiClient.addMockResponse({
  175. url: `/organizations/${organization.slug}/events-trace/${TRACE_ID}/`,
  176. body: trace
  177. ? {transactions: [trace], orphan_errors: []}
  178. : {transactions: [], orphan_errors: []},
  179. });
  180. MockApiClient.addMockResponse({
  181. url: `/organizations/${organization.slug}/events-trace-light/${TRACE_ID}/`,
  182. body: trace
  183. ? {transactions: [trace], orphan_errors: []}
  184. : {transactions: [], orphan_errors: []},
  185. });
  186. MockApiClient.addMockResponse({
  187. url: `/organizations/${organization.slug}/issues/${group.id}/integrations/`,
  188. body: [],
  189. });
  190. MockApiClient.addMockResponse({
  191. url: `/organizations/${organization.slug}/issues/${group.id}/external-issues/`,
  192. });
  193. MockApiClient.addMockResponse({
  194. url: `/organizations/${organization.slug}/issues/${group.id}/current-release/`,
  195. body: {currentRelease: null},
  196. });
  197. MockApiClient.addMockResponse({
  198. url: '/prompts-activity/',
  199. body: undefined,
  200. });
  201. MockApiClient.addMockResponse({
  202. url: `/organizations/${organization.slug}/has-mobile-app-events/`,
  203. body: null,
  204. });
  205. MockApiClient.addMockResponse({
  206. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/grouping-info/`,
  207. body: {},
  208. });
  209. MockApiClient.addMockResponse({
  210. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  211. body: [],
  212. });
  213. MockApiClient.addMockResponse({
  214. url: `/organizations/${organization.slug}/code-mappings/`,
  215. method: 'GET',
  216. body: [],
  217. });
  218. MockApiClient.addMockResponse({
  219. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/actionable-items/`,
  220. body: {
  221. errors: [],
  222. },
  223. });
  224. // Sentry related mocks
  225. MockApiClient.addMockResponse({
  226. url: '/sentry-apps/',
  227. body: [],
  228. });
  229. MockApiClient.addMockResponse({
  230. url: `/organizations/${organization.slug}/sentry-apps/`,
  231. body: [],
  232. });
  233. MockApiClient.addMockResponse({
  234. url: `/organizations/${organization.slug}/sentry-app-installations/`,
  235. body: [],
  236. });
  237. MockApiClient.addMockResponse({
  238. url: `/organizations/${organization.slug}/sentry-app-components/?projectId=${project.id}`,
  239. body: [],
  240. });
  241. MockApiClient.addMockResponse({
  242. url: '/projects/org-slug/project-slug/',
  243. body: project,
  244. });
  245. MockApiClient.addMockResponse({
  246. url: '/organizations/org-slug/users/',
  247. body: [],
  248. });
  249. MockApiClient.addMockResponse({
  250. url: '/organizations/org-slug/projects/',
  251. body: [project],
  252. });
  253. MockApiClient.addMockResponse({
  254. url: `/customers/org-slug/policies/`,
  255. body: {},
  256. });
  257. MockApiClient.addMockResponse({
  258. url: `/organizations/${organization.slug}/issues/${group.id}/first-last-release/`,
  259. method: 'GET',
  260. });
  261. };
  262. describe('groupEventDetails', () => {
  263. beforeEach(() => {
  264. MockApiClient.clearMockResponses();
  265. });
  266. afterEach(function () {
  267. MockApiClient.clearMockResponses();
  268. (browserHistory.replace as jest.Mock).mockClear();
  269. });
  270. it('redirects on switching to an invalid environment selection for event', async function () {
  271. const props = makeDefaultMockData();
  272. mockGroupApis(props.organization, props.project, props.group, props.event);
  273. const {rerender} = render(<TestComponent {...props} />, {
  274. organization: props.organization,
  275. });
  276. expect(browserHistory.replace).not.toHaveBeenCalled();
  277. rerender(<TestComponent environments={['prod']} />);
  278. await waitFor(() => expect(browserHistory.replace).toHaveBeenCalled());
  279. });
  280. it('does not redirect when switching to a valid environment selection for event', async function () {
  281. const props = makeDefaultMockData();
  282. mockGroupApis(props.organization, props.project, props.group, props.event);
  283. const {rerender} = render(<TestComponent {...props} />, {
  284. organization: props.organization,
  285. });
  286. expect(browserHistory.replace).not.toHaveBeenCalled();
  287. rerender(<TestComponent environments={[]} />);
  288. expect(await screen.findByTestId('group-event-details')).toBeInTheDocument();
  289. expect(browserHistory.replace).not.toHaveBeenCalled();
  290. });
  291. it('displays error on event error', async function () {
  292. const props = makeDefaultMockData();
  293. mockGroupApis(
  294. props.organization,
  295. props.project,
  296. props.group,
  297. TestStubs.Event({
  298. size: 1,
  299. dateCreated: '2019-03-20T00:00:00.000Z',
  300. errors: [],
  301. entries: [],
  302. tags: [{key: 'environment', value: 'dev'}],
  303. previousEventID: 'prev-event-id',
  304. nextEventID: 'next-event-id',
  305. })
  306. );
  307. render(<TestComponent event={undefined} eventError />, {
  308. organization: props.organization,
  309. });
  310. expect(
  311. await screen.findByText(/events for this issue could not be found/)
  312. ).toBeInTheDocument();
  313. });
  314. it('renders the Span Evidence and Resources section for Performance Issues', async function () {
  315. const props = makeDefaultMockData();
  316. const group: Group = TestStubs.Group({
  317. issueCategory: IssueCategory.PERFORMANCE,
  318. issueType: IssueType.PERFORMANCE_N_PLUS_ONE_DB_QUERIES,
  319. });
  320. const transaction = TestStubs.Event({
  321. entries: [{type: EntryType.SPANS, data: []}],
  322. });
  323. mockGroupApis(
  324. props.organization,
  325. props.project,
  326. props.group,
  327. TestStubs.Event({
  328. size: 1,
  329. dateCreated: '2019-03-20T00:00:00.000Z',
  330. errors: [],
  331. entries: [],
  332. tags: [{key: 'environment', value: 'dev'}],
  333. previousEventID: 'prev-event-id',
  334. nextEventID: 'next-event-id',
  335. })
  336. );
  337. const routerContext = TestStubs.routerContext();
  338. render(<TestComponent group={group} event={transaction} />, {
  339. organization: props.organization,
  340. context: routerContext,
  341. });
  342. expect(
  343. await screen.findByRole('heading', {
  344. name: /span evidence/i,
  345. })
  346. ).toBeInTheDocument();
  347. expect(
  348. screen.getByRole('heading', {
  349. name: /resources/i,
  350. })
  351. ).toBeInTheDocument();
  352. });
  353. it('renders the Function Evidence and Resources section for Profile Issues', async function () {
  354. const props = makeDefaultMockData();
  355. const group: Group = TestStubs.Group({
  356. issueCategory: IssueCategory.PERFORMANCE,
  357. issueType: IssueType.PROFILE_FILE_IO_MAIN_THREAD,
  358. });
  359. const transaction = TestStubs.Event({
  360. entries: [],
  361. occurrence: {
  362. evidenceDisplay: [],
  363. evidenceData: {
  364. templateName: 'profile',
  365. },
  366. type: 2001,
  367. },
  368. });
  369. mockGroupApis(
  370. props.organization,
  371. props.project,
  372. props.group,
  373. TestStubs.Event({
  374. size: 1,
  375. dateCreated: '2019-03-20T00:00:00.000Z',
  376. errors: [],
  377. entries: [],
  378. tags: [{key: 'environment', value: 'dev'}],
  379. previousEventID: 'prev-event-id',
  380. nextEventID: 'next-event-id',
  381. })
  382. );
  383. const routerContext = TestStubs.routerContext();
  384. render(<TestComponent group={group} event={transaction} />, {
  385. organization: props.organization,
  386. context: routerContext,
  387. });
  388. expect(
  389. await screen.findByRole('heading', {
  390. name: /function evidence/i,
  391. })
  392. ).toBeInTheDocument();
  393. expect(
  394. screen.getByRole('heading', {
  395. name: /resources/i,
  396. })
  397. ).toBeInTheDocument();
  398. });
  399. });
  400. describe('EventCause', () => {
  401. beforeEach(() => {
  402. MockApiClient.clearMockResponses();
  403. });
  404. afterEach(function () {
  405. MockApiClient.clearMockResponses();
  406. (browserHistory.replace as jest.Mock).mockClear();
  407. });
  408. it('renders suspect commit', async function () {
  409. const props = makeDefaultMockData(
  410. undefined,
  411. TestStubs.Project({firstEvent: TestStubs.Event()})
  412. );
  413. mockGroupApis(
  414. props.organization,
  415. props.project,
  416. props.group,
  417. TestStubs.Event({
  418. size: 1,
  419. dateCreated: '2019-03-20T00:00:00.000Z',
  420. errors: [],
  421. entries: [],
  422. tags: [{key: 'environment', value: 'dev'}],
  423. previousEventID: 'prev-event-id',
  424. nextEventID: 'next-event-id',
  425. })
  426. );
  427. MockApiClient.addMockResponse({
  428. url: `/projects/${props.organization.slug}/${props.project.slug}/events/${props.event.id}/committers/`,
  429. body: {
  430. committers: [
  431. {
  432. commits: [Commit({author: CommitAuthor()})],
  433. author: CommitAuthor(),
  434. },
  435. ],
  436. },
  437. });
  438. render(<TestComponent project={props.project} />, {organization: props.organization});
  439. expect(await screen.findByTestId(/event-cause/)).toBeInTheDocument();
  440. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.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. TestStubs.Event({
  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. });