import { render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";

const { authProvider } = vi.hoisted(() => ({
  authProvider: vi.fn(({ children }: { children: React.ReactNode }) => <>{children}</>),
}));

vi.mock("./auth/AuthContext", () => ({
  AuthProvider: authProvider,
  useAuth: () => ({ user: null, loading: false }),
}));
vi.mock("./pages/PublicDisplayCenterPage", () => ({
  PublicDisplayCenterPage: () => <div>公开大屏页面</div>,
}));
vi.mock("./pages/AdminPage", () => ({ AdminPage: () => <div>管理页面</div> }));
vi.mock("./pages/DisplayPage", () => ({ DisplayPage: () => <div>单项目公屏</div> }));
vi.mock("./pages/HistoryPage", () => ({ HistoryPage: () => <div>历史页面</div> }));
vi.mock("./pages/LoginPage", () => ({ LoginPage: () => <div>登录页面</div> }));
vi.mock("./pages/StaffPage", () => ({ StaffPage: () => <div>员工页面</div> }));
vi.mock("./pages/VisitorPage", () => ({ VisitorPage: () => <div>游客页面</div> }));
vi.mock("./pages/VisitorLookupPage", () => ({ VisitorLookupPage: () => <div>游客查询</div> }));
vi.mock("./pages/VisitorPhonePage", () => ({ VisitorPhonePage: () => <div>游客号码</div> }));

import { App } from "./App";

afterEach(() => {
  window.history.pushState({}, "", "/");
  vi.clearAllMocks();
});

describe("App routes", () => {
  it("opens /admin/display without mounting administrator authentication", () => {
    window.history.pushState({}, "", "/admin/display");

    render(<App />);

    expect(screen.getByText("公开大屏页面")).toBeVisible();
    expect(authProvider).not.toHaveBeenCalled();
  });
});
