shareModal.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 on open', 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. expect(await screen.findByRole('button', {name: 'Copy Link'})).toBeInTheDocument();
  44. expect(issuesApi).toHaveBeenCalledTimes(1);
  45. expect(onToggle).toHaveBeenCalledTimes(1);
  46. });
  47. it('should unshare', async () => {
  48. const group = GroupFixture({isPublic: true, shareId: '12345'});
  49. GroupStore.add([group]);
  50. const issuesApi = MockApiClient.addMockResponse({
  51. url: `/projects/${organization.slug}/${project.slug}/issues/`,
  52. method: 'PUT',
  53. body: {...group, isPublic: false, shareId: null},
  54. });
  55. renderGlobalModal();
  56. act(() =>
  57. openModal(modalProps => (
  58. <ShareIssueModal
  59. {...modalProps}
  60. groupId={group.id}
  61. organization={organization}
  62. projectSlug={project.slug}
  63. onToggle={onToggle}
  64. />
  65. ))
  66. );
  67. await userEvent.click(screen.getByLabelText('Unshare'));
  68. expect(await screen.findByRole('button', {name: 'Close'})).toBeInTheDocument();
  69. expect(issuesApi).toHaveBeenCalledTimes(1);
  70. expect(onToggle).toHaveBeenCalledTimes(1);
  71. });
  72. });