123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import styled from '@emotion/styled';
- import {Organization} from 'sentry-fixture/organization';
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {makeCloseButton} from 'sentry/components/globalModal/components';
- import TeamAccessRequestModal, {
- CreateTeamAccessRequestModalProps,
- } from 'sentry/components/modals/teamAccessRequestModal';
- describe('TeamAccessRequestModal', function () {
- let createMock;
- const closeModal = jest.fn();
- const orgId = Organization().slug;
- const memberId = TestStubs.Member().id;
- const teamId = TestStubs.Team().slug;
- const styledWrapper = styled(c => c.children);
- const modalRenderProps: CreateTeamAccessRequestModalProps = {
- Body: styledWrapper(),
- Footer: styledWrapper(),
- Header: p => <span>{p.children}</span>,
- closeModal,
- orgId,
- teamId,
- memberId,
- CloseButton: makeCloseButton(() => {}),
- api: new MockApiClient(),
- };
- function renderComponent() {
- return render(<TeamAccessRequestModal {...modalRenderProps} />);
- }
- beforeEach(function () {
- MockApiClient.clearMockResponses();
- createMock = MockApiClient.addMockResponse({
- url: `/organizations/${orgId}/members/${memberId}/teams/${teamId}/`,
- method: 'POST',
- });
- });
- it('renders', function () {
- const {container} = renderComponent();
- expect(container).toHaveTextContent(
- `You do not have permission to add members to the #${teamId} team, but we will send a request to your organization admins for approval.`
- );
- });
- it('creates access request on continue', async function () {
- renderComponent();
- await userEvent.click(screen.getByRole('button', {name: 'Continue'}));
- expect(createMock).toHaveBeenCalled();
- });
- it('closes modal on cancel', async function () {
- renderComponent();
- await userEvent.click(screen.getByRole('button', {name: 'Cancel'}));
- expect(createMock).not.toHaveBeenCalled();
- expect(closeModal).toHaveBeenCalled();
- });
- });
|