groupEventDetails.spec.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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 {Event, Group} 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('next/prev links', 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. MockApiClient.addMockResponse({
  199. url: `/projects/${props.organization.slug}/${props.project.slug}/events/1/`,
  200. body: event,
  201. });
  202. const routerContext = TestStubs.routerContext();
  203. await act(async () => {
  204. render(
  205. <TestComponent
  206. {...props}
  207. location={{query: {environment: 'dev'}} as Location<any>}
  208. />,
  209. {
  210. context: routerContext,
  211. organization: props.organization,
  212. }
  213. );
  214. await tick();
  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('EventCause', () => {
  246. beforeEach(() => {
  247. MockApiClient.clearMockResponses();
  248. });
  249. afterEach(function () {
  250. MockApiClient.clearMockResponses();
  251. (browserHistory.replace as jest.Mock).mockClear();
  252. });
  253. it('renders suspect commit', async function () {
  254. const props = makeDefaultMockData(
  255. undefined,
  256. TestStubs.Project({firstEvent: TestStubs.Event()})
  257. );
  258. mockGroupApis(
  259. props.organization,
  260. props.project,
  261. props.group,
  262. TestStubs.Event({
  263. size: 1,
  264. dateCreated: '2019-03-20T00:00:00.000Z',
  265. errors: [],
  266. entries: [],
  267. tags: [{key: 'environment', value: 'dev'}],
  268. previousEventID: 'prev-event-id',
  269. nextEventID: 'next-event-id',
  270. })
  271. );
  272. MockApiClient.addMockResponse({
  273. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  274. body: [
  275. {
  276. step: 'commit',
  277. complete: true,
  278. },
  279. ],
  280. });
  281. MockApiClient.addMockResponse({
  282. url: `/projects/${props.organization.slug}/${props.project.slug}/events/${props.event.id}/committers/`,
  283. body: {
  284. committers: [
  285. {
  286. commits: [TestStubs.Commit({author: TestStubs.CommitAuthor()})],
  287. author: TestStubs.CommitAuthor(),
  288. },
  289. ],
  290. },
  291. });
  292. render(<TestComponent project={props.project} />, {organization: props.organization});
  293. expect(await screen.findByTestId(/event-cause/)).toBeInTheDocument();
  294. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  295. });
  296. it('renders suspect commit if `releasesCompletion` empty', async function () {
  297. const props = makeDefaultMockData(
  298. undefined,
  299. TestStubs.Project({firstEvent: TestStubs.Event()})
  300. );
  301. mockGroupApis(
  302. props.organization,
  303. props.project,
  304. props.group,
  305. TestStubs.Event({
  306. size: 1,
  307. dateCreated: '2019-03-20T00:00:00.000Z',
  308. errors: [],
  309. entries: [],
  310. tags: [{key: 'environment', value: 'dev'}],
  311. previousEventID: 'prev-event-id',
  312. nextEventID: 'next-event-id',
  313. })
  314. );
  315. MockApiClient.addMockResponse({
  316. url: `/projects/${props.organization.slug}/${props.project.slug}/releases/completion/`,
  317. body: [],
  318. });
  319. await act(async () => {
  320. render(<TestComponent project={props.project} />, {
  321. organization: props.organization,
  322. });
  323. await tick();
  324. });
  325. expect(screen.queryByTestId(/loaded-event-cause-empty/)).not.toBeInTheDocument();
  326. });
  327. });
  328. describe('Platform Integrations', () => {
  329. let componentsRequest;
  330. beforeEach(() => {
  331. MockApiClient.clearMockResponses();
  332. });
  333. it('loads Integration UI components', async () => {
  334. const props = makeDefaultMockData();
  335. const unpublishedIntegration = TestStubs.SentryApp({status: 'unpublished'});
  336. const internalIntegration = TestStubs.SentryApp({status: 'internal'});
  337. const unpublishedInstall = TestStubs.SentryAppInstallation({
  338. app: {
  339. slug: unpublishedIntegration.slug,
  340. uuid: unpublishedIntegration.uuid,
  341. },
  342. });
  343. const internalInstall = TestStubs.SentryAppInstallation({
  344. app: {
  345. slug: internalIntegration.slug,
  346. uuid: internalIntegration.uuid,
  347. },
  348. });
  349. mockGroupApis(
  350. props.organization,
  351. props.project,
  352. props.group,
  353. TestStubs.Event({
  354. size: 1,
  355. dateCreated: '2019-03-20T00:00:00.000Z',
  356. errors: [],
  357. entries: [],
  358. tags: [{key: 'environment', value: 'dev'}],
  359. previousEventID: 'prev-event-id',
  360. nextEventID: 'next-event-id',
  361. })
  362. );
  363. const component = TestStubs.SentryAppComponent({
  364. sentryApp: {
  365. uuid: unpublishedIntegration.uuid,
  366. slug: unpublishedIntegration.slug,
  367. name: unpublishedIntegration.name,
  368. },
  369. });
  370. MockApiClient.addMockResponse({
  371. url: `/organizations/${props.organization.slug}/sentry-app-installations/`,
  372. body: [unpublishedInstall, internalInstall],
  373. });
  374. componentsRequest = MockApiClient.addMockResponse({
  375. url: `/organizations/${props.organization.slug}/sentry-app-components/?projectId=${props.project.id}`,
  376. body: [component],
  377. });
  378. await act(async () => {
  379. render(<TestComponent />, {organization: props.organization});
  380. await tick();
  381. });
  382. expect(componentsRequest).toHaveBeenCalled();
  383. });
  384. });