groupEventDetails.spec.tsx 18 KB

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