groupDetails.spec.jsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 {OrganizationContext} from 'sentry/views/organizationContext';
  8. import GroupDetails from 'sentry/views/organizationGroupDetails';
  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();
  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. props: {currentTab: 'details', isEventRoute: false},
  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. <OrganizationContext.Provider value={organization}>
  61. <GroupDetails {...router} selection={props.selection}>
  62. <MockComponent />
  63. </GroupDetails>
  64. </OrganizationContext.Provider>,
  65. {context: routerContext}
  66. );
  67. };
  68. beforeEach(() => {
  69. act(() => ProjectsStore.loadInitialData(organization.projects));
  70. MockApiClient.addMockResponse({
  71. url: `/issues/${group.id}/`,
  72. body: {...group},
  73. });
  74. MockApiClient.addMockResponse({
  75. url: `/issues/${group.id}/events/latest/`,
  76. statusCode: 200,
  77. body: {
  78. ...event,
  79. },
  80. });
  81. MockApiClient.addMockResponse({
  82. url: `/projects/org-slug/${project.slug}/issues/`,
  83. method: 'PUT',
  84. body: {
  85. hasSeen: false,
  86. },
  87. });
  88. MockApiClient.addMockResponse({
  89. url: '/organizations/org-slug/projects/',
  90. body: [project],
  91. });
  92. MockApiClient.addMockResponse({
  93. url: '/organizations/org-slug/users/',
  94. body: [],
  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. });
  112. afterEach(() => {
  113. act(() => ProjectsStore.reset());
  114. GroupStore.reset();
  115. PageFiltersStore.reset();
  116. MockApiClient.clearMockResponses();
  117. });
  118. it('renders', async function () {
  119. act(() => ProjectsStore.reset());
  120. createWrapper();
  121. expect(screen.queryByText(group.title)).not.toBeInTheDocument();
  122. act(() => ProjectsStore.loadInitialData(organization.projects));
  123. expect(await screen.findByText(group.title, {exact: false})).toBeInTheDocument();
  124. // Sample event alert should not show up
  125. expect(screen.queryByText(SAMPLE_EVENT_ALERT_TEXT)).not.toBeInTheDocument();
  126. });
  127. it('renders error when issue is not found', async function () {
  128. MockApiClient.addMockResponse({
  129. url: `/issues/${group.id}/`,
  130. statusCode: 404,
  131. });
  132. MockApiClient.addMockResponse({
  133. url: `/issues/${group.id}/events/latest/`,
  134. statusCode: 404,
  135. });
  136. createWrapper();
  137. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  138. expect(
  139. await screen.findByText('The issue you were looking for was not found.')
  140. ).toBeInTheDocument();
  141. });
  142. it('renders MissingProjectMembership when trying to access issue in project the user does not belong to', async function () {
  143. MockApiClient.addMockResponse({
  144. url: `/issues/${group.id}/`,
  145. statusCode: 403,
  146. });
  147. MockApiClient.addMockResponse({
  148. url: `/issues/${group.id}/events/latest/`,
  149. statusCode: 403,
  150. });
  151. createWrapper();
  152. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  153. expect(
  154. await screen.findByText(
  155. 'No teams have access to this project yet. Ask an admin to add your team to this project.'
  156. )
  157. ).toBeInTheDocument();
  158. });
  159. it('fetches issue details for a given environment', async function () {
  160. createWrapper({
  161. selection: {environments: ['staging']},
  162. });
  163. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  164. expect(await screen.findByText('environment: staging')).toBeInTheDocument();
  165. });
  166. /**
  167. * This is legacy code that I'm not even sure still happens
  168. */
  169. it('redirects to new issue if params id !== id returned from API request', async function () {
  170. MockApiClient.addMockResponse({
  171. url: `/issues/${group.id}/`,
  172. body: {...group, id: 'new-id'},
  173. });
  174. createWrapper();
  175. expect(screen.queryByText('Group Details Mock')).not.toBeInTheDocument();
  176. await waitFor(() => {
  177. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  178. });
  179. expect(browserHistory.push).toHaveBeenCalledWith(
  180. '/organizations/org-slug/issues/new-id/?foo=bar#hash'
  181. );
  182. });
  183. it('renders issue event error', async function () {
  184. MockApiClient.addMockResponse({
  185. url: `/issues/${group.id}/events/latest/`,
  186. statusCode: 404,
  187. });
  188. createWrapper();
  189. expect(await screen.findByText('eventError')).toBeInTheDocument();
  190. });
  191. it('renders for review reason', async function () {
  192. MockApiClient.addMockResponse({
  193. url: `/issues/${group.id}/`,
  194. body: {
  195. ...group,
  196. inbox: {
  197. date_added: '2020-11-24T13:17:42.248751Z',
  198. reason: 0,
  199. reason_details: null,
  200. },
  201. },
  202. });
  203. act(() => ProjectsStore.reset());
  204. createWrapper();
  205. act(() => ProjectsStore.loadInitialData(organization.projects));
  206. expect(await screen.findByText('New Issue')).toBeInTheDocument();
  207. });
  208. it('renders alert for sample event', async function () {
  209. const sampleGruop = TestStubs.Group();
  210. sampleGruop.tags.push({key: 'sample_event'});
  211. MockApiClient.addMockResponse({
  212. url: `/issues/${group.id}/`,
  213. body: {...sampleGruop},
  214. });
  215. createWrapper();
  216. expect(await screen.findByText(SAMPLE_EVENT_ALERT_TEXT)).toBeInTheDocument();
  217. });
  218. });