index.spec.tsx 3.1 KB

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