overview.actions.spec.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import {Fragment} from 'react';
  2. import {GlobalSelectionFixture} from 'sentry-fixture/globalSelection';
  3. import {GroupFixture} from 'sentry-fixture/group';
  4. import {GroupStatsFixture} from 'sentry-fixture/groupStats';
  5. import {LocationFixture} from 'sentry-fixture/locationFixture';
  6. import {OrganizationFixture} from 'sentry-fixture/organization';
  7. import {ProjectFixture} from 'sentry-fixture/project';
  8. import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
  9. import {TagsFixture} from 'sentry-fixture/tags';
  10. import {
  11. render,
  12. screen,
  13. userEvent,
  14. waitFor,
  15. within,
  16. } from 'sentry-test/reactTestingLibrary';
  17. import Indicators from 'sentry/components/indicators';
  18. import GroupStore from 'sentry/stores/groupStore';
  19. import IssueListCacheStore from 'sentry/stores/IssueListCacheStore';
  20. import SelectedGroupStore from 'sentry/stores/selectedGroupStore';
  21. import TagStore from 'sentry/stores/tagStore';
  22. import IssueListOverview from 'sentry/views/issueList/overview';
  23. const DEFAULT_LINKS_HEADER =
  24. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575731:0:1>; rel="previous"; results="false"; cursor="1443575731:0:1", ' +
  25. '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575000:0:0>; rel="next"; results="true"; cursor="1443575000:0:0"';
  26. describe('IssueListOverview (actions)', function () {
  27. const project = ProjectFixture({
  28. id: '3559',
  29. name: 'Foo Project',
  30. slug: 'project-slug',
  31. firstEvent: new Date().toISOString(),
  32. });
  33. const tags = TagsFixture();
  34. const groupStats = GroupStatsFixture();
  35. const api = new MockApiClient();
  36. const organization = OrganizationFixture({features: ['issue-priority-ui']});
  37. beforeEach(function () {
  38. MockApiClient.clearMockResponses();
  39. GroupStore.reset();
  40. SelectedGroupStore.reset();
  41. IssueListCacheStore.reset();
  42. MockApiClient.addMockResponse({
  43. url: '/organizations/org-slug/issues-stats/',
  44. body: [groupStats],
  45. });
  46. MockApiClient.addMockResponse({
  47. url: '/organizations/org-slug/searches/',
  48. body: [],
  49. });
  50. MockApiClient.addMockResponse({
  51. url: '/organizations/org-slug/recent-searches/',
  52. body: [],
  53. });
  54. MockApiClient.addMockResponse({
  55. url: '/organizations/org-slug/recent-searches/',
  56. method: 'POST',
  57. body: [],
  58. });
  59. MockApiClient.addMockResponse({
  60. url: '/organizations/org-slug/issues-count/',
  61. method: 'GET',
  62. body: [{}],
  63. });
  64. MockApiClient.addMockResponse({
  65. url: '/organizations/org-slug/processingissues/',
  66. method: 'GET',
  67. body: [],
  68. });
  69. MockApiClient.addMockResponse({
  70. url: '/organizations/org-slug/tags/',
  71. method: 'GET',
  72. body: [],
  73. });
  74. MockApiClient.addMockResponse({
  75. url: '/organizations/org-slug/users/',
  76. method: 'GET',
  77. body: [],
  78. });
  79. MockApiClient.addMockResponse({
  80. url: '/organizations/org-slug/sent-first-event/',
  81. body: {sentFirstEvent: true},
  82. });
  83. MockApiClient.addMockResponse({
  84. url: '/organizations/org-slug/projects/',
  85. body: [],
  86. });
  87. TagStore.init?.();
  88. });
  89. const defaultProps = {
  90. api,
  91. savedSearchLoading: false,
  92. savedSearches: [],
  93. useOrgSavedSearches: true,
  94. selection: GlobalSelectionFixture(),
  95. organization,
  96. tags: [
  97. tags.reduce((acc, tag) => {
  98. acc[tag.key] = tag;
  99. return acc;
  100. }),
  101. ],
  102. savedSearch: null,
  103. selectedSearchId: null,
  104. ...RouteComponentPropsFixture({
  105. location: LocationFixture({
  106. query: {query: 'is:unresolved issue.priority:[high,medium]'},
  107. }),
  108. params: {orgId: organization.slug, projectId: project.slug, searchId: undefined},
  109. }),
  110. };
  111. describe('status', function () {
  112. const group1 = GroupFixture({
  113. id: '1',
  114. culprit: 'Group 1',
  115. shortId: 'JAVASCRIPT-1',
  116. });
  117. const group2 = GroupFixture({
  118. id: '2',
  119. culprit: 'Group 2',
  120. shortId: 'JAVASCRIPT-2',
  121. });
  122. beforeEach(() => {
  123. MockApiClient.addMockResponse({
  124. url: '/organizations/org-slug/issues/',
  125. body: [group1, group2],
  126. headers: {Link: DEFAULT_LINKS_HEADER},
  127. });
  128. });
  129. it('removes issues after resolving', async function () {
  130. const updateIssueMock = MockApiClient.addMockResponse({
  131. url: '/organizations/org-slug/issues/',
  132. method: 'PUT',
  133. });
  134. render(<IssueListOverview {...defaultProps} />, {organization});
  135. const groups = await screen.findAllByTestId('group');
  136. await userEvent.click(
  137. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  138. );
  139. expect(screen.getByText('Group 1')).toBeInTheDocument();
  140. expect(screen.getByText('Group 2')).toBeInTheDocument();
  141. // After action, will refetch so need to mock that response
  142. MockApiClient.addMockResponse({
  143. url: '/organizations/org-slug/issues/',
  144. body: [group2],
  145. headers: {Link: DEFAULT_LINKS_HEADER},
  146. });
  147. await userEvent.click(screen.getByRole('button', {name: 'Resolve'}));
  148. expect(updateIssueMock).toHaveBeenCalledWith(
  149. '/organizations/org-slug/issues/',
  150. expect.objectContaining({
  151. query: expect.objectContaining({id: ['1']}),
  152. data: {status: 'resolved', statusDetails: {}, substatus: null},
  153. })
  154. );
  155. await waitFor(() => {
  156. expect(screen.queryByText('Group 1')).not.toBeInTheDocument();
  157. expect(screen.getByText('Group 2')).toBeInTheDocument();
  158. });
  159. });
  160. it('can undo resolve action', async function () {
  161. const updateIssueMock = MockApiClient.addMockResponse({
  162. url: '/organizations/org-slug/issues/',
  163. method: 'PUT',
  164. });
  165. render(
  166. <Fragment>
  167. <IssueListOverview {...defaultProps} />
  168. <Indicators />
  169. </Fragment>,
  170. {organization}
  171. );
  172. const groups = await screen.findAllByTestId('group');
  173. await userEvent.click(
  174. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  175. );
  176. expect(screen.getByText('Group 1')).toBeInTheDocument();
  177. expect(screen.getByText('Group 2')).toBeInTheDocument();
  178. // After action, will refetch so need to mock that response
  179. MockApiClient.addMockResponse({
  180. url: '/organizations/org-slug/issues/',
  181. body: [group2],
  182. headers: {Link: DEFAULT_LINKS_HEADER},
  183. });
  184. await userEvent.click(screen.getByRole('button', {name: 'Resolve'}));
  185. expect(updateIssueMock).toHaveBeenCalledWith(
  186. '/organizations/org-slug/issues/',
  187. expect.objectContaining({
  188. query: expect.objectContaining({id: ['1']}),
  189. data: {status: 'resolved', statusDetails: {}, substatus: null},
  190. })
  191. );
  192. await waitFor(() => {
  193. expect(screen.queryByText('Group 1')).not.toBeInTheDocument();
  194. expect(screen.getByText('Group 2')).toBeInTheDocument();
  195. });
  196. // Should show a toast message
  197. expect(screen.getByText('Resolved JAVASCRIPT-1')).toBeInTheDocument();
  198. // Clicking the undo button makes a call to set the status back to unresolved
  199. MockApiClient.addMockResponse({
  200. url: '/organizations/org-slug/issues/',
  201. body: [group1, group2],
  202. headers: {Link: DEFAULT_LINKS_HEADER},
  203. });
  204. await userEvent.click(screen.getByRole('button', {name: 'Undo'}));
  205. expect(updateIssueMock).toHaveBeenLastCalledWith(
  206. '/organizations/org-slug/issues/',
  207. expect.objectContaining({
  208. query: expect.objectContaining({id: ['1']}),
  209. data: {status: 'unresolved', statusDetails: {}},
  210. })
  211. );
  212. expect(await screen.findByText('Group 1')).toBeInTheDocument();
  213. });
  214. });
  215. describe('mark reviewed', function () {
  216. const group1 = GroupFixture({
  217. id: '1',
  218. culprit: 'Group 1',
  219. shortId: 'JAVASCRIPT-1',
  220. inbox: {},
  221. });
  222. const group2 = GroupFixture({
  223. id: '2',
  224. culprit: 'Group 2',
  225. shortId: 'JAVASCRIPT-2',
  226. inbox: {},
  227. });
  228. beforeEach(() => {
  229. MockApiClient.addMockResponse({
  230. url: '/organizations/org-slug/issues/',
  231. body: [group1, group2],
  232. headers: {Link: DEFAULT_LINKS_HEADER},
  233. });
  234. });
  235. it('removes issues after making reviewed (when on for review tab)', async function () {
  236. const updateIssueMock = MockApiClient.addMockResponse({
  237. url: '/organizations/org-slug/issues/',
  238. method: 'PUT',
  239. });
  240. render(
  241. <IssueListOverview
  242. {...defaultProps}
  243. {...RouteComponentPropsFixture({
  244. location: LocationFixture({
  245. query: {query: 'is:for_review'},
  246. }),
  247. params: {
  248. orgId: organization.slug,
  249. projectId: project.slug,
  250. searchId: undefined,
  251. },
  252. })}
  253. />,
  254. {organization}
  255. );
  256. const groups = await screen.findAllByTestId('group');
  257. await userEvent.click(
  258. within(groups[0]).getByRole('checkbox', {name: /select issue/i})
  259. );
  260. expect(screen.getByText('Group 1')).toBeInTheDocument();
  261. expect(screen.getByText('Group 2')).toBeInTheDocument();
  262. // After action, will refetch so need to mock that response
  263. MockApiClient.addMockResponse({
  264. url: '/organizations/org-slug/issues/',
  265. body: [group2],
  266. headers: {Link: DEFAULT_LINKS_HEADER},
  267. });
  268. await userEvent.click(screen.getByRole('button', {name: 'Mark Reviewed'}));
  269. expect(updateIssueMock).toHaveBeenCalledWith(
  270. '/organizations/org-slug/issues/',
  271. expect.objectContaining({
  272. query: expect.objectContaining({id: ['1']}),
  273. data: {inbox: false},
  274. })
  275. );
  276. await waitFor(() => {
  277. expect(screen.queryByText('Group 1')).not.toBeInTheDocument();
  278. expect(screen.getByText('Group 2')).toBeInTheDocument();
  279. });
  280. });
  281. });
  282. });