// @vitest-environment jsdom import "@testing-library/jest-dom/vitest"; import { fireEvent, render, screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { toFirstStepsChecklistVM, toWelcomeSetupVM } from "@hivegrid/view-models"; import { WelcomeSetupPage } from "./WelcomeSetupPage"; import { assertNoA11yViolations } from "~/utils/test/a11y"; vi.mock("~/components/brand/Logo", () => ({ default: ({ to }: { to?: string }) => (to ? HiveGrid : HiveGrid) })); vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string, values?: Record) => (values ? `${key}:${Object.values(values).join("/")}` : key), }), })); const checklist = toFirstStepsChecklistVM({ id: "session_1", status: "active", dismissed: false, items: [ { id: "profile", block: "profile", titleKey: "onboarding.firstSteps.profile", href: "/acme/settings/profile", completed: true }, { id: "team", block: "team", titleKey: "onboarding.firstSteps.team", href: "/acme/settings/team/members/new", completed: false, canComplete: false }, { id: "contacts", block: "contacts", titleKey: "onboarding.firstSteps.contacts", href: "/acme/contacts", completed: false }, ], }); const vm = toWelcomeSetupVM({ firstName: "Ada", workspaceName: "Acme", dashboardHref: "/acme/dashboard", checklist }); describe("WelcomeSetupPage", () => { it("renders automatic setup progress and keeps navigation explicit", () => { const onOpen = vi.fn(); const onDashboard = vi.fn(); const { container } = render(); expect(screen.getByRole("heading", { name: "onboarding.welcome.titleNamed:Ada" })).toBeInTheDocument(); expect(screen.getByText("onboarding.firstSteps.progressBadge:1/3")).toBeInTheDocument(); expect(screen.getByText("onboarding.firstSteps.completed")).toBeInTheDocument(); expect(screen.queryByRole("link", { name: "HiveGrid" })).not.toBeInTheDocument(); fireEvent.click(screen.getByRole("button", { name: "onboarding.welcome.tasks.team.action" })); expect(onOpen).toHaveBeenCalledWith("/acme/settings/team/members/new"); fireEvent.click(screen.getByRole("button", { name: "onboarding.welcome.dashboardAction" })); expect(onDashboard).toHaveBeenCalledWith("/acme/dashboard"); assertNoA11yViolations(container); }); });