actions.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import ConfigStore from 'sentry/stores/configStore';
  3. import ModalStore from 'sentry/stores/modalStore';
  4. import GroupActions from 'sentry/views/organizationGroupDetails/actions';
  5. const group = TestStubs.Group({
  6. id: '1337',
  7. pluginActions: [],
  8. pluginIssues: [],
  9. });
  10. const project = TestStubs.ProjectDetails({
  11. id: '2448',
  12. name: 'project name',
  13. slug: 'project',
  14. });
  15. const organization = TestStubs.Organization({
  16. id: '4660',
  17. slug: 'org',
  18. features: ['reprocessing-v2'],
  19. });
  20. describe('GroupActions', function () {
  21. beforeEach(function () {
  22. ConfigStore.init();
  23. jest.spyOn(ConfigStore, 'get').mockImplementation(() => []);
  24. });
  25. afterEach(() => {
  26. ConfigStore.teardown();
  27. });
  28. describe('render()', function () {
  29. it('renders correctly', function () {
  30. const wrapper = render(
  31. <GroupActions
  32. group={group}
  33. project={project}
  34. organization={organization}
  35. disabled={false}
  36. />
  37. );
  38. expect(wrapper.container).toSnapshot();
  39. });
  40. });
  41. describe('subscribing', function () {
  42. let issuesApi: any;
  43. beforeEach(function () {
  44. issuesApi = MockApiClient.addMockResponse({
  45. url: '/projects/org/project/issues/',
  46. method: 'PUT',
  47. body: TestStubs.Group({isSubscribed: false}),
  48. });
  49. });
  50. it('can subscribe', function () {
  51. render(
  52. <GroupActions
  53. group={group}
  54. project={project}
  55. organization={organization}
  56. disabled={false}
  57. />
  58. );
  59. userEvent.click(screen.getByRole('button', {name: 'Subscribe'}));
  60. expect(issuesApi).toHaveBeenCalledWith(
  61. expect.anything(),
  62. expect.objectContaining({
  63. data: {isSubscribed: true},
  64. })
  65. );
  66. });
  67. });
  68. describe('bookmarking', function () {
  69. let issuesApi: any;
  70. beforeEach(function () {
  71. issuesApi = MockApiClient.addMockResponse({
  72. url: '/projects/org/project/issues/',
  73. method: 'PUT',
  74. body: TestStubs.Group({isBookmarked: false}),
  75. });
  76. });
  77. it('can bookmark', async function () {
  78. render(
  79. <GroupActions
  80. group={group}
  81. project={project}
  82. organization={organization}
  83. disabled={false}
  84. />
  85. );
  86. userEvent.click(screen.getByLabelText('More Actions'));
  87. const bookmark = await screen.findByTestId('bookmark');
  88. userEvent.click(bookmark);
  89. expect(issuesApi).toHaveBeenCalledWith(
  90. expect.anything(),
  91. expect.objectContaining({
  92. data: {isBookmarked: true},
  93. })
  94. );
  95. });
  96. });
  97. describe('reprocessing', function () {
  98. it('renders ReprocessAction component if org has feature flag reprocessing-v2 and native exception event', async function () {
  99. const event = TestStubs.EventStacktraceException({
  100. platform: 'native',
  101. });
  102. render(
  103. <GroupActions
  104. group={group}
  105. project={project}
  106. organization={organization}
  107. event={event}
  108. disabled={false}
  109. />
  110. );
  111. userEvent.click(screen.getByLabelText('More Actions'));
  112. const reprocessActionButton = await screen.findByTestId('reprocess');
  113. expect(reprocessActionButton).toBeInTheDocument();
  114. });
  115. it('open dialog by clicking on the ReprocessAction component', async function () {
  116. const event = TestStubs.EventStacktraceException({
  117. platform: 'native',
  118. });
  119. render(
  120. <GroupActions
  121. group={group}
  122. project={project}
  123. organization={organization}
  124. event={event}
  125. disabled={false}
  126. />
  127. );
  128. const onReprocessEventFunc = jest.spyOn(ModalStore, 'openModal');
  129. userEvent.click(screen.getByLabelText('More Actions'));
  130. const reprocessActionButton = await screen.findByTestId('reprocess');
  131. expect(reprocessActionButton).toBeInTheDocument();
  132. userEvent.click(reprocessActionButton);
  133. await waitFor(() => expect(onReprocessEventFunc).toHaveBeenCalled());
  134. });
  135. });
  136. });