shareModal.spec.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {GroupFixture} from 'sentry-fixture/group';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {act, renderGlobalModal, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import {openModal} from 'sentry/actionCreators/modal';
  6. import GroupStore from 'sentry/stores/groupStore';
  7. import ModalStore from 'sentry/stores/modalStore';
  8. import ShareIssueModal from 'sentry/views/issueDetails/actions/shareModal';
  9. describe('shareModal', () => {
  10. const project = ProjectFixture();
  11. const organization = OrganizationFixture();
  12. const onToggle = jest.fn();
  13. beforeEach(() => {
  14. GroupStore.init();
  15. });
  16. afterEach(() => {
  17. ModalStore.reset();
  18. GroupStore.reset();
  19. MockApiClient.clearMockResponses();
  20. jest.clearAllMocks();
  21. });
  22. it('should share', async () => {
  23. const group = GroupFixture();
  24. GroupStore.add([group]);
  25. const issuesApi = MockApiClient.addMockResponse({
  26. url: `/projects/${organization.slug}/${project.slug}/issues/`,
  27. method: 'PUT',
  28. body: {...group, isPublic: true, shareId: '12345'},
  29. });
  30. renderGlobalModal();
  31. act(() =>
  32. openModal(modalProps => (
  33. <ShareIssueModal
  34. {...modalProps}
  35. groupId={group.id}
  36. organization={organization}
  37. projectSlug={project.slug}
  38. onToggle={onToggle}
  39. />
  40. ))
  41. );
  42. expect(screen.getByText('Share Issue')).toBeInTheDocument();
  43. await userEvent.click(screen.getByLabelText('Share'));
  44. expect(await screen.findByRole('button', {name: 'Copy Link'})).toBeInTheDocument();
  45. expect(issuesApi).toHaveBeenCalledTimes(1);
  46. expect(onToggle).toHaveBeenCalledTimes(1);
  47. });
  48. it('should unshare', async () => {
  49. const group = GroupFixture({isPublic: true, shareId: '12345'});
  50. GroupStore.add([group]);
  51. const issuesApi = MockApiClient.addMockResponse({
  52. url: `/projects/${organization.slug}/${project.slug}/issues/`,
  53. method: 'PUT',
  54. body: {...group, isPublic: false, shareId: null},
  55. });
  56. renderGlobalModal();
  57. act(() =>
  58. openModal(modalProps => (
  59. <ShareIssueModal
  60. {...modalProps}
  61. groupId={group.id}
  62. organization={organization}
  63. projectSlug={project.slug}
  64. onToggle={onToggle}
  65. />
  66. ))
  67. );
  68. await userEvent.click(screen.getByLabelText('Unshare'));
  69. expect(await screen.findByRole('button', {name: 'Close'})).toBeInTheDocument();
  70. expect(issuesApi).toHaveBeenCalledTimes(1);
  71. expect(onToggle).toHaveBeenCalledTimes(1);
  72. });
  73. });