Files
web-alterflixhub/app/lib/i18n/locale.spec.ts
T
2026-11-01 17:24:44 +07:00

27 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { resolveInitialLocale } from "./index";
describe("resolveInitialLocale", () => {
it("?lang= ชนะทุกแหล่ง", () => {
expect(resolveInitialLocale({ urlLocale: "en", stored: "th", cookie: "th" })).toBe("en");
expect(resolveInitialLocale({ urlLocale: "th", stored: "en", cookie: "en" })).toBe("th");
});
it("ใช้ค่าที่เคยเลือก (localStorage) ก่อน cookie", () => {
expect(resolveInitialLocale({ stored: "en", cookie: "th" })).toBe("en");
});
it("ถ้าไม่มีใน localStorage ใช้ cookie", () => {
expect(resolveInitialLocale({ cookie: "en" })).toBe("en");
});
it("ไม่เคยเลือกเลย → ไทย (ไทย-first ไม่อิงภาษาของเบราว์เซอร์)", () => {
expect(resolveInitialLocale({})).toBe("th");
});
it("ค่าที่ไม่รู้จักถูกมองข้ามแล้วตกไปค่าเริ่มต้น", () => {
expect(resolveInitialLocale({ urlLocale: "fr", stored: "xx", cookie: null })).toBe("th");
});
});