createTeamModal.spec.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import styled from '@emotion/styled';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import {createTeam} from 'sentry/actionCreators/teams';
  5. import {makeCloseButton} from 'sentry/components/globalModal/components';
  6. import CreateTeamModal from 'sentry/components/modals/createTeamModal';
  7. jest.mock('sentry/actionCreators/teams', () => ({
  8. createTeam: jest.fn((...args: any[]) => new Promise(resolve => resolve(args))),
  9. }));
  10. describe('CreateTeamModal', function () {
  11. const org = OrganizationFixture();
  12. const closeModal = jest.fn();
  13. const onClose = jest.fn();
  14. beforeEach(function () {
  15. onClose.mockReset();
  16. });
  17. it('calls createTeam action creator on submit', async function () {
  18. const styledWrapper = styled(c => c.children);
  19. render(
  20. <CreateTeamModal
  21. Body={styledWrapper()}
  22. Footer={styledWrapper()}
  23. Header={p => <span>{p.children}</span>}
  24. organization={org}
  25. closeModal={closeModal}
  26. onClose={onClose}
  27. CloseButton={makeCloseButton(() => {})}
  28. />
  29. );
  30. await userEvent.type(screen.getByText('Team Name'), 'new-team');
  31. await userEvent.click(screen.getByLabelText('Create Team'));
  32. await waitFor(() => expect(createTeam).toHaveBeenCalledTimes(1));
  33. expect(onClose).toHaveBeenCalled();
  34. expect(closeModal).toHaveBeenCalled();
  35. });
  36. });