index.spec.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import {Fragment} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import {
  4. render,
  5. screen,
  6. userEvent,
  7. waitFor,
  8. within,
  9. } from 'sentry-test/reactTestingLibrary';
  10. import GlobalModal from 'sentry/components/globalModal';
  11. import ConfigStore from 'sentry/stores/configStore';
  12. import ModalStore from 'sentry/stores/modalStore';
  13. import {IssueCategory} from 'sentry/types';
  14. import GroupActions from 'sentry/views/issueDetails/actions';
  15. const project = TestStubs.ProjectDetails({
  16. id: '2448',
  17. name: 'project name',
  18. slug: 'project',
  19. });
  20. const group = TestStubs.Group({
  21. id: '1337',
  22. pluginActions: [],
  23. pluginIssues: [],
  24. issueCategory: IssueCategory.ERROR,
  25. project,
  26. });
  27. const organization = TestStubs.Organization({
  28. id: '4660',
  29. slug: 'org',
  30. features: ['reprocessing-v2'],
  31. });
  32. describe('GroupActions', function () {
  33. beforeEach(function () {
  34. ConfigStore.init();
  35. jest.spyOn(ConfigStore, 'get').mockImplementation(() => []);
  36. MockApiClient.clearMockResponses();
  37. });
  38. describe('render()', function () {
  39. it('renders correctly', function () {
  40. const wrapper = render(
  41. <GroupActions
  42. group={group}
  43. project={project}
  44. organization={organization}
  45. disabled={false}
  46. />
  47. );
  48. expect(wrapper.container).toSnapshot();
  49. });
  50. });
  51. describe('subscribing', function () {
  52. let issuesApi: any;
  53. beforeEach(function () {
  54. issuesApi = MockApiClient.addMockResponse({
  55. url: '/projects/org/project/issues/',
  56. method: 'PUT',
  57. body: TestStubs.Group({isSubscribed: false}),
  58. });
  59. });
  60. it('can subscribe', function () {
  61. render(
  62. <GroupActions
  63. group={group}
  64. project={project}
  65. organization={organization}
  66. disabled={false}
  67. />
  68. );
  69. userEvent.click(screen.getByRole('button', {name: 'Subscribe'}));
  70. expect(issuesApi).toHaveBeenCalledWith(
  71. expect.anything(),
  72. expect.objectContaining({
  73. data: {isSubscribed: true},
  74. })
  75. );
  76. });
  77. });
  78. describe('bookmarking', function () {
  79. let issuesApi: any;
  80. beforeEach(function () {
  81. issuesApi = MockApiClient.addMockResponse({
  82. url: '/projects/org/project/issues/',
  83. method: 'PUT',
  84. body: TestStubs.Group({isBookmarked: false}),
  85. });
  86. });
  87. it('can bookmark', async function () {
  88. render(
  89. <GroupActions
  90. group={group}
  91. project={project}
  92. organization={organization}
  93. disabled={false}
  94. />
  95. );
  96. userEvent.click(screen.getByLabelText('More Actions'));
  97. const bookmark = await screen.findByTestId('bookmark');
  98. userEvent.click(bookmark);
  99. expect(issuesApi).toHaveBeenCalledWith(
  100. expect.anything(),
  101. expect.objectContaining({
  102. data: {isBookmarked: true},
  103. })
  104. );
  105. });
  106. });
  107. describe('reprocessing', function () {
  108. it('renders ReprocessAction component if org has feature flag reprocessing-v2 and native exception event', async function () {
  109. const event = TestStubs.EventStacktraceException({
  110. platform: 'native',
  111. });
  112. render(
  113. <GroupActions
  114. group={group}
  115. project={project}
  116. organization={organization}
  117. event={event}
  118. disabled={false}
  119. />
  120. );
  121. userEvent.click(screen.getByLabelText('More Actions'));
  122. const reprocessActionButton = await screen.findByTestId('reprocess');
  123. expect(reprocessActionButton).toBeInTheDocument();
  124. });
  125. it('open dialog by clicking on the ReprocessAction component', async function () {
  126. const event = TestStubs.EventStacktraceException({
  127. platform: 'native',
  128. });
  129. render(
  130. <GroupActions
  131. group={group}
  132. project={project}
  133. organization={organization}
  134. event={event}
  135. disabled={false}
  136. />
  137. );
  138. const onReprocessEventFunc = jest.spyOn(ModalStore, 'openModal');
  139. userEvent.click(screen.getByLabelText('More Actions'));
  140. const reprocessActionButton = await screen.findByTestId('reprocess');
  141. expect(reprocessActionButton).toBeInTheDocument();
  142. userEvent.click(reprocessActionButton);
  143. await waitFor(() => expect(onReprocessEventFunc).toHaveBeenCalled());
  144. });
  145. });
  146. it('opens share modal from more actions dropdown', async () => {
  147. const org = {
  148. ...organization,
  149. features: ['shared-issues'],
  150. };
  151. const updateMock = MockApiClient.addMockResponse({
  152. url: `/projects/${org.slug}/${project.slug}/issues/`,
  153. method: 'PUT',
  154. body: {},
  155. });
  156. render(
  157. <Fragment>
  158. <GlobalModal />
  159. <GroupActions
  160. group={group}
  161. project={project}
  162. organization={org}
  163. disabled={false}
  164. />
  165. </Fragment>,
  166. {organization: org}
  167. );
  168. userEvent.click(screen.getByLabelText('More Actions'));
  169. userEvent.click(await screen.findByText('Share'));
  170. const modal = screen.getByRole('dialog');
  171. expect(within(modal).getByText('Share Issue')).toBeInTheDocument();
  172. expect(updateMock).toHaveBeenCalled();
  173. });
  174. it('opens delete confirm modal from more actions dropdown', async () => {
  175. const org = {
  176. ...organization,
  177. access: [...organization.access, 'event:admin'],
  178. };
  179. MockApiClient.addMockResponse({
  180. url: `/projects/${org.slug}/${project.slug}/issues/`,
  181. method: 'PUT',
  182. body: {},
  183. });
  184. const deleteMock = MockApiClient.addMockResponse({
  185. url: `/projects/${org.slug}/${project.slug}/issues/`,
  186. method: 'DELETE',
  187. body: {},
  188. });
  189. render(
  190. <Fragment>
  191. <GlobalModal />
  192. <GroupActions
  193. group={group}
  194. project={project}
  195. organization={org}
  196. disabled={false}
  197. />
  198. </Fragment>,
  199. {organization: org}
  200. );
  201. userEvent.click(screen.getByLabelText('More Actions'));
  202. userEvent.click(await screen.findByRole('menuitemradio', {name: 'Delete'}));
  203. const modal = screen.getByRole('dialog');
  204. expect(
  205. within(modal).getByText(/Deleting this issue is permanent/)
  206. ).toBeInTheDocument();
  207. userEvent.click(within(modal).getByRole('button', {name: 'Delete'}));
  208. expect(deleteMock).toHaveBeenCalled();
  209. expect(browserHistory.push).toHaveBeenCalledWith({
  210. pathname: `/organizations/${organization.slug}/issues/`,
  211. query: {project: project.id},
  212. });
  213. });
  214. it('resolves and unresolves issue', () => {
  215. const issuesApi = MockApiClient.addMockResponse({
  216. url: `/projects/${organization.slug}/project/issues/`,
  217. method: 'PUT',
  218. body: {...group, status: 'resolved'},
  219. });
  220. const {rerender} = render(
  221. <GroupActions
  222. group={group}
  223. project={project}
  224. organization={organization}
  225. disabled={false}
  226. />,
  227. {organization}
  228. );
  229. userEvent.click(screen.getByRole('button', {name: 'Resolve'}));
  230. expect(issuesApi).toHaveBeenCalledWith(
  231. `/projects/${organization.slug}/project/issues/`,
  232. expect.objectContaining({data: {status: 'resolved', statusDetails: {}}})
  233. );
  234. rerender(
  235. <GroupActions
  236. group={{...group, status: 'resolved'}}
  237. project={project}
  238. organization={organization}
  239. disabled={false}
  240. />
  241. );
  242. userEvent.click(screen.getByRole('button', {name: 'Resolved'}));
  243. expect(issuesApi).toHaveBeenCalledWith(
  244. `/projects/${organization.slug}/project/issues/`,
  245. expect.objectContaining({data: {status: 'unresolved', statusDetails: {}}})
  246. );
  247. });
  248. });