Files
Moh e2e06be86e test: add comprehensive automated test coverage
- Vitest multi-project setup (unit / integration / component)
- Real-Postgres integration harness via in-process PGlite (TEST_DATABASE_URL
  override), migrations applied per worker; production code untouched
- Unit: routing, locale, validation/Zod schemas, metadata, mail, site-theme,
  marquee, media, portfolio helpers, plus architecture-rule tests
- Integration: Prisma data layer, API routes, and all server actions
- Component: UI primitives and form components (jsdom + Testing Library)
- 371 tests passing
2026-08-06 02:27:20 +02:00

43 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { getLocalizedValue, resolvePortfolioProjectViewMode } from "@/lib/portfolio";
describe("resolvePortfolioProjectViewMode", () => {
it("keeps supported view modes", () => {
expect(resolvePortfolioProjectViewMode("GRID")).toBe("GRID");
expect(resolvePortfolioProjectViewMode("STORY")).toBe("STORY");
expect(resolvePortfolioProjectViewMode("CASE_STUDY")).toBe("CASE_STUDY");
});
it("falls back to GRID for unknown or missing values", () => {
expect(resolvePortfolioProjectViewMode(undefined)).toBe("GRID");
expect(resolvePortfolioProjectViewMode(null)).toBe("GRID");
expect(resolvePortfolioProjectViewMode("unexpected")).toBe("GRID");
});
});
describe("getLocalizedValue", () => {
const content = { ar: "عربي", en: "English", de: "Deutsch" };
it("returns the direct locale value when present", () => {
expect(getLocalizedValue(content, "en")).toBe("English");
expect(getLocalizedValue(content, "ar")).toBe("عربي");
});
it("falls back to the provided fallback locale", () => {
expect(getLocalizedValue({ ar: "", en: "", de: "Deutsch" }, "en", "de")).toBe("Deutsch");
});
it("falls back to any available value when neither locale is filled", () => {
expect(getLocalizedValue({ ar: "عربي", en: "", de: "" }, "en", "de")).toBe("عربي");
});
it("trims whitespace-only values before considering them empty", () => {
expect(getLocalizedValue({ ar: " ", en: " ", de: "Deutsch" }, "en", "de")).toBe("Deutsch");
});
it("returns an empty string when everything is blank", () => {
expect(getLocalizedValue({ ar: "", en: "", de: "" }, "en")).toBe("");
});
});