groupEventDetails.spec.tsx 16 KB

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