teamAccessRequestModal.spec.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import styled from '@emotion/styled';
  2. import {MemberFixture} from 'sentry-fixture/member';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {TeamFixture} from 'sentry-fixture/team';
  5. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  6. import {makeCloseButton} from 'sentry/components/globalModal/components';
  7. import type {CreateTeamAccessRequestModalProps} from 'sentry/components/modals/teamAccessRequestModal';
  8. import TeamAccessRequestModal from 'sentry/components/modals/teamAccessRequestModal';
  9. describe('TeamAccessRequestModal', function () {
  10. let createMock;
  11. const closeModal = jest.fn();
  12. const orgId = OrganizationFixture().slug;
  13. const memberId = MemberFixture().id;
  14. const teamId = TeamFixture().slug;
  15. const styledWrapper = styled(c => c.children);
  16. const modalRenderProps: CreateTeamAccessRequestModalProps = {
  17. Body: styledWrapper(),
  18. Footer: styledWrapper(),
  19. Header: p => <span>{p.children}</span>,
  20. closeModal,
  21. orgId,
  22. teamId,
  23. memberId,
  24. CloseButton: makeCloseButton(() => {}),
  25. api: new MockApiClient(),
  26. };
  27. function renderComponent() {
  28. return render(<TeamAccessRequestModal {...modalRenderProps} />);
  29. }
  30. beforeEach(function () {
  31. MockApiClient.clearMockResponses();
  32. createMock = MockApiClient.addMockResponse({
  33. url: `/organizations/${orgId}/members/${memberId}/teams/${teamId}/`,
  34. method: 'POST',
  35. });
  36. });
  37. it('renders', function () {
  38. const {container} = renderComponent();
  39. expect(container).toHaveTextContent(
  40. `You do not have permission to add members to the #${teamId} team, but we will send a request to your organization admins for approval.`
  41. );
  42. });
  43. it('creates access request on continue', async function () {
  44. renderComponent();
  45. await userEvent.click(screen.getByRole('button', {name: 'Continue'}));
  46. expect(createMock).toHaveBeenCalled();
  47. });
  48. it('closes modal on cancel', async function () {
  49. renderComponent();
  50. await userEvent.click(screen.getByRole('button', {name: 'Cancel'}));
  51. expect(createMock).not.toHaveBeenCalled();
  52. expect(closeModal).toHaveBeenCalled();
  53. });
  54. });