123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {
- render,
- renderGlobalModal,
- screen,
- userEvent,
- } from 'sentry-test/reactTestingLibrary';
- import {OnboardingContextProvider} from 'sentry/components/onboarding/onboardingContext';
- import {PlatformKey} from 'sentry/data/platformCategories';
- import OrganizationStore from 'sentry/stores/organizationStore';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import {OnboardingProjectStatus, Project} from 'sentry/types';
- import Onboarding from 'sentry/views/onboarding/onboarding';
- describe('Onboarding', function () {
- afterEach(function () {
- MockApiClient.clearMockResponses();
- });
- it('renders the welcome page', function () {
- const routeParams = {
- step: 'welcome',
- };
- const {router, route, routerContext} = initializeOrg({
- ...initializeOrg(),
- router: {
- params: routeParams,
- },
- });
- render(
- <OnboardingContextProvider>
- <Onboarding
- router={router}
- location={router.location}
- params={routeParams}
- routes={router.routes}
- routeParams={router.params}
- route={route}
- />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- }
- );
- expect(screen.getByLabelText('Start')).toBeInTheDocument();
- expect(screen.getByLabelText('Invite Team')).toBeInTheDocument();
- });
- it('renders the select platform step', async function () {
- const routeParams = {
- step: 'select-platform',
- };
- const {router, route, routerContext, organization} = initializeOrg({
- ...initializeOrg(),
- router: {
- params: routeParams,
- },
- });
- OrganizationStore.onUpdate(organization);
- render(
- <OnboardingContextProvider>
- <Onboarding
- router={router}
- location={router.location}
- params={routeParams}
- routes={router.routes}
- routeParams={router.params}
- route={route}
- />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- }
- );
- expect(
- await screen.findByText('Select the platform you want to monitor')
- ).toBeInTheDocument();
- });
- it('renders the setup docs step', async function () {
- const nextJsProject: Project = TestStubs.Project({
- platform: 'javascript-nextjs',
- id: '2',
- slug: 'javascript-nextjs-slug',
- });
- const routeParams = {
- step: 'setup-docs',
- };
- const {router, route, routerContext, organization} = initializeOrg({
- ...initializeOrg(),
- router: {
- params: routeParams,
- },
- });
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${nextJsProject.slug}/docs/javascript-nextjs-with-error-monitoring/`,
- body: null,
- });
- MockApiClient.addMockResponse({
- url: `/projects/org-slug/${nextJsProject.slug}/`,
- body: [nextJsProject],
- });
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${nextJsProject.slug}/issues/`,
- body: [],
- });
- ProjectsStore.loadInitialData([nextJsProject]);
- OrganizationStore.onUpdate(organization);
- render(
- <OnboardingContextProvider
- value={{
- selectedSDK: {
- key: nextJsProject.slug as PlatformKey,
- type: 'framework',
- language: 'javascript',
- category: 'browser',
- },
- projects: {
- [nextJsProject.id]: {
- slug: nextJsProject.slug,
- status: OnboardingProjectStatus.WAITING,
- firstIssueId: undefined,
- },
- },
- }}
- >
- <Onboarding
- router={router}
- location={router.location}
- params={routeParams}
- routes={router.routes}
- routeParams={router.params}
- route={route}
- />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- }
- );
- expect(await screen.findByText('Configure Next.js SDK')).toBeInTheDocument();
- });
- it('renders framework selection modal if vanilla js is selected', async function () {
- const routeParams = {
- step: 'select-platform',
- };
- const {router, route, routerContext, organization} = initializeOrg({
- ...initializeOrg(),
- organization: {
- ...initializeOrg().organization,
- features: ['onboarding-sdk-selection'],
- },
- router: {
- params: routeParams,
- },
- });
- render(
- <OnboardingContextProvider>
- <Onboarding
- router={router}
- location={router.location}
- params={routeParams}
- routes={router.routes}
- routeParams={router.params}
- route={route}
- />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- organization,
- }
- );
- renderGlobalModal();
- // Select the JavaScript platform
- await userEvent.click(screen.getByTestId('platform-javascript'));
- // Click on create project button
- await userEvent.click(screen.getByRole('button', {name: 'Create Project'}));
- // Modal is open
- await screen.findByText('Do you use a framework?');
- // Close modal
- await userEvent.click(screen.getByRole('button', {name: 'Skip'}));
- });
- it('does not render framework selection modal if vanilla js is NOT selected', async function () {
- const routeParams = {
- step: 'select-platform',
- };
- const {router, route, routerContext, organization} = initializeOrg({
- ...initializeOrg(),
- organization: {
- ...initializeOrg().organization,
- features: ['onboarding-sdk-selection'],
- },
- router: {
- params: routeParams,
- },
- });
- render(
- <OnboardingContextProvider>
- <Onboarding
- router={router}
- location={router.location}
- params={routeParams}
- routes={router.routes}
- routeParams={router.params}
- route={route}
- />
- </OnboardingContextProvider>,
- {
- context: routerContext,
- organization,
- }
- );
- // Select the React platform
- await userEvent.click(screen.getByTestId('platform-javascript-react'));
- // Click on create project button
- await userEvent.click(screen.getByRole('button', {name: 'Create Project'}));
- // Modal shall not be open
- expect(screen.queryByText('Do you use a framework?')).not.toBeInTheDocument();
- });
- });
|