groupEventDetails.spec.tsx 16 KB

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