groupDetails.spec.jsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. });
  116. afterEach(() => {
  117. act(() => ProjectsStore.reset());
  118. GroupStore.reset();
  119. PageFiltersStore.reset();
  120. MockApiClient.clearMockResponses();
  121. });
  122. it('renders', async function () {
  123. act(() => ProjectsStore.reset());
  124. createWrapper();
  125. expect(screen.queryByText(group.title)).not.toBeInTheDocument();
  126. act(() => ProjectsStore.loadInitialData(organization.projects));
  127. expect(await screen.findByText(group.title, {exact: false})).toBeInTheDocument();
  128. // Sample event alert should not show up
  129. expect(screen.queryByText(SAMPLE_EVENT_ALERT_TEXT)).not.toBeInTheDocument();
  130. });
  131. it('renders error when issue is not found', async function () {
  132. MockApiClient.addMockResponse({
  133. url: `/issues/${group.id}/`,
  134. statusCode: 404,
  135. });
  136. MockApiClient.addMockResponse({
  137. url: `/issues/${group.id}/events/latest/`,
  138. statusCode: 404,
  139. });
  140. createWrapper();
  141. await waitFor(() =>
  142. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  143. );
  144. expect(
  145. await screen.findByText('The issue you were looking for was not found.')
  146. ).toBeInTheDocument();
  147. });
  148. it('renders MissingProjectMembership when trying to access issue in project the user does not belong to', async function () {
  149. MockApiClient.addMockResponse({
  150. url: `/issues/${group.id}/`,
  151. statusCode: 403,
  152. });
  153. MockApiClient.addMockResponse({
  154. url: `/issues/${group.id}/events/latest/`,
  155. statusCode: 403,
  156. });
  157. createWrapper();
  158. await waitFor(() =>
  159. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  160. );
  161. expect(
  162. await screen.findByText(
  163. 'No teams have access to this project yet. Ask an admin to add your team to this project.'
  164. )
  165. ).toBeInTheDocument();
  166. });
  167. it('fetches issue details for a given environment', async function () {
  168. createWrapper({
  169. selection: {environments: ['staging']},
  170. });
  171. await waitFor(() =>
  172. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  173. );
  174. expect(await screen.findByText('environment: staging')).toBeInTheDocument();
  175. });
  176. /**
  177. * This is legacy code that I'm not even sure still happens
  178. */
  179. it('redirects to new issue if params id !== id returned from API request', async function () {
  180. MockApiClient.addMockResponse({
  181. url: `/issues/${group.id}/`,
  182. body: {...group, id: 'new-id'},
  183. });
  184. createWrapper();
  185. expect(screen.queryByText('Group Details Mock')).not.toBeInTheDocument();
  186. await waitFor(() => {
  187. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  188. });
  189. expect(browserHistory.push).toHaveBeenCalledWith(
  190. '/organizations/org-slug/issues/new-id/?foo=bar#hash'
  191. );
  192. });
  193. it('renders issue event error', async function () {
  194. MockApiClient.addMockResponse({
  195. url: `/issues/${group.id}/events/latest/`,
  196. statusCode: 404,
  197. });
  198. createWrapper();
  199. expect(await screen.findByText('eventError')).toBeInTheDocument();
  200. });
  201. it('renders for review reason', async function () {
  202. MockApiClient.addMockResponse({
  203. url: `/issues/${group.id}/`,
  204. body: {
  205. ...group,
  206. inbox: {
  207. date_added: '2020-11-24T13:17:42.248751Z',
  208. reason: 0,
  209. reason_details: null,
  210. },
  211. },
  212. });
  213. act(() => ProjectsStore.reset());
  214. createWrapper();
  215. act(() => ProjectsStore.loadInitialData(organization.projects));
  216. expect(await screen.findByText('New Issue')).toBeInTheDocument();
  217. });
  218. it('renders alert for sample event', async function () {
  219. const sampleGroup = TestStubs.Group({issueCategory: IssueCategory.ERROR});
  220. sampleGroup.tags.push({key: 'sample_event'});
  221. MockApiClient.addMockResponse({
  222. url: `/issues/${group.id}/`,
  223. body: {...sampleGroup},
  224. });
  225. createWrapper();
  226. expect(await screen.findByText(SAMPLE_EVENT_ALERT_TEXT)).toBeInTheDocument();
  227. });
  228. });