groupDetails.spec.jsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. import {browserHistory} from 'react-router';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {act, render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import GroupStore from 'sentry/stores/groupStore';
  5. import OrganizationStore from 'sentry/stores/organizationStore';
  6. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  7. import ProjectsStore from 'sentry/stores/projectsStore';
  8. import {IssueCategory} from 'sentry/types';
  9. import GroupDetails from 'sentry/views/issueDetails';
  10. jest.unmock('sentry/utils/recreateRoute');
  11. const SAMPLE_EVENT_ALERT_TEXT =
  12. 'You are viewing a sample error. Configure Sentry to start viewing real errors.';
  13. describe('groupDetails', () => {
  14. const group = TestStubs.Group({issueCategory: IssueCategory.ERROR});
  15. const event = TestStubs.Event();
  16. const project = TestStubs.Project({teams: [TestStubs.Team()]});
  17. const routes = [
  18. {path: '/', childRoutes: [], component: null},
  19. {childRoutes: [], component: null},
  20. {
  21. path: '/organizations/:orgId/issues/:groupId/',
  22. indexRoute: null,
  23. childRoutes: [],
  24. componentPromise: () => {},
  25. component: null,
  26. },
  27. {
  28. componentPromise: null,
  29. component: null,
  30. },
  31. ];
  32. const initRouter = {
  33. location: {
  34. pathname: `/organizations/org-slug/issues/${group.id}/`,
  35. query: {},
  36. search: '?foo=bar',
  37. hash: '#hash',
  38. },
  39. params: {
  40. groupId: group.id,
  41. },
  42. routes,
  43. };
  44. const defaultInit = initializeOrg({
  45. project,
  46. router: initRouter,
  47. });
  48. function MockComponent({group: groupProp, environments, eventError}) {
  49. return (
  50. <div>
  51. Group Details Mock
  52. <div>title: {groupProp.title}</div>
  53. <div>environment: {environments.join(' ')}</div>
  54. {eventError && <div>eventError</div>}
  55. </div>
  56. );
  57. }
  58. const createWrapper = (init = defaultInit) => {
  59. return render(
  60. <GroupDetails
  61. {...init.router}
  62. router={init.router}
  63. organization={init.organization}
  64. >
  65. <MockComponent />
  66. </GroupDetails>,
  67. {context: init.routerContext, organization: init.organization, router: init.router}
  68. );
  69. };
  70. beforeEach(() => {
  71. MockApiClient.clearMockResponses();
  72. OrganizationStore.onUpdate(defaultInit.organization);
  73. act(() => ProjectsStore.loadInitialData(defaultInit.organization.projects));
  74. MockApiClient.addMockResponse({
  75. url: `/issues/${group.id}/`,
  76. body: {...group},
  77. });
  78. MockApiClient.addMockResponse({
  79. url: `/issues/${group.id}/events/latest/`,
  80. statusCode: 200,
  81. body: {
  82. ...event,
  83. },
  84. });
  85. MockApiClient.addMockResponse({
  86. url: `/projects/org-slug/${project.slug}/issues/`,
  87. method: 'PUT',
  88. body: {
  89. hasSeen: false,
  90. },
  91. });
  92. MockApiClient.addMockResponse({
  93. url: '/organizations/org-slug/projects/',
  94. body: [project],
  95. });
  96. MockApiClient.addMockResponse({
  97. url: `/issues/${group.id}/first-last-release/`,
  98. method: 'GET',
  99. });
  100. MockApiClient.addMockResponse({
  101. url: `/organizations/${defaultInit.organization.slug}/events/`,
  102. statusCode: 200,
  103. body: {
  104. data: [
  105. {
  106. 'count()': 1,
  107. },
  108. ],
  109. },
  110. });
  111. MockApiClient.addMockResponse({
  112. url: `/organizations/${defaultInit.organization.slug}/environments/`,
  113. body: TestStubs.Environments(),
  114. });
  115. MockApiClient.addMockResponse({
  116. url: `/issues/${group.id}/tags/`,
  117. body: [],
  118. });
  119. });
  120. afterEach(() => {
  121. act(() => ProjectsStore.reset());
  122. GroupStore.reset();
  123. PageFiltersStore.reset();
  124. MockApiClient.clearMockResponses();
  125. });
  126. it('renders', async function () {
  127. act(() => ProjectsStore.reset());
  128. createWrapper();
  129. expect(screen.queryByText(group.title)).not.toBeInTheDocument();
  130. act(() => ProjectsStore.loadInitialData(defaultInit.organization.projects));
  131. expect(await screen.findByText(group.title, {exact: false})).toBeInTheDocument();
  132. // Sample event alert should not show up
  133. expect(screen.queryByText(SAMPLE_EVENT_ALERT_TEXT)).not.toBeInTheDocument();
  134. });
  135. it('renders error when issue is not found', async function () {
  136. MockApiClient.addMockResponse({
  137. url: `/issues/${group.id}/`,
  138. statusCode: 404,
  139. });
  140. MockApiClient.addMockResponse({
  141. url: `/issues/${group.id}/events/latest/`,
  142. statusCode: 404,
  143. });
  144. createWrapper();
  145. await waitFor(() =>
  146. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  147. );
  148. expect(
  149. await screen.findByText('The issue you were looking for was not found.')
  150. ).toBeInTheDocument();
  151. });
  152. it('renders MissingProjectMembership when trying to access issue in project the user does not belong to', async function () {
  153. MockApiClient.addMockResponse({
  154. url: `/issues/${group.id}/`,
  155. statusCode: 403,
  156. });
  157. MockApiClient.addMockResponse({
  158. url: `/issues/${group.id}/events/latest/`,
  159. statusCode: 403,
  160. });
  161. createWrapper();
  162. await waitFor(() =>
  163. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  164. );
  165. expect(
  166. await screen.findByText(
  167. 'No teams have access to this project yet. Ask an admin to add your team to this project.'
  168. )
  169. ).toBeInTheDocument();
  170. });
  171. it('fetches issue details for a given environment', async function () {
  172. const init = initializeOrg({
  173. router: {
  174. ...initRouter,
  175. location: TestStubs.location({
  176. ...initRouter.location,
  177. query: {environment: 'staging'},
  178. }),
  179. },
  180. });
  181. createWrapper({router: init.router});
  182. await waitFor(() =>
  183. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  184. );
  185. expect(await screen.findByText('environment: staging')).toBeInTheDocument();
  186. });
  187. /**
  188. * This is legacy code that I'm not even sure still happens
  189. */
  190. it('redirects to new issue if params id !== id returned from API request', async function () {
  191. MockApiClient.addMockResponse({
  192. url: `/issues/${group.id}/`,
  193. body: {...group, id: 'new-id'},
  194. });
  195. createWrapper();
  196. expect(screen.queryByText('Group Details Mock')).not.toBeInTheDocument();
  197. await waitFor(() => {
  198. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  199. });
  200. expect(browserHistory.push).toHaveBeenCalledWith(
  201. '/organizations/org-slug/issues/new-id/?foo=bar#hash'
  202. );
  203. });
  204. it('renders issue event error', async function () {
  205. MockApiClient.addMockResponse({
  206. url: `/issues/${group.id}/events/latest/`,
  207. statusCode: 404,
  208. });
  209. createWrapper();
  210. expect(await screen.findByText('eventError')).toBeInTheDocument();
  211. });
  212. it('renders for review reason', async function () {
  213. MockApiClient.addMockResponse({
  214. url: `/issues/${group.id}/`,
  215. body: {
  216. ...group,
  217. inbox: {
  218. date_added: '2020-11-24T13:17:42.248751Z',
  219. reason: 0,
  220. reason_details: null,
  221. },
  222. },
  223. });
  224. createWrapper();
  225. expect(await screen.findByText('New Issue')).toBeInTheDocument();
  226. });
  227. it('renders substatus badge', async function () {
  228. MockApiClient.addMockResponse({
  229. url: `/issues/${group.id}/`,
  230. body: {
  231. ...group,
  232. inbox: null,
  233. status: 'unresolved',
  234. substatus: 'ongoing',
  235. },
  236. });
  237. createWrapper({
  238. ...defaultInit,
  239. organization: {...defaultInit.organization, features: ['escalating-issues-ui']},
  240. });
  241. expect(await screen.findByText('Ongoing')).toBeInTheDocument();
  242. });
  243. it('renders alert for sample event', async function () {
  244. const sampleGroup = TestStubs.Group({issueCategory: IssueCategory.ERROR});
  245. sampleGroup.tags.push({key: 'sample_event'});
  246. MockApiClient.addMockResponse({
  247. url: `/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: `/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. });