index.spec.tsx 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. 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', async 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. await userEvent.type(screen.getByPlaceholderText('e.g. My Company'), 'Good Burger');
  34. await userEvent.click(
  35. screen.getByRole('checkbox', {
  36. name: 'I agree to the Terms of Service and the Privacy Policy',
  37. })
  38. );
  39. await userEvent.click(screen.getByText('Create Organization'));
  40. await waitFor(() => {
  41. expect(orgCreateMock).toHaveBeenCalledWith(
  42. '/organizations/',
  43. expect.objectContaining({
  44. data: {agreeTerms: true, defaultTeam: true, name: 'Good Burger'},
  45. })
  46. );
  47. });
  48. expect(window.location.assign).toHaveBeenCalledTimes(1);
  49. expect(window.location.assign).toHaveBeenCalledWith(
  50. '/organizations/org-slug/projects/new/'
  51. );
  52. });
  53. it('creates a new org with customer domain feature', async function () {
  54. const orgCreateMock = MockApiClient.addMockResponse({
  55. url: '/organizations/',
  56. method: 'POST',
  57. body: TestStubs.Organization({
  58. features: ['customer-domains'],
  59. }),
  60. });
  61. ConfigStore.set('termsUrl', 'https://example.com/terms');
  62. ConfigStore.set('privacyUrl', 'https://example.com/privacy');
  63. render(<OrganizationCreate />);
  64. expect(screen.getByText('Create a New Organization')).toBeInTheDocument();
  65. await userEvent.type(screen.getByPlaceholderText('e.g. My Company'), 'Good Burger');
  66. await userEvent.click(
  67. screen.getByRole('checkbox', {
  68. name: 'I agree to the Terms of Service and the Privacy Policy',
  69. })
  70. );
  71. await userEvent.click(screen.getByText('Create Organization'));
  72. await waitFor(() => {
  73. expect(orgCreateMock).toHaveBeenCalledWith(
  74. '/organizations/',
  75. expect.objectContaining({
  76. data: {agreeTerms: true, defaultTeam: true, name: 'Good Burger'},
  77. })
  78. );
  79. });
  80. expect(window.location.assign).toHaveBeenCalledTimes(1);
  81. expect(window.location.assign).toHaveBeenCalledWith(
  82. 'https://org-slug.sentry.io/projects/new/'
  83. );
  84. });
  85. });