12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import {GroupFixture} from 'sentry-fixture/group';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {ProjectFixture} from 'sentry-fixture/project';
- 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 = ProjectFixture();
- const organization = OrganizationFixture();
- const onToggle = jest.fn();
- beforeEach(() => {
- GroupStore.init();
- });
- afterEach(() => {
- ModalStore.reset();
- GroupStore.reset();
- MockApiClient.clearMockResponses();
- jest.clearAllMocks();
- });
- it('should share on open', async () => {
- const group = GroupFixture();
- 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 = GroupFixture({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);
- });
- });
|