index.spec.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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');
  7. ConfigStore.get('privacyUrl');
  8. });
  9. afterEach(() => {
  10. MockApiClient.clearMockResponses();
  11. jest.resetAllMocks();
  12. });
  13. it('renders without terms', function () {
  14. const wrapper = render(<OrganizationCreate />);
  15. expect(wrapper.container).toSnapshot();
  16. });
  17. it('renders with terms', function () {
  18. ConfigStore.set('termsUrl', 'https://example.com/terms');
  19. ConfigStore.set('privacyUrl', 'https://example.com/privacy');
  20. const wrapper = render(<OrganizationCreate />);
  21. expect(wrapper.container).toSnapshot();
  22. });
  23. it('creates a new org', function () {
  24. const orgCreateMock = MockApiClient.addMockResponse({
  25. url: '/organizations/',
  26. method: 'POST',
  27. body: TestStubs.Organization(),
  28. });
  29. ConfigStore.set('termsUrl', 'https://example.com/terms');
  30. ConfigStore.set('privacyUrl', 'https://example.com/privacy');
  31. render(<OrganizationCreate />);
  32. expect(screen.getByText('Create a New Organization')).toBeInTheDocument();
  33. userEvent.paste(screen.getByPlaceholderText('e.g. My Company'), 'Good Burger');
  34. userEvent.click(
  35. screen.getByRole('checkbox', {
  36. name: 'I agree to the Terms of Service and the Privacy Policy',
  37. })
  38. );
  39. userEvent.click(screen.getByText('Create Organization'));
  40. expect(orgCreateMock).toHaveBeenCalledWith(
  41. '/organizations/',
  42. expect.objectContaining({
  43. data: {agreeTerms: true, defaultTeam: true, name: 'Good Burger'},
  44. })
  45. );
  46. expect(window.location.assign).toHaveBeenCalledTimes(1);
  47. expect(window.location.assign).toHaveBeenCalledWith(
  48. '/organizations/org-slug/projects/new/'
  49. );
  50. });
  51. it('creates a new org with customer domain feature', function () {
  52. const orgCreateMock = MockApiClient.addMockResponse({
  53. url: '/organizations/',
  54. method: 'POST',
  55. body: TestStubs.Organization({
  56. features: ['customer-domains'],
  57. }),
  58. });
  59. ConfigStore.set('termsUrl', 'https://example.com/terms');
  60. ConfigStore.set('privacyUrl', 'https://example.com/privacy');
  61. render(<OrganizationCreate />);
  62. expect(screen.getByText('Create a New Organization')).toBeInTheDocument();
  63. userEvent.paste(screen.getByPlaceholderText('e.g. My Company'), 'Good Burger');
  64. userEvent.click(
  65. screen.getByRole('checkbox', {
  66. name: 'I agree to the Terms of Service and the Privacy Policy',
  67. })
  68. );
  69. userEvent.click(screen.getByText('Create Organization'));
  70. expect(orgCreateMock).toHaveBeenCalledWith(
  71. '/organizations/',
  72. expect.objectContaining({
  73. data: {agreeTerms: true, defaultTeam: true, name: 'Good Burger'},
  74. })
  75. );
  76. expect(window.location.assign).toHaveBeenCalledTimes(1);
  77. expect(window.location.assign).toHaveBeenCalledWith(
  78. 'https://org-slug.sentry.io/projects/new/'
  79. );
  80. });
  81. });