groupDetails.spec.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. import {ConfigFixture} from 'sentry-fixture/config';
  2. import {EnvironmentsFixture} from 'sentry-fixture/environments';
  3. import {EventFixture} from 'sentry-fixture/event';
  4. import {GroupFixture} from 'sentry-fixture/group';
  5. import {LocationFixture} from 'sentry-fixture/locationFixture';
  6. import {ProjectFixture} from 'sentry-fixture/project';
  7. import {TeamFixture} from 'sentry-fixture/team';
  8. import {UserFixture} from 'sentry-fixture/user';
  9. import {initializeOrg} from 'sentry-test/initializeOrg';
  10. import {act, render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  11. import ConfigStore from 'sentry/stores/configStore';
  12. import GroupStore from 'sentry/stores/groupStore';
  13. import OrganizationStore from 'sentry/stores/organizationStore';
  14. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  15. import ProjectsStore from 'sentry/stores/projectsStore';
  16. import {Environment, Group, IssueCategory} from 'sentry/types';
  17. import GroupDetails from 'sentry/views/issueDetails/groupDetails';
  18. jest.unmock('sentry/utils/recreateRoute');
  19. const SAMPLE_EVENT_ALERT_TEXT =
  20. 'You are viewing a sample error. Configure Sentry to start viewing real errors.';
  21. describe('groupDetails', () => {
  22. const group = GroupFixture({issueCategory: IssueCategory.ERROR});
  23. const event = EventFixture();
  24. const project = ProjectFixture({teams: [TeamFixture()]});
  25. const routes = [
  26. {path: '/', childRoutes: []},
  27. {childRoutes: []},
  28. {
  29. path: '/organizations/:orgId/issues/:groupId/',
  30. childRoutes: [],
  31. },
  32. {},
  33. ];
  34. const initRouter = {
  35. location: {
  36. pathname: `/organizations/org-slug/issues/${group.id}/`,
  37. query: {},
  38. search: '?foo=bar',
  39. hash: '#hash',
  40. },
  41. params: {
  42. groupId: group.id,
  43. },
  44. routes,
  45. };
  46. const defaultInit = initializeOrg<{groupId: string}>({
  47. project,
  48. router: initRouter,
  49. });
  50. const recommendedUser = UserFixture({
  51. options: {
  52. ...UserFixture().options,
  53. defaultIssueEvent: 'recommended',
  54. },
  55. });
  56. const latestUser = UserFixture({
  57. options: {
  58. ...UserFixture().options,
  59. defaultIssueEvent: 'latest',
  60. },
  61. });
  62. const oldestUser = UserFixture({
  63. options: {
  64. ...UserFixture().options,
  65. defaultIssueEvent: 'oldest',
  66. },
  67. });
  68. function MockComponent({
  69. group: groupProp,
  70. environments,
  71. eventError,
  72. }: {
  73. environments?: Environment[];
  74. eventError?: boolean;
  75. group?: Group;
  76. }) {
  77. return (
  78. <div>
  79. Group Details Mock
  80. <div>title: {groupProp?.title}</div>
  81. <div>environment: {environments?.join(' ')}</div>
  82. {eventError && <div>eventError</div>}
  83. </div>
  84. );
  85. }
  86. const createWrapper = (init = defaultInit) => {
  87. return render(
  88. <GroupDetails {...init.routerProps}>
  89. <MockComponent />
  90. </GroupDetails>,
  91. {context: init.routerContext, organization: init.organization, router: init.router}
  92. );
  93. };
  94. beforeEach(() => {
  95. MockApiClient.clearMockResponses();
  96. OrganizationStore.onUpdate(defaultInit.organization);
  97. act(() => ProjectsStore.loadInitialData(defaultInit.organization.projects));
  98. MockApiClient.addMockResponse({
  99. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/`,
  100. body: {...group},
  101. });
  102. MockApiClient.addMockResponse({
  103. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/events/recommended/`,
  104. statusCode: 200,
  105. body: {
  106. ...event,
  107. },
  108. });
  109. MockApiClient.addMockResponse({
  110. url: `/projects/org-slug/${project.slug}/issues/`,
  111. method: 'PUT',
  112. body: {
  113. hasSeen: false,
  114. },
  115. });
  116. MockApiClient.addMockResponse({
  117. url: '/organizations/org-slug/projects/',
  118. body: [project],
  119. });
  120. MockApiClient.addMockResponse({
  121. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/first-last-release/`,
  122. method: 'GET',
  123. });
  124. MockApiClient.addMockResponse({
  125. url: `/organizations/${defaultInit.organization.slug}/events/`,
  126. statusCode: 200,
  127. body: {
  128. data: [
  129. {
  130. 'count()': 1,
  131. },
  132. ],
  133. },
  134. });
  135. MockApiClient.addMockResponse({
  136. url: `/organizations/${defaultInit.organization.slug}/environments/`,
  137. body: EnvironmentsFixture(),
  138. });
  139. MockApiClient.addMockResponse({
  140. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/tags/`,
  141. body: [],
  142. });
  143. MockApiClient.addMockResponse({
  144. url: '/organizations/org-slug/replay-count/',
  145. body: {},
  146. });
  147. });
  148. afterEach(() => {
  149. act(() => ProjectsStore.reset());
  150. GroupStore.reset();
  151. PageFiltersStore.reset();
  152. MockApiClient.clearMockResponses();
  153. });
  154. it('renders', async function () {
  155. act(() => ProjectsStore.reset());
  156. createWrapper();
  157. expect(screen.queryByText(group.title)).not.toBeInTheDocument();
  158. act(() => ProjectsStore.loadInitialData(defaultInit.organization.projects));
  159. expect(await screen.findByText(group.title, {exact: false})).toBeInTheDocument();
  160. // Sample event alert should not show up
  161. expect(screen.queryByText(SAMPLE_EVENT_ALERT_TEXT)).not.toBeInTheDocument();
  162. });
  163. it('renders error when issue is not found', async function () {
  164. MockApiClient.addMockResponse({
  165. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/`,
  166. statusCode: 404,
  167. });
  168. MockApiClient.addMockResponse({
  169. url: `/organization/${defaultInit.organization.slug}/issues/${group.id}/events/recommended/`,
  170. statusCode: 404,
  171. });
  172. createWrapper();
  173. await waitFor(() =>
  174. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  175. );
  176. expect(
  177. await screen.findByText('The issue you were looking for was not found.')
  178. ).toBeInTheDocument();
  179. });
  180. it('renders MissingProjectMembership when trying to access issue in project the user does not belong to', async function () {
  181. MockApiClient.addMockResponse({
  182. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/`,
  183. statusCode: 403,
  184. });
  185. MockApiClient.addMockResponse({
  186. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/events/recommended/`,
  187. statusCode: 403,
  188. });
  189. createWrapper();
  190. await waitFor(() =>
  191. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  192. );
  193. expect(
  194. await screen.findByText(
  195. 'No teams have access to this project yet. Ask an admin to add your team to this project.'
  196. )
  197. ).toBeInTheDocument();
  198. });
  199. it('fetches issue details for a given environment', async function () {
  200. const init = initializeOrg({
  201. router: {
  202. ...initRouter,
  203. location: LocationFixture({
  204. ...initRouter.location,
  205. query: {environment: 'staging'},
  206. }),
  207. },
  208. });
  209. createWrapper(init);
  210. await waitFor(() =>
  211. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  212. );
  213. expect(await screen.findByText('environment: staging')).toBeInTheDocument();
  214. });
  215. it('renders issue event error', async function () {
  216. MockApiClient.addMockResponse({
  217. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/events/recommended/`,
  218. statusCode: 404,
  219. });
  220. createWrapper();
  221. expect(await screen.findByText('eventError')).toBeInTheDocument();
  222. });
  223. it('renders for review reason', async function () {
  224. MockApiClient.addMockResponse({
  225. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/`,
  226. body: {
  227. ...group,
  228. inbox: {
  229. date_added: '2020-11-24T13:17:42.248751Z',
  230. reason: 0,
  231. reason_details: null,
  232. },
  233. },
  234. });
  235. createWrapper();
  236. expect(await screen.findByText('New Issue')).toBeInTheDocument();
  237. });
  238. it('renders substatus badge', async function () {
  239. MockApiClient.addMockResponse({
  240. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/`,
  241. body: {
  242. ...group,
  243. inbox: null,
  244. status: 'unresolved',
  245. substatus: 'ongoing',
  246. },
  247. });
  248. createWrapper({
  249. ...defaultInit,
  250. organization: {...defaultInit.organization, features: ['escalating-issues']},
  251. });
  252. expect(await screen.findByText('Ongoing')).toBeInTheDocument();
  253. });
  254. it('renders alert for sample event', async function () {
  255. MockApiClient.addMockResponse({
  256. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/tags/`,
  257. body: [{key: 'sample_event'}],
  258. });
  259. createWrapper();
  260. expect(await screen.findByText(SAMPLE_EVENT_ALERT_TEXT)).toBeInTheDocument();
  261. });
  262. it('renders error when project does not exist', async function () {
  263. MockApiClient.addMockResponse({
  264. url: `/projects/org-slug/other-project-slug/issues/`,
  265. method: 'PUT',
  266. });
  267. MockApiClient.addMockResponse({
  268. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/`,
  269. body: {...group, project: {slug: 'other-project-slug'}},
  270. });
  271. createWrapper();
  272. expect(
  273. await screen.findByText('The project other-project-slug does not exist')
  274. ).toBeInTheDocument();
  275. });
  276. it('uses /recommended endpoint when feature flag is on and no event is provided', async function () {
  277. const recommendedMock = MockApiClient.addMockResponse({
  278. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/events/recommended/`,
  279. statusCode: 200,
  280. body: event,
  281. });
  282. createWrapper();
  283. await waitFor(() => expect(recommendedMock).toHaveBeenCalledTimes(1));
  284. });
  285. it('uses /latest endpoint when default is set to latest', async function () {
  286. ConfigStore.loadInitialData(ConfigFixture({user: latestUser}));
  287. const latestMock = MockApiClient.addMockResponse({
  288. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/events/latest/`,
  289. statusCode: 200,
  290. body: event,
  291. });
  292. createWrapper();
  293. await waitFor(() => expect(latestMock).toHaveBeenCalledTimes(1));
  294. });
  295. it('uses /oldest endpoint when default is set to oldest', async function () {
  296. ConfigStore.loadInitialData(ConfigFixture({user: oldestUser}));
  297. const oldestMock = MockApiClient.addMockResponse({
  298. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/events/oldest/`,
  299. statusCode: 200,
  300. body: event,
  301. });
  302. createWrapper();
  303. await waitFor(() => expect(oldestMock).toHaveBeenCalledTimes(1));
  304. });
  305. it('uses /recommended endpoint when default is set to recommended', async function () {
  306. ConfigStore.loadInitialData(ConfigFixture({user: recommendedUser}));
  307. const recommendedMock = MockApiClient.addMockResponse({
  308. url: `/organizations/${defaultInit.organization.slug}/issues/${group.id}/events/recommended/`,
  309. statusCode: 200,
  310. body: event,
  311. });
  312. createWrapper();
  313. await waitFor(() => expect(recommendedMock).toHaveBeenCalledTimes(1));
  314. });
  315. });