groupEventDetails.spec.tsx 17 KB

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