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
This commit is contained in:
Moh
2026-08-06 02:27:20 +02:00
parent 0f48381894
commit e2e06be86e
50 changed files with 4975 additions and 26 deletions
+103
View File
@@ -0,0 +1,103 @@
import { describe, expect, it } from "vitest";
import {
FALLBACK_LOCALE,
getDirection,
getLocalizedPath,
getLocalizedPathWithDefault,
isSupportedLocale,
resolveLocale,
stripLocalePrefix,
} from "@/lib/locale";
describe("isSupportedLocale", () => {
it("accepts the three app locales", () => {
expect(isSupportedLocale("de")).toBe(true);
expect(isSupportedLocale("en")).toBe(true);
expect(isSupportedLocale("ar")).toBe(true);
});
it("rejects everything else", () => {
expect(isSupportedLocale("fr")).toBe(false);
expect(isSupportedLocale("")).toBe(false);
expect(isSupportedLocale(undefined)).toBe(false);
expect(isSupportedLocale(null)).toBe(false);
});
});
describe("resolveLocale", () => {
it("keeps supported locales", () => {
expect(resolveLocale("ar", "de")).toBe("ar");
});
it("falls back for unsupported locales", () => {
expect(resolveLocale("fr", "en")).toBe("en");
expect(resolveLocale(undefined, FALLBACK_LOCALE)).toBe("de");
expect(resolveLocale(null, "ar")).toBe("ar");
});
});
describe("getDirection", () => {
it("is rtl for arabic only", () => {
expect(getDirection("ar")).toBe("rtl");
expect(getDirection("de")).toBe("ltr");
expect(getDirection("en")).toBe("ltr");
expect(getDirection("fr")).toBe("ltr");
});
});
describe("stripLocalePrefix", () => {
it("removes a bare locale prefix", () => {
expect(stripLocalePrefix("/de")).toBe("/");
expect(stripLocalePrefix("/ar")).toBe("/");
});
it("removes a nested locale prefix", () => {
expect(stripLocalePrefix("/en/about")).toBe("/about");
expect(stripLocalePrefix("/ar/portfolio/x")).toBe("/portfolio/x");
});
it("returns unprefixed paths unchanged", () => {
expect(stripLocalePrefix("/about")).toBe("/about");
expect(stripLocalePrefix("/")).toBe("/");
expect(stripLocalePrefix("")).toBe("/");
});
it("does not strip lookalike segments", () => {
expect(stripLocalePrefix("/design")).toBe("/design");
});
});
describe("getLocalizedPathWithDefault", () => {
it("keeps the default locale on the bare domain", () => {
expect(getLocalizedPathWithDefault("ar", "/", "ar")).toBe("/");
expect(getLocalizedPathWithDefault("de", "/", "ar")).toBe("/de");
expect(getLocalizedPathWithDefault("en", "/", "ar")).toBe("/en");
});
it("builds nested paths against the configured default", () => {
expect(getLocalizedPathWithDefault("ar", "/coming-soon", "ar")).toBe("/coming-soon");
expect(getLocalizedPathWithDefault("de", "/coming-soon", "ar")).toBe("/de/coming-soon");
expect(getLocalizedPathWithDefault("en", "/portfolio", "de")).toBe("/en/portfolio");
});
it("re-bases an already-prefixed path onto the requested locale", () => {
expect(getLocalizedPathWithDefault("en", "/ar/contact", "de")).toBe("/en/contact");
expect(getLocalizedPathWithDefault("ar", "/de/about", "ar")).toBe("/about");
});
it("normalizes an empty path to root", () => {
expect(getLocalizedPathWithDefault("de", "", "de")).toBe("/");
expect(getLocalizedPathWithDefault("en", "", "de")).toBe("/en");
});
it("falls back to the default locale for unsupported input", () => {
expect(getLocalizedPathWithDefault("fr", "/about", "de")).toBe("/about");
});
it("getLocalizedPath is an alias of getLocalizedPathWithDefault", () => {
expect(getLocalizedPath("en", "/about", "de")).toBe(
getLocalizedPathWithDefault("en", "/about", "de"),
);
});
});