groupEventDetails.spec.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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('displays error on event error', 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. render(<TestComponent event={undefined} eventError />, {
  199. organization: props.organization,
  200. });
  201. expect(
  202. await screen.findByText(/events for this issue could not be found/)
  203. ).toBeInTheDocument();
  204. });
  205. it('renders the Span Evidence and Resources section for Performance Issues', async function () {
  206. const props = makeDefaultMockData();
  207. const group: Group = TestStubs.Group({
  208. issueCategory: IssueCategory.PERFORMANCE,
  209. issueType: IssueType.PERFORMANCE_N_PLUS_ONE_DB_QUERIES,
  210. });
  211. const transaction = TestStubs.Event({
  212. entries: [{type: EntryType.SPANS, data: []}],
  213. });
  214. mockGroupApis(
  215. props.organization,
  216. props.project,
  217. props.group,
  218. TestStubs.Event({
  219. size: 1,
  220. dateCreated: '2019-03-20T00:00:00.000Z',
  221. errors: [],
  222. entries: [],
  223. tags: [{key: 'environment', value: 'dev'}],
  224. previousEventID: 'prev-event-id',
  225. nextEventID: 'next-event-id',
  226. })
  227. );
  228. const routerContext = TestStubs.routerContext();
  229. await act(async () => {
  230. render(<TestComponent group={group} event={transaction} />, {
  231. organization: props.organization,
  232. context: routerContext,
  233. });
  234. await tick();
  235. });
  236. expect(
  237. screen.getByRole('heading', {
  238. name: /span evidence/i,
  239. })
  240. ).toBeInTheDocument();
  241. expect(
  242. screen.getByRole('heading', {
  243. name: /resources/i,
  244. })
  245. ).toBeInTheDocument();
  246. });
  247. it('renders the Function Evidence and Resources section for Profile Issues', async function () {
  248. const props = makeDefaultMockData();
  249. const group: Group = TestStubs.Group({
  250. issueCategory: IssueCategory.PROFILE,
  251. issueType: IssueType.PROFILE_FILE_IO_MAIN_THREAD,
  252. });
  253. const transaction = TestStubs.Event({
  254. entries: [],
  255. occurrence: {
  256. evidenceDisplay: [],
  257. evidenceData: {},
  258. type: 2000,
  259. },
  260. });
  261. mockGroupApis(
  262. props.organization,
  263. props.project,
  264. props.group,
  265. TestStubs.Event({
  266. size: 1,
  267. dateCreated: '2019-03-20T00:00:00.000Z',
  268. errors: [],
  269. entries: [],
  270. tags: [{key: 'environment', value: 'dev'}],
  271. previousEventID: 'prev-event-id',
  272. nextEventID: 'next-event-id',
  273. })
  274. );
  275. const routerContext = TestStubs.routerContext();
  276. await act(async () => {
  277. render(<TestComponent group={group} event={transaction} />, {
  278. organization: props.organization,
  279. context: routerContext,
  280. });
  281. await tick();
  282. });
  283. expect(
  284. screen.getByRole('heading', {
  285. name: /function evidence/i,
  286. })
  287. ).toBeInTheDocument();
  288. expect(
  289. screen.getByRole('heading', {
  290. name: /resources/i,
  291. })
  292. ).toBeInTheDocument();
  293. });
  294. });
  295. describe('EventCause', () => {
  296. beforeEach(() => {
  297. MockApiClient.clearMockResponses();
  298. });
  299. afterEach(function () {
  300. MockApiClient.clearMockResponses();
  301. (browserHistory.replace as jest.Mock).mockClear();
  302. });
  303. it('renders suspect commit', async function () {
  304. const props = makeDefaultMockData(
  305. undefined,
  306. TestStubs.Project({firstEvent: TestStubs.Event()})
  307. );
  308. mockGroupApis(
  309. props.organization,
  310. props.project,
  311. props.group,
  312. TestStubs.Event({
  313. size: 1,
  314. dateCreated: '2019-03-20T00:00:00.000Z',
  315. errors: [],
  316. entries: [],
  317. tags: [{key: 'environment', value: 'dev'}],
  318. previousEventID: 'prev-event-id',
  319. nextEventID: 'next-event-id',
  320. })
  321. );
  322. MockApiClient.addMockResponse({
  323. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  324. body: [
  325. {
  326. step: 'commit',
  327. complete: true,
  328. },
  329. ],
  330. });
  331. MockApiClient.addMockResponse({
  332. url: `/projects/${props.organization.slug}/${props.project.slug}/events/${props.event.id}/committers/`,
  333. body: {
  334. committers: [
  335. {
  336. commits: [TestStubs.Commit({author: TestStubs.CommitAuthor()})],
  337. author: TestStubs.CommitAuthor(),
  338. },
  339. ],
  340. },
  341. });
  342. render(<TestComponent project={props.project} />, {organization: props.organization});
  343. expect(await screen.findByTestId(/event-cause/)).toBeInTheDocument();
  344. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  345. });
  346. it('renders suspect commit if `releasesCompletion` empty', async function () {
  347. const props = makeDefaultMockData(
  348. undefined,
  349. TestStubs.Project({firstEvent: TestStubs.Event()})
  350. );
  351. mockGroupApis(
  352. props.organization,
  353. props.project,
  354. props.group,
  355. TestStubs.Event({
  356. size: 1,
  357. dateCreated: '2019-03-20T00:00:00.000Z',
  358. errors: [],
  359. entries: [],
  360. tags: [{key: 'environment', value: 'dev'}],
  361. previousEventID: 'prev-event-id',
  362. nextEventID: 'next-event-id',
  363. })
  364. );
  365. MockApiClient.addMockResponse({
  366. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  367. body: [],
  368. });
  369. await act(async () => {
  370. render(<TestComponent project={props.project} />, {
  371. organization: props.organization,
  372. });
  373. await tick();
  374. });
  375. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  376. });
  377. });
  378. describe('Platform Integrations', () => {
  379. let componentsRequest;
  380. beforeEach(() => {
  381. MockApiClient.clearMockResponses();
  382. });
  383. it('loads Integration UI components', async () => {
  384. const props = makeDefaultMockData();
  385. const unpublishedIntegration = TestStubs.SentryApp({status: 'unpublished'});
  386. const internalIntegration = TestStubs.SentryApp({status: 'internal'});
  387. const unpublishedInstall = TestStubs.SentryAppInstallation({
  388. app: {
  389. slug: unpublishedIntegration.slug,
  390. uuid: unpublishedIntegration.uuid,
  391. },
  392. });
  393. const internalInstall = TestStubs.SentryAppInstallation({
  394. app: {
  395. slug: internalIntegration.slug,
  396. uuid: internalIntegration.uuid,
  397. },
  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. const component = TestStubs.SentryAppComponent({
  414. sentryApp: {
  415. uuid: unpublishedIntegration.uuid,
  416. slug: unpublishedIntegration.slug,
  417. name: unpublishedIntegration.name,
  418. },
  419. });
  420. MockApiClient.addMockResponse({
  421. url: `/organizations/${props.organization.slug}/sentry-app-installations/`,
  422. body: [unpublishedInstall, internalInstall],
  423. });
  424. componentsRequest = MockApiClient.addMockResponse({
  425. url: `/organizations/${props.organization.slug}/sentry-app-components/?projectId=${props.project.id}`,
  426. body: [component],
  427. });
  428. await act(async () => {
  429. render(<TestComponent />, {organization: props.organization});
  430. await tick();
  431. });
  432. expect(componentsRequest).toHaveBeenCalled();
  433. });
  434. });