groupEventDetails.spec.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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 ? [trace] : [],
  177. });
  178. MockApiClient.addMockResponse({
  179. url: `/organizations/${organization.slug}/events-trace-light/${TRACE_ID}/`,
  180. body: trace ? [trace] : [],
  181. });
  182. MockApiClient.addMockResponse({
  183. url: `/organizations/${organization.slug}/issues/${group.id}/integrations/`,
  184. body: [],
  185. });
  186. MockApiClient.addMockResponse({
  187. url: `/organizations/${organization.slug}/issues/${group.id}/external-issues/`,
  188. });
  189. MockApiClient.addMockResponse({
  190. url: `/organizations/${organization.slug}/issues/${group.id}/current-release/`,
  191. body: {currentRelease: null},
  192. });
  193. MockApiClient.addMockResponse({
  194. url: '/prompts-activity/',
  195. body: undefined,
  196. });
  197. MockApiClient.addMockResponse({
  198. url: `/organizations/${organization.slug}/has-mobile-app-events/`,
  199. body: null,
  200. });
  201. MockApiClient.addMockResponse({
  202. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/grouping-info/`,
  203. body: {},
  204. });
  205. MockApiClient.addMockResponse({
  206. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  207. body: [],
  208. });
  209. MockApiClient.addMockResponse({
  210. url: `/organizations/${organization.slug}/code-mappings/`,
  211. method: 'GET',
  212. body: [],
  213. });
  214. MockApiClient.addMockResponse({
  215. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/actionable-items/`,
  216. body: {
  217. errors: [],
  218. },
  219. });
  220. // Sentry related mocks
  221. MockApiClient.addMockResponse({
  222. url: '/sentry-apps/',
  223. body: [],
  224. });
  225. MockApiClient.addMockResponse({
  226. url: `/organizations/${organization.slug}/sentry-apps/`,
  227. body: [],
  228. });
  229. MockApiClient.addMockResponse({
  230. url: `/organizations/${organization.slug}/sentry-app-installations/`,
  231. body: [],
  232. });
  233. MockApiClient.addMockResponse({
  234. url: `/organizations/${organization.slug}/sentry-app-components/?projectId=${project.id}`,
  235. body: [],
  236. });
  237. MockApiClient.addMockResponse({
  238. url: '/projects/org-slug/project-slug/',
  239. body: project,
  240. });
  241. MockApiClient.addMockResponse({
  242. url: '/organizations/org-slug/users/',
  243. body: [],
  244. });
  245. MockApiClient.addMockResponse({
  246. url: '/organizations/org-slug/projects/',
  247. body: [project],
  248. });
  249. MockApiClient.addMockResponse({
  250. url: `/customers/org-slug/policies/`,
  251. body: {},
  252. });
  253. MockApiClient.addMockResponse({
  254. url: `/organizations/${organization.slug}/issues/${group.id}/first-last-release/`,
  255. method: 'GET',
  256. });
  257. };
  258. describe('groupEventDetails', () => {
  259. beforeEach(() => {
  260. MockApiClient.clearMockResponses();
  261. });
  262. afterEach(function () {
  263. MockApiClient.clearMockResponses();
  264. (browserHistory.replace as jest.Mock).mockClear();
  265. });
  266. it('redirects on switching to an invalid environment selection for event', async function () {
  267. const props = makeDefaultMockData();
  268. mockGroupApis(props.organization, props.project, props.group, props.event);
  269. const {rerender} = render(<TestComponent {...props} />, {
  270. organization: props.organization,
  271. });
  272. expect(browserHistory.replace).not.toHaveBeenCalled();
  273. rerender(<TestComponent environments={['prod']} />);
  274. await waitFor(() => expect(browserHistory.replace).toHaveBeenCalled());
  275. });
  276. it('does not redirect when switching to a valid 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={[]} />);
  284. expect(await screen.findByTestId('group-event-details')).toBeInTheDocument();
  285. expect(browserHistory.replace).not.toHaveBeenCalled();
  286. });
  287. it('displays error on event error', async function () {
  288. const props = makeDefaultMockData();
  289. mockGroupApis(
  290. props.organization,
  291. props.project,
  292. props.group,
  293. TestStubs.Event({
  294. size: 1,
  295. dateCreated: '2019-03-20T00:00:00.000Z',
  296. errors: [],
  297. entries: [],
  298. tags: [{key: 'environment', value: 'dev'}],
  299. previousEventID: 'prev-event-id',
  300. nextEventID: 'next-event-id',
  301. })
  302. );
  303. render(<TestComponent event={undefined} eventError />, {
  304. organization: props.organization,
  305. });
  306. expect(
  307. await screen.findByText(/events for this issue could not be found/)
  308. ).toBeInTheDocument();
  309. });
  310. it('renders the Span Evidence and Resources section for Performance Issues', async function () {
  311. const props = makeDefaultMockData();
  312. const group: Group = TestStubs.Group({
  313. issueCategory: IssueCategory.PERFORMANCE,
  314. issueType: IssueType.PERFORMANCE_N_PLUS_ONE_DB_QUERIES,
  315. });
  316. const transaction = TestStubs.Event({
  317. entries: [{type: EntryType.SPANS, data: []}],
  318. });
  319. mockGroupApis(
  320. props.organization,
  321. props.project,
  322. props.group,
  323. TestStubs.Event({
  324. size: 1,
  325. dateCreated: '2019-03-20T00:00:00.000Z',
  326. errors: [],
  327. entries: [],
  328. tags: [{key: 'environment', value: 'dev'}],
  329. previousEventID: 'prev-event-id',
  330. nextEventID: 'next-event-id',
  331. })
  332. );
  333. const routerContext = TestStubs.routerContext();
  334. render(<TestComponent group={group} event={transaction} />, {
  335. organization: props.organization,
  336. context: routerContext,
  337. });
  338. expect(
  339. await screen.findByRole('heading', {
  340. name: /span evidence/i,
  341. })
  342. ).toBeInTheDocument();
  343. expect(
  344. screen.getByRole('heading', {
  345. name: /resources/i,
  346. })
  347. ).toBeInTheDocument();
  348. });
  349. it('renders the Function Evidence and Resources section for Profile Issues', async function () {
  350. const props = makeDefaultMockData();
  351. const group: Group = TestStubs.Group({
  352. issueCategory: IssueCategory.PERFORMANCE,
  353. issueType: IssueType.PROFILE_FILE_IO_MAIN_THREAD,
  354. });
  355. const transaction = TestStubs.Event({
  356. entries: [],
  357. occurrence: {
  358. evidenceDisplay: [],
  359. evidenceData: {
  360. templateName: 'profile',
  361. },
  362. type: 2001,
  363. },
  364. });
  365. mockGroupApis(
  366. props.organization,
  367. props.project,
  368. props.group,
  369. TestStubs.Event({
  370. size: 1,
  371. dateCreated: '2019-03-20T00:00:00.000Z',
  372. errors: [],
  373. entries: [],
  374. tags: [{key: 'environment', value: 'dev'}],
  375. previousEventID: 'prev-event-id',
  376. nextEventID: 'next-event-id',
  377. })
  378. );
  379. const routerContext = TestStubs.routerContext();
  380. render(<TestComponent group={group} event={transaction} />, {
  381. organization: props.organization,
  382. context: routerContext,
  383. });
  384. expect(
  385. await screen.findByRole('heading', {
  386. name: /function evidence/i,
  387. })
  388. ).toBeInTheDocument();
  389. expect(
  390. screen.getByRole('heading', {
  391. name: /resources/i,
  392. })
  393. ).toBeInTheDocument();
  394. });
  395. });
  396. describe('EventCause', () => {
  397. beforeEach(() => {
  398. MockApiClient.clearMockResponses();
  399. });
  400. afterEach(function () {
  401. MockApiClient.clearMockResponses();
  402. (browserHistory.replace as jest.Mock).mockClear();
  403. });
  404. it('renders suspect commit', async function () {
  405. const props = makeDefaultMockData(
  406. undefined,
  407. TestStubs.Project({firstEvent: TestStubs.Event()})
  408. );
  409. mockGroupApis(
  410. props.organization,
  411. props.project,
  412. props.group,
  413. TestStubs.Event({
  414. size: 1,
  415. dateCreated: '2019-03-20T00:00:00.000Z',
  416. errors: [],
  417. entries: [],
  418. tags: [{key: 'environment', value: 'dev'}],
  419. previousEventID: 'prev-event-id',
  420. nextEventID: 'next-event-id',
  421. })
  422. );
  423. MockApiClient.addMockResponse({
  424. url: `/projects/${props.organization.slug}/${props.project.slug}/events/${props.event.id}/committers/`,
  425. body: {
  426. committers: [
  427. {
  428. commits: [Commit({author: CommitAuthor()})],
  429. author: CommitAuthor(),
  430. },
  431. ],
  432. },
  433. });
  434. render(<TestComponent project={props.project} />, {organization: props.organization});
  435. expect(await screen.findByTestId(/event-cause/)).toBeInTheDocument();
  436. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  437. });
  438. });
  439. describe('Platform Integrations', () => {
  440. let componentsRequest;
  441. beforeEach(() => {
  442. MockApiClient.clearMockResponses();
  443. });
  444. it('loads Integration UI components', async () => {
  445. const props = makeDefaultMockData();
  446. const unpublishedIntegration = SentryApp({status: 'unpublished'});
  447. const internalIntegration = SentryApp({status: 'internal'});
  448. const unpublishedInstall = TestStubs.SentryAppInstallation({
  449. app: {
  450. slug: unpublishedIntegration.slug,
  451. uuid: unpublishedIntegration.uuid,
  452. },
  453. });
  454. const internalInstall = TestStubs.SentryAppInstallation({
  455. app: {
  456. slug: internalIntegration.slug,
  457. uuid: internalIntegration.uuid,
  458. },
  459. });
  460. mockGroupApis(
  461. props.organization,
  462. props.project,
  463. props.group,
  464. TestStubs.Event({
  465. size: 1,
  466. dateCreated: '2019-03-20T00:00:00.000Z',
  467. errors: [],
  468. entries: [],
  469. tags: [{key: 'environment', value: 'dev'}],
  470. previousEventID: 'prev-event-id',
  471. nextEventID: 'next-event-id',
  472. })
  473. );
  474. const component = SentryAppComponent({
  475. sentryApp: {
  476. uuid: unpublishedIntegration.uuid,
  477. slug: unpublishedIntegration.slug,
  478. name: unpublishedIntegration.name,
  479. },
  480. });
  481. MockApiClient.addMockResponse({
  482. url: `/organizations/${props.organization.slug}/sentry-app-installations/`,
  483. body: [unpublishedInstall, internalInstall],
  484. });
  485. componentsRequest = MockApiClient.addMockResponse({
  486. url: `/organizations/${props.organization.slug}/sentry-app-components/?projectId=${props.project.id}`,
  487. body: [component],
  488. });
  489. render(<TestComponent />, {organization: props.organization});
  490. expect(await screen.findByText('Sample App Issue')).toBeInTheDocument();
  491. expect(componentsRequest).toHaveBeenCalled();
  492. });
  493. describe('ANR Root Cause', () => {
  494. beforeEach(() => {
  495. MockApiClient.clearMockResponses();
  496. });
  497. it('shows anr root cause', async () => {
  498. const {organization} = initializeOrg();
  499. const props = makeDefaultMockData({
  500. ...organization,
  501. features: ['anr-improvements'],
  502. });
  503. mockGroupApis(
  504. props.organization,
  505. props.project,
  506. props.group,
  507. props.event,
  508. mockedTrace(props.project)
  509. );
  510. const routerContext = TestStubs.routerContext();
  511. render(<TestComponent group={props.group} event={props.event} />, {
  512. organization: props.organization,
  513. context: routerContext,
  514. });
  515. expect(
  516. await screen.findByRole('heading', {
  517. name: /suspect root cause/i,
  518. })
  519. ).toBeInTheDocument();
  520. expect(screen.getByText('File IO on Main Thread')).toBeInTheDocument();
  521. });
  522. it('does not render root issues section if related perf issues do not exist', async () => {
  523. const {organization} = initializeOrg();
  524. const props = makeDefaultMockData({
  525. ...organization,
  526. features: ['anr-improvements'],
  527. });
  528. const trace = mockedTrace(props.project);
  529. mockGroupApis(props.organization, props.project, props.group, props.event, {
  530. ...trace,
  531. performance_issues: [],
  532. });
  533. const routerContext = TestStubs.routerContext();
  534. render(<TestComponent group={props.group} event={props.event} />, {
  535. organization: props.organization,
  536. context: routerContext,
  537. });
  538. // mechanism: ANR
  539. expect(await screen.findByText('ANR')).toBeInTheDocument();
  540. expect(
  541. screen.queryByRole('heading', {
  542. name: /suspect root issues/i,
  543. })
  544. ).not.toBeInTheDocument();
  545. expect(screen.queryByText('File IO on Main Thread')).not.toBeInTheDocument();
  546. });
  547. });
  548. });