Files
UHD_Media_Tool/apps/web/app/components/episode-mapping/preview-table.test.ts
T
rootandClaude Opus 5.5 63e94b308e feat(identify-words): 识别词——全局识别词(MP 语法)+ 作品识别词(季集换算),规则页「识别词」页签
- 新表 identify_words(0094):全局一块 + 每部作品一块原文,带版本与审计;episode_mapping_rule 转成文本行后删表
- 全局识别词移植 MP WordsMatcher(屏蔽 / 替换 / 集数偏移 / 替换+偏移 / {[tmdbid=…]}),所有按标题 / 文件名识别的地方解析前套用,命中的行记在解析结果上;保存后后台按改动行重新识别
- 作品识别词:S02 >> S01 EP+24 / S01E13 >> S00E01 / S01 @组 >> 忽略,解析器 + 打印器 + 编译;发布组繁简视为同一个
- 去掉规则自动停用:算出来对不上季表只待确认,要停用就注释掉那一行
- 集数待确认的采用 / 忽略与智能体 apply_rule 改为往作品识别词追加一行(带来历注释)
- 编辑器可视化 / 文本两种模式改同一份原文,保存前试算;作品页「集数映射」用同一个编辑器

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
2026-10-08 17:03:00 +08:00

91 lines
3.0 KiB
TypeScript

import type { EpisodeMappingPreviewItem } from "@umt/contracts";
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { PreviewTable } from "./preview-table.tsx";
const item = (over: Partial<EpisodeMappingPreviewItem>): EpisodeMappingPreviewItem => ({
sourceReleaseId: "7d3f7f5e-8a8c-4b8e-9f0a-1b2c3d4e5f60",
title: "[Lilith-Raws] Kusuriya no Hitorigoto - 40",
publishedAt: "2025-03-14T15:00:00.000Z",
releaseGroup: "Lilith-Raws",
current: {
method: "unresolved",
source: { season: 1, episodes: { start: 40, end: 40 } },
canonical: null,
evidence: [],
},
preview: {
method: "rule",
source: { season: 1, episodes: { start: 40, end: 40 } },
canonical: { season: 2, episodes: { start: 10, end: 10 } },
ruleId: "draft",
evidence: [],
},
words: [],
validation: "pass",
changed: true,
...over,
});
describe("模拟预览表格", () => {
it("原始 → 当前 → 套用后、方式、校验;有变化的行高亮", () => {
const html = renderToStaticMarkup(createElement(PreviewTable, { items: [item({})], hasDraft: true }));
expect(html).toContain("套用后");
expect(html).toContain("S01E40");
expect(html).toContain("待确认");
expect(html).toContain("S02E10");
expect(html).toContain("按作品识别词");
expect(html).toContain("对得上");
expect(html).toContain("有变化");
expect(html).toContain('data-changed="true"');
});
it("方式下面写命中的作品识别词行与全局识别词", () => {
const html = renderToStaticMarkup(
createElement(PreviewTable, {
items: [
item({
preview: { ...item({}).preview, ruleLine: 2, ruleText: "S01 @Lilith-Raws >> S02 EP-30" },
words: ["Kusuriya => 药屋"],
}),
],
hasDraft: true,
}),
);
expect(html).toContain("第 2 行 S01 @Lilith-Raws &gt;&gt; S02 EP-30");
expect(html).toContain("命中识别词:");
expect(html).toContain("Kusuriya =&gt; 药屋");
});
it("没变化不高亮;校验不通过显示对不上;没有草稿时列名是重算", () => {
const html = renderToStaticMarkup(
createElement(PreviewTable, {
items: [
item({
changed: false,
validation: "fail",
preview: {
method: "unresolved",
source: { season: 1, episodes: { start: 40, end: 40 } },
canonical: null,
evidence: [],
},
}),
],
hasDraft: false,
}),
);
expect(html).toContain("重算");
expect(html).toContain("对不上");
expect(html).not.toContain("data-changed");
expect(html).not.toContain("有变化");
});
it("没有资源时显示空态", () => {
expect(renderToStaticMarkup(createElement(PreviewTable, { items: [], hasDraft: false }))).toContain(
"还没有绑定的资源",
);
});
});