Unify dynamic locale routing
CI / quality (push) Waiting to run

This commit is contained in:
MOH
2026-03-15 05:12:33 +01:00
parent dfed5ec831
commit 27df4ad2fe
3 changed files with 42 additions and 46 deletions
+22
View File
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { getLocalizedPathWithDefault } from "../lib/locale";
describe("locale path helpers", () => {
it("keeps the configured 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 locale", () => {
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("strips old locale prefixes before rebuilding the target path", () => {
expect(getLocalizedPathWithDefault("en", "/ar/contact", "de")).toBe("/en/contact");
expect(getLocalizedPathWithDefault("ar", "/de/about", "ar")).toBe("/about");
});
});