shareModal.spec.tsx 2.4 KB

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