shareModal.spec.tsx 2.3 KB

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