123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import {act, renderGlobalModal, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {openModal} from 'sentry/actionCreators/modal';
- import GroupStore from 'sentry/stores/groupStore';
- import ModalStore from 'sentry/stores/modalStore';
- import ShareIssueModal from 'sentry/views/issueDetails/actions/shareModal';
- describe('shareModal', () => {
- const project = TestStubs.Project();
- const organization = TestStubs.Organization();
- const onToggle = jest.fn();
- beforeEach(() => {
- GroupStore.init();
- });
- afterEach(() => {
- ModalStore.reset();
- GroupStore.reset();
- MockApiClient.clearMockResponses();
- jest.clearAllMocks();
- });
- it('should share on open', async () => {
- const group = TestStubs.Group();
- GroupStore.add([group]);
- const issuesApi = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/issues/`,
- method: 'PUT',
- body: {...group, isPublic: true, shareId: '12345'},
- });
- renderGlobalModal();
- act(() =>
- openModal(modalProps => (
- <ShareIssueModal
- {...modalProps}
- groupId={group.id}
- organization={organization}
- projectSlug={project.slug}
- onToggle={onToggle}
- />
- ))
- );
- expect(screen.getByText('Share Issue')).toBeInTheDocument();
- expect(await screen.findByRole('button', {name: 'Copy Link'})).toBeInTheDocument();
- expect(issuesApi).toHaveBeenCalledTimes(1);
- expect(onToggle).toHaveBeenCalledTimes(1);
- });
- it('should unshare', async () => {
- const group = TestStubs.Group({isPublic: true, shareId: '12345'});
- GroupStore.add([group]);
- const issuesApi = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/issues/`,
- method: 'PUT',
- body: {...group, isPublic: false, shareId: null},
- });
- renderGlobalModal();
- act(() =>
- openModal(modalProps => (
- <ShareIssueModal
- {...modalProps}
- groupId={group.id}
- organization={organization}
- projectSlug={project.slug}
- onToggle={onToggle}
- />
- ))
- );
- await userEvent.click(screen.getByLabelText('Unshare'));
- expect(await screen.findByRole('button', {name: 'Close'})).toBeInTheDocument();
- expect(issuesApi).toHaveBeenCalledTimes(1);
- expect(onToggle).toHaveBeenCalledTimes(1);
- });
- });
|