groupEventDetails.spec.tsx 15 KB

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