Files
sass-mohfarawati/tests/unit/admin-navigation.test.ts
T
moh dc21c33867 ADDED - Admin SEO page, robots/sitemap hardening and media/maintenance security fixes
SEO
- New Settings > SEO admin page (seo_settings in app_config): indexing switch,
  Google/Bing verification, X handle, JSON-LD identity (Person/Organization,
  sameAs), per-locale keywords, readiness checklist and open links for
  sitemap.xml / robots.txt / manifest.
- robots.txt is now dynamic: disallows admin, api, success and coming-soon
  paths; blocks everything while indexing is off or maintenance is on.
- sitemap.xml carries hreflang alternates per URL, lists only categories with
  published projects, and is empty while hidden.
- Metadata: robots + verification meta, og:locale in de_DE/en_US/ar_AR form,
  alternateLocale, twitter site/creator, project cover as OG image with
  article type, noindex on /success and /coming-soon.
- JSON-LD: WebSite + publisher graph on all public pages, CreativeWork per
  project (view-mode independent).

Security
- Maintenance bypass now requires a correctly signed admin cookie; the
  middleware previously only checked the cookie existed. Token helpers moved
  to lib/admin-session-token.ts (shared by proxy.ts and lib/admin-auth.ts).
- Media uploads: magic-byte validation against the declared type, SVG
  sanitization (script/handlers/foreignObject/javascript: rejected), upload
  folder sanitized, kind inferred from the real file.
- Media route: fixed prefix-based path check that accepted sibling
  directories, unknown extensions return 404, nosniff header, CSP sandbox on
  SVG, gif content type added.
- External media URLs: protocol-relative (//host) URLs rejected.

Portfolio
- Project and category slugs share /portfolio/[slug]; saving now rejects a
  slug already used on the other side instead of silently shadowing it.

Tooling/docs
- Lint: ignore scripts/legacy-prisma-seed.cjs, drop unused import.
- New docs/SEO.md; FEATURES, ARCHITECTURE (Drizzle instead of Prisma), admin
  spec and CLAUDE.md updated.
- Tests for all of the above (unit + integration); suite green.
2026-09-20 21:36:16 +02:00

89 lines
3.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { getAdminNavigation } from "@/lib/admin-navigation";
const copy = {
overview: "Overview",
maintenance: "Maintenance",
uiKit: "UI Kit",
portfolio: "Portfolio",
media: "Media",
siteSettings: "Site Settings",
brandSettings: "Brand",
localizationSettings: "Localization",
marquee: "Marquee",
smtp: "SMTP",
};
describe("getAdminNavigation", () => {
it("returns the full set of top-level sections", () => {
const nav = getAdminNavigation(copy, "overview");
const labels = nav.map((item) => item.label);
expect(labels).toEqual([
"Overview",
"Maintenance",
"UI Kit",
"Media",
"Site Settings",
"Marquee",
"SMTP",
"Portfolio",
]);
});
it("marks the active top-level section", () => {
const nav = getAdminNavigation(copy, "smtp");
expect(nav.find((item) => item.label === "SMTP")?.active).toBe(true);
expect(nav.find((item) => item.label === "Overview")?.active).toBe(false);
});
it("expands site-settings and marks the active child", () => {
const nav = getAdminNavigation(copy, "site-settings", undefined, "localization");
const siteSettings = nav.find((item) => item.label === "Site Settings");
expect(siteSettings?.expanded).toBe(true);
expect(siteSettings?.active).toBe(false); // has a child selected
const localization = siteSettings?.children?.find((c) => c.label === "Localization");
expect(localization?.active).toBe(true);
});
it("marks the parent active when no child is selected", () => {
const nav = getAdminNavigation(copy, "site-settings");
const siteSettings = nav.find((item) => item.label === "Site Settings");
expect(siteSettings?.active).toBe(true);
expect(siteSettings?.expanded).toBe(true);
});
it("maps portfolio children and de-duplicates hrefs", () => {
const nav = getAdminNavigation(copy, "portfolio", "projects");
const portfolio = nav.find((item) => item.label === "Portfolio");
expect(portfolio?.expanded).toBe(true);
const hrefs = portfolio?.children?.map((c) => c.href) ?? [];
expect(new Set(hrefs).size).toBe(hrefs.length); // unique
const projects = portfolio?.children?.find((c) => c.label === "Projects");
expect(projects?.active).toBe(true);
});
it("activates the new-project child", () => {
const nav = getAdminNavigation(copy, "portfolio", "new-project");
const portfolio = nav.find((item) => item.label === "Portfolio");
expect(portfolio?.children?.find((c) => c.label === "Add Project")?.active).toBe(true);
});
it("falls back to default child labels when copy omits them", () => {
const minimal = { ...copy, brandSettings: undefined, localizationSettings: undefined, marquee: undefined, smtp: undefined };
const nav = getAdminNavigation(minimal, "overview");
const siteSettings = nav.find((item) => item.label === "Site Settings");
expect(siteSettings?.children?.map((c) => c.label)).toEqual(["Brand", "Localization", "SEO"]);
expect(nav.find((item) => item.href.endsWith("/marquee"))?.label).toBe("Marquee");
expect(nav.find((item) => item.href.endsWith("/smtp"))?.label).toBe("SMTP");
});
it("gives every item an icon and href", () => {
const nav = getAdminNavigation(copy, "overview");
for (const item of nav) {
expect(item.icon).toBeTruthy();
expect(typeof item.href).toBe("string");
}
});
});