droboticflow-new/tests/frontend/scope-cycle-inline-editor.test.mjs

72 lines
4.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import * as reviewNavigation from "../../src/lib/review-navigation.js";
// 票 05 钉子的存留部分(spec D5 / ADR 0009)。票 07(D5 修订版)把 Ctrl/⌘+↑/↓
// 从「既有意见条目导航」改为「切换写意见的目标档」:导航序断言(05 测试 1/2)已被
// review-target-interaction.test.mjs 的目标档位表驱动取代并删除;此处保留仍成立的
// 默认作用域、常驻编辑器与删除净守卫,帮助行守卫改写为新语义。
// 接缝:src/lib/review-navigation.js 为纯函数(node --test 直接加载);
// TS 模块(useReviewDraft / ReviewProblemPanel)按仓库先例以源码守卫钉住(见文末)。
test("default scope: action→action, slice→slice, everything else→timestamp; no selection follows position", () => {
const { defaultReviewScope } = reviewNavigation;
const pos = (extra = {}) => ({ sliceId: "s1", time: 4, ...extra });
// 已选目标优先:导航/点击落在哪类目标上,F 就默认哪类。
assert.equal(defaultReviewScope("action", pos({ actionId: "a1" })), "action");
assert.equal(defaultReviewScope("slice", pos({ actionId: "a1" })), "slice");
assert.equal(defaultReviewScope("timestamp", pos()), "timestamp");
// 其余(历史整体、未知值)→ 时间点。
assert.equal(defaultReviewScope("task", pos()), "timestamp");
// 未选时按画面位置兜底:动作→动作、切片→切片、都无→时间点。
assert.equal(defaultReviewScope(null, pos({ actionId: "a1" })), "action");
assert.equal(defaultReviewScope(null, pos()), "slice");
assert.equal(defaultReviewScope(null, { time: 4 }), "timestamp");
assert.equal(defaultReviewScope(null, null), "timestamp");
});
const read = (path) => fs.readFileSync(new URL(path, import.meta.url), "utf8");
test("source guard: hook wires the target model and resident editor", () => {
const source = read("../../src/hooks/useReviewDraft.ts");
assert.match(
source,
/import \{\s*defaultReviewScope,\s*nearestReviewPositionAction,\s*nextReviewTargetScope,\s*postSubmitReviewTarget,\s*reviewPositionAction,\s*reviewTargetPosition,\s*\} from "\.\.\/lib\/review-navigation\.js";/,
);
// 目标档解析用画面:时间点档=切入时刻冻结锚点,其余=实时播放头。
assert.match(source, /reviewTargetPosition\(scope, m\.position, m\.targetAnchor\)/);
// 常驻内联编辑器的绑定(无打开编辑器时)。
assert.match(source, /residentEditor:/);
assert.match(source, /editSelected: \(\) => selectScope\(defaultReviewScope\(m\.selected, m\.position\), true\)/);
// 选择列表条目记录当前档位(时间点条目同时冻结锚点)。
assert.match(source, /m\.selected = problem\.scope;/);
assert.match(source, /m\.targetAnchor = \{/);
});
test("source guard: expander, summary UI and their state fully removed", () => {
const hook = read("../../src/hooks/useReviewDraft.ts");
const panel = read("../../src/components/ReviewProblemPanel.tsx");
for (const source of [hook, panel]) {
assert.doesNotMatch(source, /showSummary/);
assert.doesNotMatch(source, /全任务/);
}
assert.doesNotMatch(panel, /编辑当前画面意见/);
assert.doesNotMatch(panel, /review\.groups/);
assert.doesNotMatch(hook, /groups: \[\.\.\.groups\(\)\.values\(\)\]/);
});
test("source guard: resident inline editor promotes into edit state on focus", () => {
const panel = read("../../src/components/ReviewProblemPanel.tsx");
assert.match(panel, /const resident =/);
assert.match(panel, /onFocus=\{\(\) => review\.editSelected\(\)\}/);
assert.doesNotMatch(panel, /onFocus=\{\(\) => review\.selectScope\(resident\.scope, true\)\}/);
});
test("source guard: shortcut help describes target switching with zero popups (07 rewrite)", () => {
const help = read("../../src/lib/review-shortcuts.js");
assert.match(help, /Ctrl \/ ⌘ \+ ↑ \/ ↓[\s\S]{0,80}切换意见目标/);
assert.doesNotMatch(help, /选择整体/);
assert.doesNotMatch(help, /选择意见范围/);
});