actions.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import ModalActions from 'sentry/actions/modalActions';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. import {Event} from 'sentry/types/event';
  5. import GroupActions from 'sentry/views/organizationGroupDetails/actions';
  6. const group = TestStubs.Group({
  7. id: '1337',
  8. pluginActions: [],
  9. pluginIssues: [],
  10. });
  11. const project = TestStubs.ProjectDetails({
  12. id: '2448',
  13. name: 'project name',
  14. slug: 'project',
  15. });
  16. const organization = TestStubs.Organization({
  17. id: '4660',
  18. slug: 'org',
  19. features: ['reprocessing-v2'],
  20. });
  21. function renderComponent(event?: Event) {
  22. return mountWithTheme(
  23. <GroupActions
  24. group={group}
  25. project={project}
  26. organization={organization}
  27. event={event}
  28. disabled={false}
  29. />
  30. );
  31. }
  32. describe('GroupActions', function () {
  33. beforeEach(function () {
  34. jest.spyOn(ConfigStore, 'get').mockImplementation(() => []);
  35. });
  36. describe('render()', function () {
  37. it('renders correctly', function () {
  38. const wrapper = renderComponent();
  39. expect(wrapper).toSnapshot();
  40. });
  41. });
  42. describe('subscribing', function () {
  43. let issuesApi: any;
  44. beforeEach(function () {
  45. issuesApi = MockApiClient.addMockResponse({
  46. url: '/projects/org/project/issues/',
  47. method: 'PUT',
  48. body: TestStubs.Group({isSubscribed: false}),
  49. });
  50. });
  51. it('can subscribe', function () {
  52. const wrapper = renderComponent();
  53. const btn = wrapper.find('button[aria-label="Subscribe"]');
  54. btn.simulate('click');
  55. expect(issuesApi).toHaveBeenCalledWith(
  56. expect.anything(),
  57. expect.objectContaining({
  58. data: {isSubscribed: true},
  59. })
  60. );
  61. });
  62. });
  63. describe('bookmarking', function () {
  64. let issuesApi: any;
  65. beforeEach(function () {
  66. issuesApi = MockApiClient.addMockResponse({
  67. url: '/projects/org/project/issues/',
  68. method: 'PUT',
  69. body: TestStubs.Group({isBookmarked: false}),
  70. });
  71. });
  72. it('can bookmark', function () {
  73. const wrapper = renderComponent();
  74. const btn = wrapper.find('button[aria-label="Bookmark"]');
  75. btn.simulate('click');
  76. expect(issuesApi).toHaveBeenCalledWith(
  77. expect.anything(),
  78. expect.objectContaining({
  79. data: {isBookmarked: true},
  80. })
  81. );
  82. });
  83. });
  84. describe('reprocessing', function () {
  85. it('renders ReprocessAction component if org has feature flag reprocessing-v2', function () {
  86. const wrapper = renderComponent();
  87. const reprocessActionButton = wrapper.find('ReprocessAction button');
  88. expect(reprocessActionButton).toBeTruthy();
  89. });
  90. it('open dialog by clicking on the ReprocessAction component', async function () {
  91. const event = TestStubs.EventStacktraceException({
  92. platform: 'native',
  93. });
  94. const onReprocessEventFunc = jest.spyOn(ModalActions, 'openModal');
  95. const wrapper = renderComponent(event);
  96. const reprocessActionButton = wrapper.find('ReprocessAction button');
  97. expect(reprocessActionButton).toBeTruthy();
  98. reprocessActionButton.simulate('click');
  99. await tick();
  100. wrapper.update();
  101. expect(onReprocessEventFunc).toHaveBeenCalled();
  102. });
  103. });
  104. });