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"); }); });