groupDetails.spec.jsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 GroupDetails from 'sentry/views/organizationGroupDetails';
  8. jest.unmock('sentry/utils/recreateRoute');
  9. const SAMPLE_EVENT_ALERT_TEXT =
  10. 'You are viewing a sample error. Configure Sentry to start viewing real errors.';
  11. describe('groupDetails', () => {
  12. const group = TestStubs.Group();
  13. const event = TestStubs.Event();
  14. const project = TestStubs.Project({teams: [TestStubs.Team()]});
  15. const selection = {environments: []};
  16. const routes = [
  17. {path: '/', childRoutes: [], component: null},
  18. {childRoutes: [], component: null},
  19. {
  20. path: '/organizations/:orgId/issues/:groupId/',
  21. indexRoute: null,
  22. childRoutes: [],
  23. componentPromise: () => {},
  24. component: null,
  25. },
  26. {
  27. componentPromise: null,
  28. component: null,
  29. props: {currentTab: 'details', isEventRoute: false},
  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 organization={organization} {...router} selection={props.selection}>
  60. <MockComponent />
  61. </GroupDetails>,
  62. {context: routerContext}
  63. );
  64. };
  65. beforeEach(() => {
  66. act(() => ProjectsStore.loadInitialData(organization.projects));
  67. MockApiClient.addMockResponse({
  68. url: `/issues/${group.id}/`,
  69. body: {...group},
  70. });
  71. MockApiClient.addMockResponse({
  72. url: `/issues/${group.id}/events/latest/`,
  73. statusCode: 200,
  74. body: {
  75. ...event,
  76. },
  77. });
  78. MockApiClient.addMockResponse({
  79. url: `/projects/org-slug/${project.slug}/issues/`,
  80. method: 'PUT',
  81. body: {
  82. hasSeen: false,
  83. },
  84. });
  85. MockApiClient.addMockResponse({
  86. url: '/organizations/org-slug/projects/',
  87. body: [project],
  88. });
  89. MockApiClient.addMockResponse({
  90. url: '/organizations/org-slug/users/',
  91. body: [],
  92. });
  93. MockApiClient.addMockResponse({
  94. url: `/issues/${group.id}/first-last-release/`,
  95. body: {firstRelease: group.firstRelease, lastRelease: group.lastRelease},
  96. });
  97. });
  98. afterEach(() => {
  99. act(() => ProjectsStore.reset());
  100. GroupStore.reset();
  101. PageFiltersStore.reset();
  102. MockApiClient.clearMockResponses();
  103. });
  104. it('renders', async function () {
  105. act(() => ProjectsStore.reset());
  106. createWrapper();
  107. expect(screen.queryByText(group.title)).not.toBeInTheDocument();
  108. act(() => ProjectsStore.loadInitialData(organization.projects));
  109. expect(await screen.findByText(group.title, {exact: false})).toBeInTheDocument();
  110. // Sample event alert should not show up
  111. expect(screen.queryByText(SAMPLE_EVENT_ALERT_TEXT)).not.toBeInTheDocument();
  112. });
  113. it('renders error when issue is not found', async function () {
  114. MockApiClient.addMockResponse({
  115. url: `/issues/${group.id}/`,
  116. statusCode: 404,
  117. });
  118. MockApiClient.addMockResponse({
  119. url: `/issues/${group.id}/events/latest/`,
  120. statusCode: 404,
  121. });
  122. createWrapper();
  123. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  124. expect(
  125. await screen.findByText('The issue you were looking for was not found.')
  126. ).toBeInTheDocument();
  127. });
  128. it('renders MissingProjectMembership when trying to access issue in project the user does not belong to', async function () {
  129. MockApiClient.addMockResponse({
  130. url: `/issues/${group.id}/`,
  131. statusCode: 403,
  132. });
  133. MockApiClient.addMockResponse({
  134. url: `/issues/${group.id}/events/latest/`,
  135. statusCode: 403,
  136. });
  137. createWrapper();
  138. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  139. expect(
  140. await screen.findByText(
  141. "You'll need to join a team with access before you can view this data."
  142. )
  143. ).toBeInTheDocument();
  144. });
  145. it('fetches issue details for a given environment', async function () {
  146. createWrapper({
  147. selection: {environments: ['staging']},
  148. });
  149. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  150. expect(await screen.findByText('environment: staging')).toBeInTheDocument();
  151. });
  152. /**
  153. * This is legacy code that I'm not even sure still happens
  154. */
  155. it('redirects to new issue if params id !== id returned from API request', async function () {
  156. MockApiClient.addMockResponse({
  157. url: `/issues/${group.id}/`,
  158. body: {...group, id: 'new-id'},
  159. });
  160. createWrapper();
  161. expect(screen.queryByText('Group Details Mock')).not.toBeInTheDocument();
  162. await waitFor(() => {
  163. expect(browserHistory.push).toHaveBeenCalledTimes(1);
  164. });
  165. expect(browserHistory.push).toHaveBeenCalledWith(
  166. '/organizations/org-slug/issues/new-id/?foo=bar#hash'
  167. );
  168. });
  169. it('renders issue event error', async function () {
  170. MockApiClient.addMockResponse({
  171. url: `/issues/${group.id}/events/latest/`,
  172. statusCode: 404,
  173. });
  174. createWrapper();
  175. expect(await screen.findByText('eventError')).toBeInTheDocument();
  176. });
  177. it('renders for review reason', async function () {
  178. MockApiClient.addMockResponse({
  179. url: `/issues/${group.id}/`,
  180. body: {
  181. ...group,
  182. inbox: {
  183. date_added: '2020-11-24T13:17:42.248751Z',
  184. reason: 0,
  185. reason_details: null,
  186. },
  187. },
  188. });
  189. act(() => ProjectsStore.reset());
  190. createWrapper();
  191. act(() => ProjectsStore.loadInitialData(organization.projects));
  192. expect(await screen.findByText('New Issue')).toBeInTheDocument();
  193. });
  194. it('renders alert for sample event', async function () {
  195. const sampleGruop = TestStubs.Group();
  196. sampleGruop.tags.push({key: 'sample_event'});
  197. MockApiClient.addMockResponse({
  198. url: `/issues/${group.id}/`,
  199. body: {...sampleGruop},
  200. });
  201. createWrapper();
  202. expect(await screen.findByText(SAMPLE_EVENT_ALERT_TEXT)).toBeInTheDocument();
  203. });
  204. });