/* @vitest-environment node */

import { describe, it, expect } from "vitest";
import { getPrimaryNavFromPathname, PRIMARY_NAV } from "./activeRoute.js";

describe("lib/frontend/nav/activeRoute", () => {
	it("returns null for non-branch routes", () => {
		expect(getPrimaryNavFromPathname("/")).toBe(null);
		expect(getPrimaryNavFromPathname("/login")).toBe(null);
		expect(getPrimaryNavFromPathname("/forbidden")).toBe(null);
		expect(getPrimaryNavFromPathname("/search")).toBe(null);
	});

	it("marks explorer active for /:branch and /:branch/... (non-search)", () => {
		expect(getPrimaryNavFromPathname("/NL01")).toEqual({
			active: PRIMARY_NAV.EXPLORER,
			branch: "NL01",
		});

		expect(getPrimaryNavFromPathname("/NL01/2025/12/31")).toEqual({
			active: PRIMARY_NAV.EXPLORER,
			branch: "NL01",
		});
	});

	it("marks search active for /:branch/search", () => {
		expect(getPrimaryNavFromPathname("/NL01/search")).toEqual({
			active: PRIMARY_NAV.SEARCH,
			branch: "NL01",
		});

		expect(getPrimaryNavFromPathname("/NL01/search/anything")).toEqual({
			active: PRIMARY_NAV.SEARCH,
			branch: "NL01",
		});
	});

	it("returns null for invalid branch segment", () => {
		expect(getPrimaryNavFromPathname("/nl01")).toBe(null);
		expect(getPrimaryNavFromPathname("/XX01")).toBe(null);
	});
});
