/**
 * #343 — i18n/config 순수 함수 단위 테스트.
 */
import { isLocale, detectBrowserLocale, DEFAULT_LOCALE } from "@/i18n/config";

describe("i18n/config.isLocale", () => {
  it("returns true for supported locales", () => {
    expect(isLocale("ko")).toBe(true);
    expect(isLocale("en")).toBe(true);
    expect(isLocale("ja")).toBe(true);
    expect(isLocale("es")).toBe(true);
  });

  it("returns false for unsupported / null / undefined", () => {
    expect(isLocale("fr")).toBe(false);
    expect(isLocale("zh")).toBe(false);
    expect(isLocale(null)).toBe(false);
    expect(isLocale(undefined)).toBe(false);
    expect(isLocale("")).toBe(false);
  });
});

describe("i18n/config.detectBrowserLocale", () => {
  // jsdom의 navigator.language는 기본 'en-US'
  it("returns supported locale from navigator.language", () => {
    Object.defineProperty(navigator, "language", { value: "en-US", configurable: true });
    expect(detectBrowserLocale()).toBe("en");
    Object.defineProperty(navigator, "language", { value: "ko-KR", configurable: true });
    expect(detectBrowserLocale()).toBe("ko");
    Object.defineProperty(navigator, "language", { value: "ja", configurable: true });
    expect(detectBrowserLocale()).toBe("ja");
    Object.defineProperty(navigator, "language", { value: "es-MX", configurable: true });
    expect(detectBrowserLocale()).toBe("es");
  });

  it("falls back to DEFAULT_LOCALE for unsupported", () => {
    Object.defineProperty(navigator, "language", { value: "fr-FR", configurable: true });
    expect(detectBrowserLocale()).toBe(DEFAULT_LOCALE);
    Object.defineProperty(navigator, "language", { value: "zh-CN", configurable: true });
    expect(detectBrowserLocale()).toBe(DEFAULT_LOCALE);
  });
});
