droboticflow/tests/frontend/slice-edit-panel-usability.test.mjs

62 lines
3.7 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs";
import test from "node:test";
const css = fs.readFileSync(new URL("../../src/styles/capture-workspace.css", import.meta.url), "utf8");
const panel = fs.readFileSync(new URL("../../src/components/SliceEditPanel.tsx", import.meta.url), "utf8");
test("ticket 01: dictionaries render in place inside the slice edit panel (D7)", () => {
// The shared base rule (position: absolute; inset: 0) is designed for the
// focused editor, where dictionaries replace the editor's contents. Inside
// the slice edit panel the nearest positioned ancestor is the panel root,
// so the base rule covered boundary rows, C/G/merge and 取消/记入预览.
// The panel-scoped rule restores in-flow placement with internal scrolling.
const scoped = css.match(/\[data-testid="slice-edit-panel"\] \.workspace-dictionary-panel\s*\{([^}]*)\}/);
assert.ok(scoped, "slice edit panel scopes a dictionary neutralization rule");
assert.match(scoped[1], /position:\s*relative/);
assert.match(scoped[1], /inset:\s*auto/);
assert.match(scoped[1], /max-height:/, "dictionary scrolls internally instead of stretching the panel");
// The base replacement rule stays intact for its original focused-editor context.
assert.match(css, /\.workspace-dictionary-panel\s*\{[^}]*position:\s*absolute[^}]*inset:\s*0/s);
});
test("ticket 01: panel header and Enter-apply footer stay pinned while content scrolls (D7)", () => {
// The panel root is the scroll container; header and footer stick to its
// edges with the panel background so a long dictionary never scrolls
// 「Enter 应用」 out of view.
assert.match(panel, /flex-col overflow-y-auto/, "panel root remains the scroll container");
const header = panel.slice(panel.indexOf('data-testid="slice-edit-panel"'), panel.indexOf("切片重设 · 片"));
assert.match(header, /sticky top-0/, "header is pinned to the panel top");
assert.match(header, /bg-\[color:var\(--app-panel\)\]/, "pinned header has an opaque background");
const footer = panel.slice(
panel.indexOf('data-testid="slice-edit-panel-hint"'),
panel.indexOf('data-testid="slice-edit-panel-apply"'),
);
assert.match(footer, /sticky bottom-0/, "apply footer is pinned to the panel bottom");
assert.match(footer, /bg-\[color:var\(--app-panel\)\]/, "pinned footer has an opaque background");
assert.match(panel, /onClick=\{onApply\}/, "apply action stays available");
assert.match(panel, /onClick=\{onCancel\}/, "cancel action stays available");
});
test("ticket 01: keyboard contract Esc / Ctrl+Enter is unchanged (D7)", () => {
// Pure layout fix: the discard draft keeps its own key layer — Esc closes
// the draft one level at a time, Ctrl/⌘+Enter confirms via 记入预览.
const draft = panel.slice(panel.indexOf("{discard.draft ? ("), panel.indexOf("记入预览"));
assert.match(draft, /event\.stopPropagation\(\)/);
assert.match(draft, /event\.key === "Escape"/);
assert.match(draft, /\(event\.ctrlKey \|\| event\.metaKey\) && event\.key === "Enter"/);
});
test("ticket 01: compact disposition dialog clears the bottom-right submit rail (D7)", () => {
// adb3dee6 pinned the compact dialog to the viewport with bottom: 116px,
// which lands inside the 126px submit rail (grid row 3) once the focused
// /work wrapper's 12px padding is counted — occluding the bottom-right
// controls. The dialog must end above the rail: 12px wrapper + 126px rail.
const compact = css.match(
/\.annotation-operations-page\[data-workspace-compact\] \.capture-disposition-panel\s*\{([^}]*)\}/,
);
assert.ok(compact, "compact disposition dialog rule exists");
assert.match(compact[1], /bottom:\s*138px/);
assert.doesNotMatch(compact[1], /bottom:\s*116px/);
});