import { describe, expect, it } from "vitest";
import {
  resourceLanguageLabel,
  resourceTypeDisplay,
  resourceTypeLabel,
  typeFilterLabel,
} from "./resourceTypeLabels";

const t = (key: string) =>
  ({
    filterAll: "全部",
    type_image: "图片",
    type_video: "视频",
    type_music: "音乐",
    lang_zh_CN: "中文",
    lang_en: "English",
    lang_ja: "日本語",
  })[key] ?? key;

describe("resource labels", () => {
  it("localizes known resource types and falls back to raw type", () => {
    expect(typeFilterLabel(t, "all")).toBe("全部");
    expect(resourceTypeLabel(t, "image")).toBe("图片");
    expect(resourceTypeDisplay(t, "video")).toBe("视频");
    expect(resourceTypeLabel(t, "music")).toBe("音乐");
    expect(resourceTypeLabel(t, "unknown")).toBe("unknown");
  });

  it("normalizes resource language codes", () => {
    expect(resourceLanguageLabel(t, "zh-TW")).toBe("中文");
    expect(resourceLanguageLabel(t, "zh-CN")).toBe("中文");
    expect(resourceLanguageLabel(t, "zh-hans")).toBe("中文");
    expect(resourceLanguageLabel(t, "EN")).toBe("English");
    expect(resourceLanguageLabel(t, "ja")).toBe("日本語");
    expect(resourceLanguageLabel(t, "xx")).toBe("xx");
  });
});
