groupEventDetails.spec.tsx 13 KB

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