createTeamModal.spec.jsx 1.2 KB

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