groupEventDetails.spec.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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 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. CommitterStore.teardown();
  160. (browserHistory.replace as jest.Mock).mockClear();
  161. });
  162. it('redirects on switching to an invalid environment selection for event', async function () {
  163. const props = makeDefaultMockData();
  164. mockGroupApis(props.organization, props.project, props.group, props.event);
  165. const {rerender} = render(<TestComponent {...props} />, {
  166. organization: props.organization,
  167. });
  168. expect(browserHistory.replace).not.toHaveBeenCalled();
  169. rerender(
  170. <TestComponent environments={[{id: '1', name: 'prod', displayName: 'Prod'}]} />
  171. );
  172. await waitFor(() => expect(browserHistory.replace).toHaveBeenCalled());
  173. });
  174. it('does not redirect when switching to a valid environment selection for event', async function () {
  175. const props = makeDefaultMockData();
  176. mockGroupApis(props.organization, props.project, props.group, props.event);
  177. const {rerender} = render(<TestComponent {...props} />, {
  178. organization: props.organization,
  179. });
  180. expect(browserHistory.replace).not.toHaveBeenCalled();
  181. rerender(<TestComponent environments={[]} />);
  182. expect(await screen.findByTestId('group-event-details')).toBeInTheDocument();
  183. expect(browserHistory.replace).not.toHaveBeenCalled();
  184. });
  185. it('next/prev links', function () {
  186. const props = makeDefaultMockData();
  187. mockGroupApis(
  188. props.organization,
  189. props.project,
  190. props.group,
  191. TestStubs.Event({
  192. size: 1,
  193. dateCreated: '2019-03-20T00:00:00.000Z',
  194. errors: [],
  195. entries: [],
  196. tags: [{key: 'environment', value: 'dev'}],
  197. previousEventID: 'prev-event-id',
  198. nextEventID: 'next-event-id',
  199. })
  200. );
  201. MockApiClient.addMockResponse({
  202. url: `/projects/${props.organization.slug}/${props.project.slug}/events/1/`,
  203. body: event,
  204. });
  205. const routerContext = TestStubs.routerContext();
  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. 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. });
  245. describe('EventCauseEmpty', () => {
  246. beforeEach(() => {
  247. MockApiClient.clearMockResponses();
  248. CommitterStore.init();
  249. });
  250. afterEach(function () {
  251. MockApiClient.clearMockResponses();
  252. (browserHistory.replace as jest.Mock).mockClear();
  253. CommitterStore.teardown();
  254. });
  255. it('renders empty state', async function () {
  256. const props = makeDefaultMockData(
  257. undefined,
  258. TestStubs.Project({firstEvent: TestStubs.Event()})
  259. );
  260. mockGroupApis(
  261. props.organization,
  262. props.project,
  263. props.group,
  264. TestStubs.Event({
  265. size: 1,
  266. dateCreated: '2019-03-20T00:00:00.000Z',
  267. errors: [],
  268. entries: [],
  269. tags: [{key: 'environment', value: 'dev'}],
  270. previousEventID: 'prev-event-id',
  271. nextEventID: 'next-event-id',
  272. })
  273. );
  274. MockApiClient.addMockResponse({
  275. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  276. body: [
  277. {
  278. step: 'commit',
  279. complete: false,
  280. },
  281. ],
  282. });
  283. render(<TestComponent project={props.project} />, {organization: props.organization});
  284. expect(await screen.findByTestId(/loaded-event-cause-empty/)).toBeInTheDocument();
  285. expect(screen.queryByText(/event-cause/)).not.toBeInTheDocument();
  286. });
  287. it('renders suspect commit', async function () {
  288. const props = makeDefaultMockData(
  289. undefined,
  290. TestStubs.Project({firstEvent: TestStubs.Event()})
  291. );
  292. mockGroupApis(
  293. props.organization,
  294. props.project,
  295. props.group,
  296. TestStubs.Event({
  297. size: 1,
  298. dateCreated: '2019-03-20T00:00:00.000Z',
  299. errors: [],
  300. entries: [],
  301. tags: [{key: 'environment', value: 'dev'}],
  302. previousEventID: 'prev-event-id',
  303. nextEventID: 'next-event-id',
  304. })
  305. );
  306. MockApiClient.addMockResponse({
  307. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  308. body: [
  309. {
  310. step: 'commit',
  311. complete: true,
  312. },
  313. ],
  314. });
  315. CommitterStore.loadSuccess(
  316. props.organization.slug,
  317. props.project.slug,
  318. props.event.id,
  319. [
  320. {
  321. commits: [TestStubs.Commit({author: TestStubs.CommitAuthor()})],
  322. author: TestStubs.CommitAuthor(),
  323. },
  324. ]
  325. );
  326. render(<TestComponent project={props.project} />, {organization: props.organization});
  327. expect(await screen.findByTestId(/event-cause/)).toBeInTheDocument();
  328. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  329. });
  330. it('renders suspect commit if `releasesCompletion` empty', function () {
  331. const props = makeDefaultMockData(
  332. undefined,
  333. TestStubs.Project({firstEvent: TestStubs.Event()})
  334. );
  335. mockGroupApis(
  336. props.organization,
  337. props.project,
  338. props.group,
  339. TestStubs.Event({
  340. size: 1,
  341. dateCreated: '2019-03-20T00:00:00.000Z',
  342. errors: [],
  343. entries: [],
  344. tags: [{key: 'environment', value: 'dev'}],
  345. previousEventID: 'prev-event-id',
  346. nextEventID: 'next-event-id',
  347. })
  348. );
  349. MockApiClient.addMockResponse({
  350. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  351. body: [],
  352. });
  353. render(<TestComponent project={props.project} />, {organization: props.organization});
  354. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  355. });
  356. });
  357. describe('Platform Integrations', () => {
  358. let componentsRequest;
  359. beforeEach(() => {
  360. MockApiClient.clearMockResponses();
  361. });
  362. it('loads Integration UI components', () => {
  363. const props = makeDefaultMockData();
  364. const unpublishedIntegration = TestStubs.SentryApp({status: 'unpublished'});
  365. const internalIntegration = TestStubs.SentryApp({status: 'internal'});
  366. const unpublishedInstall = TestStubs.SentryAppInstallation({
  367. app: {
  368. slug: unpublishedIntegration.slug,
  369. uuid: unpublishedIntegration.uuid,
  370. },
  371. });
  372. const internalInstall = TestStubs.SentryAppInstallation({
  373. app: {
  374. slug: internalIntegration.slug,
  375. uuid: internalIntegration.uuid,
  376. },
  377. });
  378. mockGroupApis(
  379. props.organization,
  380. props.project,
  381. props.group,
  382. TestStubs.Event({
  383. size: 1,
  384. dateCreated: '2019-03-20T00:00:00.000Z',
  385. errors: [],
  386. entries: [],
  387. tags: [{key: 'environment', value: 'dev'}],
  388. previousEventID: 'prev-event-id',
  389. nextEventID: 'next-event-id',
  390. })
  391. );
  392. const component = TestStubs.SentryAppComponent({
  393. sentryApp: {
  394. uuid: unpublishedIntegration.uuid,
  395. slug: unpublishedIntegration.slug,
  396. name: unpublishedIntegration.name,
  397. },
  398. });
  399. MockApiClient.addMockResponse({
  400. url: `/organizations/${props.organization.slug}/sentry-app-installations/`,
  401. body: [unpublishedInstall, internalInstall],
  402. });
  403. componentsRequest = MockApiClient.addMockResponse({
  404. url: `/organizations/${props.organization.slug}/sentry-app-components/?projectId=${props.project.id}`,
  405. body: [component],
  406. });
  407. render(<TestComponent />, {organization: props.organization});
  408. expect(componentsRequest).toHaveBeenCalled();
  409. });
  410. });