groupDetails.spec.tsx 10 KB

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