teamAccessRequestModal.spec.tsx 2.0 KB

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