import React from "react";
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
// Mock next/navigation
vi.mock("next/navigation", () => ({
usePathname: () => "/login",
useRouter: () => ({ push: vi.fn(), replace: vi.fn(), back: vi.fn() }),
useSearchParams: () => new URLSearchParams(),
}));
vi.mock("next/link", () => ({
default: ({ children, href, ...props }: any) => {children},
}));
vi.mock("next/image", () => ({
default: (props: any) =>
,
}));
// Mock sub-components with exact path matching
vi.mock("../components/AuthModal", () => ({
default: ({ isOpen, onClose }: any) => (
),
}));
vi.mock("../components/CartDrawer", () => ({
default: ({ isOpen, onCheckout, onShopNavigate }: any) => (
),
}));
vi.mock("../components/PetProfile", () => ({
default: () => Pet Profile
,
}));
vi.mock("../components/VideosPage", () => ({
default: ({ initialVideos }: any) => (
Videos: {initialVideos?.length || 0}
),
}));
vi.mock("../components/SmartAdvisor", () => ({
default: () => Smart Advisor
,
}));
import LoginPage from "./login/page";
import CartPage from "./cart/page";
import ProfilePage from "./profile/page";
import VideosPage from "./videos/page";
import SmartAdvisorPage from "./smart-advisor/page";
describe("Lightweight Utility Routes and Responsive Layouts (UX-29)", () => {
it("renders LoginPage with minimal semantic wrapper and single accessible h1", () => {
const { container } = render();
const h1 = screen.getByRole("heading", { level: 1 });
expect(h1.textContent).toContain("ورود یا ثبتنام");
expect(screen.getByTestId("auth-modal")).toBeTruthy();
const main = container.querySelector("main");
expect(main).not.toBeNull();
expect(main?.getAttribute("dir")).toBe("rtl");
});
it("renders CartPage with semantic main wrapper and single accessible h1", () => {
const { container } = render();
const h1 = screen.getByRole("heading", { level: 1 });
expect(h1.textContent).toContain("سبد خرید");
expect(screen.getByTestId("cart-drawer")).toBeTruthy();
const main = container.querySelector("main");
expect(main).not.toBeNull();
});
it("renders ProfilePage cleanly delegating to PetProfile component", () => {
render();
expect(screen.getByTestId("pet-profile-component")).toBeTruthy();
});
it("renders VideosPage cleanly passing initial videos dataset", async () => {
const component = await VideosPage();
render(component);
expect(screen.getByTestId("videos-page-component")).toBeTruthy();
});
it("renders SmartAdvisorPage with semantic breadcrumbs, h1 and advisor container", () => {
render();
const h1 = screen.getByRole("heading", { level: 1 });
expect(h1.textContent).toMatch(/مشاوره تخصصی و راهنمای/);
expect(screen.getByTestId("smart-advisor-component")).toBeTruthy();
});
});