import { beforeEach, describe, expect, it, vi } from "vitest";
import { render } from "@testing-library/react";
import NotFound from "./not-found";
const replaceMock = vi.fn();
vi.mock("next/navigation", () => ({
useRouter: () => ({ replace: replaceMock }),
}));
let mockAuth: { user: { id: string } | null; isLoading: boolean };
vi.mock("@/lib/auth/auth-context", () => ({
useAuth: () => mockAuth,
}));
describe("NotFound page", () => {
beforeEach(() => {
replaceMock.mockReset();
});
it("does not redirect while the auth check is still loading", () => {
mockAuth = { user: null, isLoading: true };
render();
expect(replaceMock).not.toHaveBeenCalled();
});
it("redirects to the dashboard when logged in", () => {
mockAuth = { user: { id: "user-1" }, isLoading: false };
render();
expect(replaceMock).toHaveBeenCalledWith("/dashboard");
});
it("redirects to login when not logged in", () => {
mockAuth = { user: null, isLoading: false };
render();
expect(replaceMock).toHaveBeenCalledWith("/login");
});
});