Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { fireEvent, render, screen } from "@testing-library/react";
import type { ReactNode } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { PlanType } from "../store/onboarding-store";
import { OnboardingView } from "./onboarding-view";

const mocks = vi.hoisted(() => ({
push: vi.fn(),
selectedPlan: null as PlanType | null,
}));

vi.mock("next/navigation", () => ({
useRouter: () => ({ push: mocks.push, replace: vi.fn() }),
usePathname: () => "/onboarding/getting-started",
}));

vi.mock("posthog-js", () => ({ default: { capture: vi.fn() } }));

vi.mock("@calcom/lib/hooks/useLocale", () => ({
useLocale: () => ({ t: (key: string) => key, i18n: { language: "en" } }),
}));

vi.mock("../components/OnboardingLayout", () => ({
OnboardingLayout: ({ children }: { children: ReactNode }) => <div>{children}</div>,
}));

vi.mock("../components/onboarding-continuation-prompt", () => ({
OnboardingContinuationPrompt: () => null,
}));

vi.mock("../components/plan-icon", () => ({ PlanIcon: () => null }));

vi.mock("../store/onboarding-store", () => ({
useOnboardingStore: () => ({
selectedPlan: mocks.selectedPlan,
setSelectedPlan: vi.fn(),
resetOnboardingPreservingPlan: vi.fn(),
}),
}));

describe("OnboardingView", () => {
beforeEach(() => {
mocks.push.mockReset();
});

it.each<PlanType | null>([
"personal",
"team",
"organization",
null,
])("continues to personal onboarding when the selected plan is %s", (plan) => {
mocks.selectedPlan = plan;
render(<OnboardingView userEmail="user@example.com" />);

fireEvent.click(screen.getByTestId("onboarding-continue-btn"));

expect(mocks.push).toHaveBeenCalledWith("/onboarding/personal/settings");
expect(mocks.push).toHaveBeenCalledTimes(1);
});
});
10 changes: 3 additions & 7 deletions apps/web/modules/onboarding/getting-started/onboarding-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,10 @@ export const OnboardingView = ({ userEmail }: OnboardingViewProps) => {
plan_type: selectedPlan,
});
}
// Cal.diy removed the team and organization onboarding pages, so personal is the only
// onboarding flow that exists. A persisted "team" or "organization" choice used to 404.
startTransition(() => {
if (selectedPlan === "organization") {
router.push("/onboarding/organization/details");
} else if (selectedPlan === "team") {
router.push("/onboarding/teams/details");
} else if (selectedPlan === "personal") {
router.push("/onboarding/personal/settings");
}
router.push("/onboarding/personal/settings");
});
};

Expand Down
Loading