platform.spec.jsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import {createProject} from 'sentry/actionCreators/projects';
  3. import TeamStore from 'sentry/stores/teamStore';
  4. import OnboardingPlatform from 'sentry/views/onboarding/platform';
  5. jest.mock('sentry/actionCreators/projects');
  6. describe('OnboardingWelcome', function () {
  7. afterEach(() => {
  8. jest.resetAllMocks();
  9. });
  10. it('calls onUpdate when setting the platform', function () {
  11. const onUpdate = jest.fn();
  12. render(<OnboardingPlatform active onUpdate={onUpdate} />);
  13. userEvent.click(screen.getByTestId('platform-dotnet'));
  14. expect(onUpdate).toHaveBeenCalled();
  15. });
  16. it('creates a project when no project exists', async function () {
  17. const onComplete = jest.fn();
  18. const wrapper = render(<OnboardingPlatform active onComplete={onComplete} />);
  19. // Select a platform to create
  20. wrapper.rerender(
  21. <OnboardingPlatform active onComplete={onComplete} platform="dotnet" />
  22. );
  23. act(() => {
  24. TeamStore.loadInitialData([{id: '1', slug: 'team-slug'}]);
  25. });
  26. const button = screen.getByRole('button', {name: 'Create Project'});
  27. expect(button).toBeInTheDocument();
  28. expect(button).toBeEnabled();
  29. let resolveProjectCreate;
  30. createProject.mockReturnValue(
  31. new Promise(resolve => (resolveProjectCreate = resolve))
  32. );
  33. // Create the project
  34. userEvent.click(button);
  35. expect(button).toHaveTextContent('Creating Project...');
  36. // Project completed creation (tick for async completion)
  37. resolveProjectCreate({id: 1, slug: 'test-project'});
  38. wrapper.rerender(
  39. <OnboardingPlatform active={false} onComplete={onComplete} platform="dotnet" />
  40. );
  41. expect(button).toHaveTextContent('Project Created');
  42. await waitFor(() => expect(onComplete).toHaveBeenCalled());
  43. });
  44. it('does not create a project if one already exists', async function () {
  45. const onComplete = jest.fn();
  46. render(
  47. <OnboardingPlatform
  48. active
  49. project={{id: '1', slug: 'test'}}
  50. platform="dotnet"
  51. onComplete={onComplete}
  52. />
  53. );
  54. act(() => {
  55. TeamStore.loadInitialData([{id: '1', slug: 'team-slug'}]);
  56. });
  57. const button = screen.getByRole('button', {name: 'Set Up Your Project'});
  58. expect(button).toBeInTheDocument();
  59. expect(button).toBeEnabled();
  60. // Create the project
  61. userEvent.click(button);
  62. expect(button).toBeDisabled();
  63. expect(createProject).not.toHaveBeenCalled();
  64. await waitFor(() => expect(onComplete).toHaveBeenCalled());
  65. });
  66. });