organizationCreate.spec.jsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import ConfigStore from 'sentry/stores/configStore';
  3. import OrganizationCreate from 'sentry/views/organizationCreate';
  4. describe('OrganizationCreate', function () {
  5. beforeEach(() => {
  6. ConfigStore.get('termsUrl', null);
  7. ConfigStore.get('privacyUrl', null);
  8. });
  9. afterEach(() => {
  10. MockApiClient.clearMockResponses();
  11. });
  12. it('renders without terms', function () {
  13. const wrapper = render(<OrganizationCreate />);
  14. expect(wrapper.container).toSnapshot();
  15. });
  16. it('renders with terms', function () {
  17. ConfigStore.set('termsUrl', 'https://example.com/terms');
  18. ConfigStore.set('privacyUrl', 'https://example.com/privacy');
  19. const wrapper = render(<OrganizationCreate />);
  20. expect(wrapper.container).toSnapshot();
  21. });
  22. it('creates a new org', function () {
  23. const orgCreateMock = MockApiClient.addMockResponse({
  24. url: '/organizations/',
  25. method: 'POST',
  26. });
  27. ConfigStore.set('termsUrl', 'https://example.com/terms');
  28. ConfigStore.set('privacyUrl', 'https://example.com/privacy');
  29. render(<OrganizationCreate />);
  30. expect(screen.getByText('Create a New Organization')).toBeInTheDocument();
  31. userEvent.paste(screen.getByPlaceholderText('e.g. My Company'), 'Good Burger');
  32. userEvent.click(
  33. screen.getByRole('checkbox', {
  34. name: 'I agree to the Terms of Service and the Privacy Policy',
  35. })
  36. );
  37. userEvent.click(screen.getByText('Create Organization'));
  38. expect(orgCreateMock).toHaveBeenCalledWith(
  39. '/organizations/',
  40. expect.objectContaining({
  41. data: {agreeTerms: true, defaultTeam: true, name: 'Good Burger'},
  42. })
  43. );
  44. });
  45. });