groupEventDetails.spec.tsx 17 KB

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