platform.spec.jsx 2.6 KB

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