Files
UHD_Media_Tool/packages/contracts/test/reasons.test.ts
T
rootandClaude Opus 5.5 71b129d85a feat(web): merge search filters into one row and tidy episode versions (POLISH-1)
- H&R becomes a quick-filter facet (yes/no/unknown, with counts) on search
  results and the site resources tab; drop the old free/H&R selects, keep
  size range and sort on the same row (mobile: drawer), single clear button
- legacy free/hr URL params migrate into quick filters; stored selections
  keep the same localStorage key
- search timing and query terms move into TechInfo
- library episode versions: click the whole row to expand, versions listed
  as sibling rows, details only under the selected version, raw values in
  TechInfo
- slot comparison gaps get reason codes (matchGapText in contracts
  reasons.ts): "可换成 2160p", "缺 HDR 版本"

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-29 22:06:32 +08:00

45 lines
2.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { looksLikeCode, matchGapText, matchGapTexts, reasonSentence, reasonText } from "../src/reasons.ts";
describe("reasonText(DEAI-2 原因码人话化)", () => {
it("裸码、blocked:多码、带后缀的码都能翻译", () => {
expect(reasonText("identity_unknown")).toEqual({ text: "没识别出作品", action: "指定作品后重新整理" });
expect(reasonText("blocked:target_exists")?.text).toBe("媒体库里已有同名文件");
expect(reasonText("blocked:target_exists,hnr_unknown")?.text).toBe("媒体库里已有同名文件;不确定做种要求是否满足");
expect(reasonText("move_downgraded_to_copy:hnr_unknown")?.text).toBe("做种未完成,已改为复制");
expect(reasonText("below_min_size")?.text).toContain("最小体积");
});
it("不认识的码返回 null;句子兜底不把码原样给人看", () => {
expect(reasonText("some_new_code")).toBeNull();
expect(reasonSentence("some_new_code")).toBe("处理失败");
expect(reasonSentence("磁盘已满")).toBe("磁盘已满");
expect(reasonSentence("identity_unknown")).toBe("没识别出作品。指定作品后重新整理");
});
it("looksLikeCode 只认内部码", () => {
expect(looksLikeCode("blocked:target_exists")).toBe(true);
expect(looksLikeCode("identity_unknown")).toBe(true);
expect(looksLikeCode("目标已存在")).toBe(false);
expect(looksLikeCode("Connection refused")).toBe(false);
});
});
describe("matchGapText(POLISH-1 入库版本差距)", () => {
it("带参数的码转成短句", () => {
expect(matchGapText("version_resolution:2160p")).toBe("可换成 2160p");
expect(matchGapText("version_hdr")).toBe("缺 HDR 版本");
expect(matchGapText("version_hdr:DV")).toBe("缺 DV 版本");
expect(matchGapText("version_source:REMUX")).toBe("可换成 Remux");
expect(matchGapText("version_subtitles:zh-Hans")).toBe("缺简中字幕");
expect(matchGapText("version_subtitles:chs")).toBe("缺 chs 字幕");
});
it("不认识的码返回 null;列表去重", () => {
expect(matchGapText("nope")).toBeNull();
expect(matchGapTexts(["version_resolution:2160p", "version_resolution_upgrade:2160p", "nope"])).toEqual([
"可换成 2160p",
]);
});
});