index.spec.tsx 4.1 KB

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