|
| 1 | +import { cleanup, render, screen } from "@testing-library/react"; |
| 2 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 3 | + |
| 4 | +import { IndexRedirect } from "./IndexRedirect"; |
| 5 | + |
| 6 | +vi.mock("@tanstack/react-router", () => ({ |
| 7 | + Navigate: ({ to }: { to: string }) => <div data-testid="navigate">{to}</div>, |
| 8 | +})); |
| 9 | + |
| 10 | +let onboarding = { isReady: true, isComplete: false, dismissed: false }; |
| 11 | +vi.mock("@/providers/OnboardingProvider/OnboardingProvider", () => ({ |
| 12 | + useOnboarding: () => onboarding, |
| 13 | +})); |
| 14 | + |
| 15 | +afterEach(cleanup); |
| 16 | + |
| 17 | +const target = () => screen.queryByTestId("navigate"); |
| 18 | + |
| 19 | +describe("IndexRedirect", () => { |
| 20 | + it("waits (no redirect) until onboarding state is ready", () => { |
| 21 | + onboarding = { isReady: false, isComplete: false, dismissed: false }; |
| 22 | + render(<IndexRedirect />); |
| 23 | + expect(target()).toBeNull(); |
| 24 | + }); |
| 25 | + |
| 26 | + it("redirects to /welcome while onboarding is active", () => { |
| 27 | + onboarding = { isReady: true, isComplete: false, dismissed: false }; |
| 28 | + render(<IndexRedirect />); |
| 29 | + expect(target()).toHaveTextContent("/welcome"); |
| 30 | + }); |
| 31 | + |
| 32 | + it("redirects to /dashboard once complete", () => { |
| 33 | + onboarding = { isReady: true, isComplete: true, dismissed: false }; |
| 34 | + render(<IndexRedirect />); |
| 35 | + expect(target()).toHaveTextContent("/dashboard"); |
| 36 | + }); |
| 37 | + |
| 38 | + it("redirects to /dashboard once dismissed", () => { |
| 39 | + onboarding = { isReady: true, isComplete: false, dismissed: true }; |
| 40 | + render(<IndexRedirect />); |
| 41 | + expect(target()).toHaveTextContent("/dashboard"); |
| 42 | + }); |
| 43 | +}); |
0 commit comments