groupDetails.spec.tsx 10 KB

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