groupEventDetails.spec.tsx 18 KB

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