groupDetails.spec.jsx 7.1 KB

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