profilingOnboardingModal.spec.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {ModalRenderProps} from 'sentry/actionCreators/modal';
  3. import {ProfilingOnboardingModal} from 'sentry/components/profiling/ProfilingOnboarding/profilingOnboardingModal';
  4. import ProjectStore from 'sentry/stores/projectsStore';
  5. import {Project} from 'sentry/types/project';
  6. const MockRenderModalProps: ModalRenderProps = {
  7. Body: ({children}) => <div>{children}</div>,
  8. Header: ({children}) => <div>{children}</div>,
  9. Footer: ({children}) => <div>{children}</div>,
  10. CloseButton: ({children}) => <div>{children}</div>,
  11. closeModal: jest.fn(),
  12. onDismiss: jest.fn(),
  13. } as unknown as ModalRenderProps;
  14. function selectProject(project: Project) {
  15. if (!project.name) {
  16. throw new Error(`Selected project requires a name, received ${project.name}`);
  17. }
  18. userEvent.click(screen.getAllByRole('textbox')[0]);
  19. userEvent.click(screen.getByText(project.name));
  20. }
  21. describe('ProfilingOnboarding', function () {
  22. beforeEach(() => {
  23. ProjectStore.teardown();
  24. });
  25. it('renders default step', () => {
  26. render(<ProfilingOnboardingModal {...MockRenderModalProps} />);
  27. expect(screen.getByText(/Select a Project/i)).toBeInTheDocument();
  28. });
  29. it('goes to next step and previous step if project is supported', () => {
  30. ProjectStore.loadInitialData([
  31. TestStubs.Project({name: 'iOS Project', platform: 'apple-ios'}),
  32. ]);
  33. render(<ProfilingOnboardingModal {...MockRenderModalProps} />);
  34. selectProject(TestStubs.Project({name: 'iOS Project'}));
  35. act(() => {
  36. userEvent.click(screen.getAllByText('Next')[0]);
  37. });
  38. expect(screen.getByText(/Step 2 of 2/i)).toBeInTheDocument();
  39. // Previous step
  40. act(() => {
  41. userEvent.click(screen.getAllByText('Back')[0]);
  42. });
  43. expect(screen.getByText(/Select a Project/i)).toBeInTheDocument();
  44. });
  45. it('does not allow going to next step if project is unsupported', () => {
  46. ProjectStore.loadInitialData([
  47. TestStubs.Project({name: 'javascript', platform: 'javascript'}),
  48. ]);
  49. render(<ProfilingOnboardingModal {...MockRenderModalProps} />);
  50. selectProject(TestStubs.Project({name: 'javascript'}));
  51. act(() => {
  52. userEvent.click(screen.getAllByText('Next')[0]);
  53. });
  54. expect(screen.getByRole('button', {name: /Next/i})).toBeDisabled();
  55. });
  56. });