groupDetails.spec.jsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 selection = {environments: []};
  18. const routes = [
  19. {path: '/', childRoutes: [], component: null},
  20. {childRoutes: [], component: null},
  21. {
  22. path: '/organizations/:orgId/issues/:groupId/',
  23. indexRoute: null,
  24. childRoutes: [],
  25. componentPromise: () => {},
  26. component: null,
  27. },
  28. {
  29. componentPromise: null,
  30. component: null,
  31. },
  32. ];
  33. const {organization, router, routerContext} = initializeOrg({
  34. project,
  35. router: {
  36. location: {
  37. pathname: `/organizations/org-slug/issues/${group.id}/`,
  38. query: {},
  39. search: '?foo=bar',
  40. hash: '#hash',
  41. },
  42. params: {
  43. groupId: group.id,
  44. },
  45. routes,
  46. },
  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 = (props = {selection}) => {
  59. return render(
  60. <GroupDetails
  61. {...router}
  62. router={router}
  63. selection={props.selection}
  64. organization={organization}
  65. >
  66. <MockComponent />
  67. </GroupDetails>,
  68. {context: routerContext, organization, router}
  69. );
  70. };
  71. beforeEach(() => {
  72. OrganizationStore.onUpdate(organization);
  73. act(() => ProjectsStore.loadInitialData(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. body: {firstRelease: group.firstRelease, lastRelease: group.lastRelease},
  99. });
  100. MockApiClient.addMockResponse({
  101. url: `/organizations/${organization.slug}/events/`,
  102. statusCode: 200,
  103. body: {
  104. data: [
  105. {
  106. 'count()': 1,
  107. },
  108. ],
  109. },
  110. });
  111. MockApiClient.addMockResponse({
  112. url: `/organizations/${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(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. createWrapper({
  173. selection: {environments: ['staging']},
  174. });
  175. await waitFor(() =>
  176. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  177. );
  178. expect(await screen.findByText('environment: staging')).toBeInTheDocument();
  179. });
  180. /**
  181. * This is legacy code that I'm not even sure still happens
  182. */
  183. it('redirects to new issue if params id !== id returned from API request', async function () {
  184. MockApiClient.addMockResponse({
  185. url: `/issues/${group.id}/`,
  186. body: {...group, id: 'new-id'},
  187. });
  188. createWrapper();
  189. expect(screen.queryByText('Group Details Mock')).not.toBeInTheDocument();
  190. await waitFor(() => {
  191. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  192. });
  193. expect(browserHistory.push).toHaveBeenCalledWith(
  194. '/organizations/org-slug/issues/new-id/?foo=bar#hash'
  195. );
  196. });
  197. it('renders issue event error', async function () {
  198. MockApiClient.addMockResponse({
  199. url: `/issues/${group.id}/events/latest/`,
  200. statusCode: 404,
  201. });
  202. createWrapper();
  203. expect(await screen.findByText('eventError')).toBeInTheDocument();
  204. });
  205. it('renders for review reason', async function () {
  206. MockApiClient.addMockResponse({
  207. url: `/issues/${group.id}/`,
  208. body: {
  209. ...group,
  210. inbox: {
  211. date_added: '2020-11-24T13:17:42.248751Z',
  212. reason: 0,
  213. reason_details: null,
  214. },
  215. },
  216. });
  217. act(() => ProjectsStore.reset());
  218. createWrapper();
  219. act(() => ProjectsStore.loadInitialData(organization.projects));
  220. expect(await screen.findByText('New Issue')).toBeInTheDocument();
  221. });
  222. it('renders alert for sample event', async function () {
  223. const sampleGroup = TestStubs.Group({issueCategory: IssueCategory.ERROR});
  224. sampleGroup.tags.push({key: 'sample_event'});
  225. MockApiClient.addMockResponse({
  226. url: `/issues/${group.id}/tags/`,
  227. body: [{key: 'sample_event'}],
  228. });
  229. createWrapper();
  230. expect(await screen.findByText(SAMPLE_EVENT_ALERT_TEXT)).toBeInTheDocument();
  231. });
  232. });