forked from Lilly-Protocol/lily-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsection-nav.test.tsx
More file actions
57 lines (50 loc) · 1.79 KB
/
Copy pathsection-nav.test.tsx
File metadata and controls
57 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { SectionNav } from "./section-nav";
vi.mock("next/link", () => ({
default: ({
children,
href,
className,
"aria-current": ariaCurrent,
}: {
children: React.ReactNode;
href: string;
className?: string;
"aria-current"?: string;
}) => (
<a href={href} className={className} aria-current={ariaCurrent}>
{children}
</a>
),
}));
const mockUsePathname = vi.fn();
vi.mock("next/navigation", () => ({
usePathname: () => mockUsePathname(),
}));
const mockRoutes = [
{ id: "home", title: "Home", path: "/" },
{ id: "about", title: "About", path: "/about" },
{ id: "agent-detail", title: "Agent Detail", path: "/app/agents/[id]" },
] as const;
describe("SectionNav", () => {
it("marks link as active when pathname matches exactly", () => {
mockUsePathname.mockReturnValue("/about");
render(<SectionNav routes={mockRoutes} />);
const aboutLink = screen.getByRole("link", { name: /about/i });
expect(aboutLink).toHaveAttribute("aria-current", "page");
expect(aboutLink.className).toContain("border-[var(--color-accent)]");
});
it("does not mark links as active on unrelated path", () => {
mockUsePathname.mockReturnValue("/contact");
render(<SectionNav routes={mockRoutes} />);
const homeLink = screen.getByRole("link", { name: /home/i });
expect(homeLink).not.toHaveAttribute("aria-current");
});
it("renders placeholder div for dynamic route pattern", () => {
mockUsePathname.mockReturnValue("/app/agents/123");
render(<SectionNav routes={mockRoutes} />);
expect(screen.queryByRole("link", { name: /agent detail/i })).toBeNull();
expect(screen.getByText("Agent Detail")).toBeInTheDocument();
});
});