index.spec.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {render, screen, userEvent, waitFor} 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. render(<OrganizationCreate />);
  15. });
  16. it('renders with terms', function () {
  17. ConfigStore.set('termsUrl', 'https://example.com/terms');
  18. ConfigStore.set('privacyUrl', 'https://example.com/privacy');
  19. render(<OrganizationCreate />);
  20. });
  21. it('creates a new org', async function () {
  22. const orgCreateMock = MockApiClient.addMockResponse({
  23. url: '/organizations/',
  24. method: 'POST',
  25. body: TestStubs.Organization(),
  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. await userEvent.type(screen.getByPlaceholderText('e.g. My Company'), 'Good Burger');
  32. await userEvent.click(
  33. screen.getByRole('checkbox', {
  34. name: 'I agree to the Terms of Service and the Privacy Policy',
  35. })
  36. );
  37. await userEvent.click(screen.getByText('Create Organization'));
  38. await waitFor(() => {
  39. expect(orgCreateMock).toHaveBeenCalledWith(
  40. '/organizations/',
  41. expect.objectContaining({
  42. data: {agreeTerms: true, defaultTeam: true, name: 'Good Burger'},
  43. })
  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', async 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. await userEvent.type(screen.getByPlaceholderText('e.g. My Company'), 'Good Burger');
  64. await userEvent.click(
  65. screen.getByRole('checkbox', {
  66. name: 'I agree to the Terms of Service and the Privacy Policy',
  67. })
  68. );
  69. await userEvent.click(screen.getByText('Create Organization'));
  70. await waitFor(() => {
  71. expect(orgCreateMock).toHaveBeenCalledWith(
  72. '/organizations/',
  73. expect.objectContaining({
  74. data: {agreeTerms: true, defaultTeam: true, name: 'Good Burger'},
  75. })
  76. );
  77. });
  78. expect(window.location.assign).toHaveBeenCalledTimes(1);
  79. expect(window.location.assign).toHaveBeenCalledWith(
  80. 'https://org-slug.sentry.io/projects/new/'
  81. );
  82. });
  83. });