groupEventDetails.spec.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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}/tags/`,
  92. body: [],
  93. });
  94. MockApiClient.addMockResponse({
  95. url: `/groups/${group.id}/integrations/`,
  96. body: [],
  97. });
  98. MockApiClient.addMockResponse({
  99. url: `/groups/${group.id}/external-issues/`,
  100. });
  101. MockApiClient.addMockResponse({
  102. url: `/issues/${group.id}/current-release/`,
  103. body: {currentRelease: null},
  104. });
  105. MockApiClient.addMockResponse({
  106. url: '/prompts-activity/',
  107. body: undefined,
  108. });
  109. MockApiClient.addMockResponse({
  110. url: `/organizations/${organization.slug}/has-mobile-app-events/`,
  111. body: null,
  112. });
  113. MockApiClient.addMockResponse({
  114. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/grouping-info/`,
  115. body: {},
  116. });
  117. MockApiClient.addMockResponse({
  118. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  119. body: [],
  120. });
  121. MockApiClient.addMockResponse({
  122. url: `/organizations/${organization.slug}/code-mappings/`,
  123. method: 'GET',
  124. body: [],
  125. });
  126. // Sentry related mocks
  127. MockApiClient.addMockResponse({
  128. url: '/sentry-apps/',
  129. body: [],
  130. });
  131. MockApiClient.addMockResponse({
  132. url: `/organizations/${organization.slug}/sentry-apps/`,
  133. body: [],
  134. });
  135. MockApiClient.addMockResponse({
  136. url: `/organizations/${organization.slug}/sentry-app-installations/`,
  137. body: [],
  138. });
  139. MockApiClient.addMockResponse({
  140. url: `/organizations/${organization.slug}/sentry-app-components/?projectId=${project.id}`,
  141. body: [],
  142. });
  143. MockApiClient.addMockResponse({
  144. url: '/projects/org-slug/project-slug/',
  145. body: project,
  146. });
  147. };
  148. describe('groupEventDetails', () => {
  149. beforeEach(() => {
  150. MockApiClient.clearMockResponses();
  151. CommitterStore.init();
  152. });
  153. afterEach(function () {
  154. MockApiClient.clearMockResponses();
  155. (browserHistory.replace as jest.Mock).mockClear();
  156. });
  157. it('redirects on switching to an invalid environment selection for event', async function () {
  158. const props = makeDefaultMockData();
  159. mockGroupApis(props.organization, props.project, props.group, props.event);
  160. const {rerender} = render(<TestComponent {...props} />, {
  161. organization: props.organization,
  162. });
  163. expect(browserHistory.replace).not.toHaveBeenCalled();
  164. rerender(
  165. <TestComponent environments={[{id: '1', name: 'prod', displayName: 'Prod'}]} />
  166. );
  167. await waitFor(() => expect(browserHistory.replace).toHaveBeenCalled());
  168. });
  169. it('does not redirect when switching to a valid environment selection for event', async function () {
  170. const props = makeDefaultMockData();
  171. mockGroupApis(props.organization, props.project, props.group, props.event);
  172. const {rerender} = render(<TestComponent {...props} />, {
  173. organization: props.organization,
  174. });
  175. expect(browserHistory.replace).not.toHaveBeenCalled();
  176. rerender(<TestComponent environments={[]} />);
  177. expect(await screen.findByTestId('group-event-details')).toBeInTheDocument();
  178. expect(browserHistory.replace).not.toHaveBeenCalled();
  179. });
  180. it('next/prev links', async function () {
  181. const props = makeDefaultMockData();
  182. mockGroupApis(
  183. props.organization,
  184. props.project,
  185. props.group,
  186. TestStubs.Event({
  187. size: 1,
  188. dateCreated: '2019-03-20T00:00:00.000Z',
  189. errors: [],
  190. entries: [],
  191. tags: [{key: 'environment', value: 'dev'}],
  192. previousEventID: 'prev-event-id',
  193. nextEventID: 'next-event-id',
  194. })
  195. );
  196. MockApiClient.addMockResponse({
  197. url: `/projects/${props.organization.slug}/${props.project.slug}/events/1/`,
  198. body: event,
  199. });
  200. const routerContext = TestStubs.routerContext();
  201. await act(async () => {
  202. render(
  203. <TestComponent
  204. {...props}
  205. location={{query: {environment: 'dev'}} as Location<any>}
  206. />,
  207. {
  208. context: routerContext,
  209. organization: props.organization,
  210. }
  211. );
  212. await tick();
  213. });
  214. expect(screen.getByLabelText(/Oldest/)).toBeInTheDocument();
  215. expect(screen.getByLabelText(/Older/)).toBeInTheDocument();
  216. expect(screen.getByLabelText(/Newer/)).toBeInTheDocument();
  217. expect(screen.getByLabelText(/Newest/)).toBeInTheDocument();
  218. });
  219. it('displays error on event error', async function () {
  220. const props = makeDefaultMockData();
  221. mockGroupApis(
  222. props.organization,
  223. props.project,
  224. props.group,
  225. TestStubs.Event({
  226. size: 1,
  227. dateCreated: '2019-03-20T00:00:00.000Z',
  228. errors: [],
  229. entries: [],
  230. tags: [{key: 'environment', value: 'dev'}],
  231. previousEventID: 'prev-event-id',
  232. nextEventID: 'next-event-id',
  233. })
  234. );
  235. render(<TestComponent event={undefined} eventError />, {
  236. organization: props.organization,
  237. });
  238. expect(
  239. await screen.findByText(/events for this issue could not be found/)
  240. ).toBeInTheDocument();
  241. });
  242. });
  243. describe('EventCause', () => {
  244. beforeEach(() => {
  245. MockApiClient.clearMockResponses();
  246. CommitterStore.init();
  247. });
  248. afterEach(function () {
  249. MockApiClient.clearMockResponses();
  250. (browserHistory.replace as jest.Mock).mockClear();
  251. });
  252. it('renders suspect commit', async function () {
  253. const props = makeDefaultMockData(
  254. undefined,
  255. TestStubs.Project({firstEvent: TestStubs.Event()})
  256. );
  257. mockGroupApis(
  258. props.organization,
  259. props.project,
  260. props.group,
  261. TestStubs.Event({
  262. size: 1,
  263. dateCreated: '2019-03-20T00:00:00.000Z',
  264. errors: [],
  265. entries: [],
  266. tags: [{key: 'environment', value: 'dev'}],
  267. previousEventID: 'prev-event-id',
  268. nextEventID: 'next-event-id',
  269. })
  270. );
  271. MockApiClient.addMockResponse({
  272. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  273. body: [
  274. {
  275. step: 'commit',
  276. complete: true,
  277. },
  278. ],
  279. });
  280. CommitterStore.loadSuccess(
  281. props.organization.slug,
  282. props.project.slug,
  283. props.event.id,
  284. [
  285. {
  286. commits: [TestStubs.Commit({author: TestStubs.CommitAuthor()})],
  287. author: TestStubs.CommitAuthor(),
  288. },
  289. ]
  290. );
  291. render(<TestComponent project={props.project} />, {organization: props.organization});
  292. expect(await screen.findByTestId(/event-cause/)).toBeInTheDocument();
  293. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  294. });
  295. it('renders suspect commit if `releasesCompletion` empty', async function () {
  296. const props = makeDefaultMockData(
  297. undefined,
  298. TestStubs.Project({firstEvent: TestStubs.Event()})
  299. );
  300. mockGroupApis(
  301. props.organization,
  302. props.project,
  303. props.group,
  304. TestStubs.Event({
  305. size: 1,
  306. dateCreated: '2019-03-20T00:00:00.000Z',
  307. errors: [],
  308. entries: [],
  309. tags: [{key: 'environment', value: 'dev'}],
  310. previousEventID: 'prev-event-id',
  311. nextEventID: 'next-event-id',
  312. })
  313. );
  314. MockApiClient.addMockResponse({
  315. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  316. body: [],
  317. });
  318. await act(async () => {
  319. render(<TestComponent project={props.project} />, {
  320. organization: props.organization,
  321. });
  322. await tick();
  323. });
  324. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  325. });
  326. });
  327. describe('Platform Integrations', () => {
  328. let componentsRequest;
  329. beforeEach(() => {
  330. MockApiClient.clearMockResponses();
  331. });
  332. it('loads Integration UI components', async () => {
  333. const props = makeDefaultMockData();
  334. const unpublishedIntegration = TestStubs.SentryApp({status: 'unpublished'});
  335. const internalIntegration = TestStubs.SentryApp({status: 'internal'});
  336. const unpublishedInstall = TestStubs.SentryAppInstallation({
  337. app: {
  338. slug: unpublishedIntegration.slug,
  339. uuid: unpublishedIntegration.uuid,
  340. },
  341. });
  342. const internalInstall = TestStubs.SentryAppInstallation({
  343. app: {
  344. slug: internalIntegration.slug,
  345. uuid: internalIntegration.uuid,
  346. },
  347. });
  348. mockGroupApis(
  349. props.organization,
  350. props.project,
  351. props.group,
  352. TestStubs.Event({
  353. size: 1,
  354. dateCreated: '2019-03-20T00:00:00.000Z',
  355. errors: [],
  356. entries: [],
  357. tags: [{key: 'environment', value: 'dev'}],
  358. previousEventID: 'prev-event-id',
  359. nextEventID: 'next-event-id',
  360. })
  361. );
  362. const component = TestStubs.SentryAppComponent({
  363. sentryApp: {
  364. uuid: unpublishedIntegration.uuid,
  365. slug: unpublishedIntegration.slug,
  366. name: unpublishedIntegration.name,
  367. },
  368. });
  369. MockApiClient.addMockResponse({
  370. url: `/organizations/${props.organization.slug}/sentry-app-installations/`,
  371. body: [unpublishedInstall, internalInstall],
  372. });
  373. componentsRequest = MockApiClient.addMockResponse({
  374. url: `/organizations/${props.organization.slug}/sentry-app-components/?projectId=${props.project.id}`,
  375. body: [component],
  376. });
  377. await act(async () => {
  378. render(<TestComponent />, {organization: props.organization});
  379. await tick();
  380. });
  381. expect(componentsRequest).toHaveBeenCalled();
  382. });
  383. });