groupEventDetails.spec.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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('EventCause', () => {
  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 suspect commit', 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: true,
  281. },
  282. ],
  283. });
  284. CommitterStore.loadSuccess(
  285. props.organization.slug,
  286. props.project.slug,
  287. props.event.id,
  288. [
  289. {
  290. commits: [TestStubs.Commit({author: TestStubs.CommitAuthor()})],
  291. author: TestStubs.CommitAuthor(),
  292. },
  293. ]
  294. );
  295. render(<TestComponent project={props.project} />, {organization: props.organization});
  296. expect(await screen.findByTestId(/event-cause/)).toBeInTheDocument();
  297. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  298. });
  299. it('renders suspect commit if `releasesCompletion` empty', async function () {
  300. const props = makeDefaultMockData(
  301. undefined,
  302. TestStubs.Project({firstEvent: TestStubs.Event()})
  303. );
  304. mockGroupApis(
  305. props.organization,
  306. props.project,
  307. props.group,
  308. TestStubs.Event({
  309. size: 1,
  310. dateCreated: '2019-03-20T00:00:00.000Z',
  311. errors: [],
  312. entries: [],
  313. tags: [{key: 'environment', value: 'dev'}],
  314. previousEventID: 'prev-event-id',
  315. nextEventID: 'next-event-id',
  316. })
  317. );
  318. MockApiClient.addMockResponse({
  319. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  320. body: [],
  321. });
  322. await act(async () => {
  323. render(<TestComponent project={props.project} />, {
  324. organization: props.organization,
  325. });
  326. await tick();
  327. });
  328. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  329. });
  330. });
  331. describe('Platform Integrations', () => {
  332. let componentsRequest;
  333. beforeEach(() => {
  334. MockApiClient.clearMockResponses();
  335. });
  336. it('loads Integration UI components', async () => {
  337. const props = makeDefaultMockData();
  338. const unpublishedIntegration = TestStubs.SentryApp({status: 'unpublished'});
  339. const internalIntegration = TestStubs.SentryApp({status: 'internal'});
  340. const unpublishedInstall = TestStubs.SentryAppInstallation({
  341. app: {
  342. slug: unpublishedIntegration.slug,
  343. uuid: unpublishedIntegration.uuid,
  344. },
  345. });
  346. const internalInstall = TestStubs.SentryAppInstallation({
  347. app: {
  348. slug: internalIntegration.slug,
  349. uuid: internalIntegration.uuid,
  350. },
  351. });
  352. mockGroupApis(
  353. props.organization,
  354. props.project,
  355. props.group,
  356. TestStubs.Event({
  357. size: 1,
  358. dateCreated: '2019-03-20T00:00:00.000Z',
  359. errors: [],
  360. entries: [],
  361. tags: [{key: 'environment', value: 'dev'}],
  362. previousEventID: 'prev-event-id',
  363. nextEventID: 'next-event-id',
  364. })
  365. );
  366. const component = TestStubs.SentryAppComponent({
  367. sentryApp: {
  368. uuid: unpublishedIntegration.uuid,
  369. slug: unpublishedIntegration.slug,
  370. name: unpublishedIntegration.name,
  371. },
  372. });
  373. MockApiClient.addMockResponse({
  374. url: `/organizations/${props.organization.slug}/sentry-app-installations/`,
  375. body: [unpublishedInstall, internalInstall],
  376. });
  377. componentsRequest = MockApiClient.addMockResponse({
  378. url: `/organizations/${props.organization.slug}/sentry-app-components/?projectId=${props.project.id}`,
  379. body: [component],
  380. });
  381. await act(async () => {
  382. render(<TestComponent />, {organization: props.organization});
  383. await tick();
  384. });
  385. expect(componentsRequest).toHaveBeenCalled();
  386. });
  387. });