forked from longtao.wu/droboticflow
✨ Keep dictionaries and long descriptions in the fixed editor
This commit is contained in:
parent
64397225b7
commit
1de1d85b14
@ -16,7 +16,9 @@
|
||||
|
||||
任务 04 为专注视图中的切片和描述时间轴提供每页最多 4 条的连续时间区间。页码、全局条目范围、前后页、查找及当前项定位始终可达;输入名称或描述文本查找下一匹配项,输入 `#13` 可直接打开第 13 条,即使区间只有一帧也无需点击狭小色块。搜索不筛除数据,Ctrl / ⌘ + 左右仍选择全局相邻切片;B/V、草稿恢复与撤销/重做会显示目标所在页。翻页、查找和切换布局不会保存草稿。原布局继续显示完整时间轴。
|
||||
|
||||
内嵌字典、长文本展开、单相机放大和窗口过小时暂停,由后续任务交付。当前双画面尺寸验证使用五档实际浏览器内容区,不代表已覆盖各种操作系统缩放设置。
|
||||
任务 05 将两类字典放入固定编辑区:搜索、每页 2 项、前后页和返回入口固定,长词条显示两行预览,悬停或辅助技术可读取完整词条,填入后可继续完整阅读。F / D 打开,方向键选择,Enter 填入,Esc 一次返回工作台;选择描述模板不会保存,可继续修改。长描述在同一个文本框内滚动,“展开描述编辑”暂时收起精确边界区域以增加文字空间,保存和取消始终在文本滚动区外;收起、切片导航与布局切换不保存草稿。原布局仍使用原有字典弹层。
|
||||
|
||||
单相机放大和窗口过小时暂停,由后续任务交付。当前双画面尺寸验证使用五档实际浏览器内容区,不代表已覆盖各种操作系统缩放设置。
|
||||
|
||||
## 源码恢复与业务数据恢复
|
||||
|
||||
@ -33,3 +35,5 @@
|
||||
大量条目的浏览器验收为 `tests/browser/annotation-workspace-navigation.mjs`,使用独立的 many-annotate-04 与 many-slice-04 任务(后者传入 `NAVIGATION_PHASE=slice`)。两者均有 13 个切片,描述任务首片有 13 条描述。脚本检查五档尺寸、全局导航、草稿与布局切换、尾页删除、跨页历史、单帧描述查找及公共 API 回读;仅显式保存与历史恢复写入本地描述任务,不生成切片或送检。禁止通过重置已有任务重跑验收;任务 ID 可指定该命名前缀下的新增隔离任务。
|
||||
|
||||
分页边界拖动验收为 `tests/browser/annotation-workspace-boundaries.mjs`,默认检查切片,传入 `NAVIGATION_PHASE=annotate` 检查描述。它使用真实鼠标手势将页尾边界向两侧移动,并检查同一横坐标不会重复改变边界;描述模式通过现有编辑、确认结束点和保存建立相邻区间,再以公共 API 核对共享精确帧。历史验收还覆盖从另一切片重做已保存描述时,关闭编辑器并显示目标页。
|
||||
|
||||
字典与长文本验收为 `tests/browser/annotation-workspace-dictionaries.mjs`,使用 pool-01 与 annotate-primary。隔离项目需配置多页字典,以及“布局长名称验收”长名称与“布局长文本模板”长描述。脚本验证两类字典在五档内容区的固定入口、搜索分页、原布局回退、一次 Esc、原生剪切/撤销、草稿展开/收起/跨片保存及 API 撤销/重做回读。组合事件检查是浏览器派发的快捷键归属检查,不代表操作系统输入法验收;完整 OS 缩放与输入法矩阵仍需人工验证。
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { TimelinePageNavigation, useTimelinePage } from "./TimelinePageNavigation";
|
||||
import { pageContaining } from "../lib/annotation-list-navigation.js";
|
||||
import { WorkspaceDictionaryPanel } from "./WorkspaceDictionaryPanel";
|
||||
import { SliceNameDictionaryPicker } from "./SliceNameDictionaryPicker";
|
||||
import type { PointerEvent as ReactPointerEvent } from "react";
|
||||
import {
|
||||
@ -338,13 +339,15 @@ export function CaptureAnnotationWorkbench({
|
||||
if (phase !== "annotate" || readOnly) setEndSelection(null);
|
||||
}, [phase, readOnly, setEndSelection]);
|
||||
const [showDictionary, setShowDictionary] = useState(false);
|
||||
const [expandedDescription, setExpandedDescription] = useState(false);
|
||||
useEffect(() => setExpandedDescription(false), [editingAnnotation?.id]);
|
||||
useEffect(() => {
|
||||
if (showDictionary)
|
||||
if (showDictionary && !focusedLayout)
|
||||
(
|
||||
descriptionDictionaryRef.current?.querySelector<HTMLButtonElement>("[data-dictionary-option]") ||
|
||||
descriptionDictionaryRef.current
|
||||
)?.focus();
|
||||
}, [showDictionary]);
|
||||
}, [showDictionary, focusedLayout]);
|
||||
const [error, setError] = useState("");
|
||||
const [showRejectModal, setShowRejectModal] = useState(false);
|
||||
const [generalRejectReason, setGeneralRejectReason] = useState("");
|
||||
@ -2370,12 +2373,14 @@ export function CaptureAnnotationWorkbench({
|
||||
readOnly
|
||||
disabled={readOnly || isQualityReview}
|
||||
value={selectedSlice.name || ""}
|
||||
title={selectedSlice.name || ""}
|
||||
placeholder="请从项目切片字典选择"
|
||||
className="flex-1 rounded-md border border-slate-300 bg-[color:var(--app-panel)] px-3 py-1.5 text-xs font-semibold text-slate-900 shadow-sm transition placeholder:text-slate-400 focus:border-orange-500 focus:outline-none focus:ring-1 focus:ring-orange-500 dark:border-[#34363b] dark:bg-[#1a1b1e] dark:text-white"
|
||||
/>
|
||||
{!readOnly && !isQualityReview && (
|
||||
<SliceNameDictionaryPicker
|
||||
portal={adaptiveLayout && phase === "slice"}
|
||||
inline={focusedLayout}
|
||||
portal={adaptiveLayout && phase === "slice" && !focusedLayout}
|
||||
triggerRef={sliceDictionaryTriggerRef}
|
||||
key={`${taskId}:${selectedSlice.id}`}
|
||||
items={sliceDictionary}
|
||||
@ -2982,11 +2987,29 @@ export function CaptureAnnotationWorkbench({
|
||||
return (
|
||||
<div
|
||||
data-testid="annotation-description-editor"
|
||||
data-expanded-description={(focusedLayout && expandedDescription) || undefined}
|
||||
ref={descriptionEditorRef}
|
||||
tabIndex={-1}
|
||||
aria-label="动作描述编辑区"
|
||||
className="relative mx-auto mt-3 w-full max-w-xl max-h-[max(180px,calc(76dvh-140px))] overflow-auto rounded-md border border-slate-200 bg-[color:var(--app-panel)] p-3.5 shadow-lg outline-none focus-visible:border-orange-500 focus-visible:ring-2 focus-visible:ring-orange-300 dark:border-[#2a2b2f] dark:bg-[#151619]"
|
||||
>
|
||||
{focusedLayout && showDictionary && editingAnnotation && !readOnly && !isQualityReview ? (
|
||||
<WorkspaceDictionaryPanel
|
||||
title="选择动作描述"
|
||||
searchLabel="搜索描述字典"
|
||||
items={labels.map((item) => ({
|
||||
id: item.id,
|
||||
text: item.description || item.name,
|
||||
searchText: `${item.name} ${item.description || ""}`,
|
||||
}))}
|
||||
status={!labels.length ? <p>暂无字典词条,可直接填写描述。</p> : undefined}
|
||||
onSelect={(id) => {
|
||||
const item = labels.find((item) => item.id === id);
|
||||
if (item) chooseTemplate(item);
|
||||
}}
|
||||
onClose={closeDescriptionDictionary}
|
||||
/>
|
||||
) : null}
|
||||
{readOnly && !isQualityReview ? (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between border-b border-slate-200 pb-2 dark:border-slate-700">
|
||||
@ -3261,7 +3284,7 @@ export function CaptureAnnotationWorkbench({
|
||||
<BookOpen className="h-3.5 w-3.5" />
|
||||
从字典选择
|
||||
</button>
|
||||
{showDictionary && !isInvalid ? (
|
||||
{showDictionary && !isInvalid && !focusedLayout ? (
|
||||
<div
|
||||
ref={descriptionDictionaryRef}
|
||||
role="dialog"
|
||||
@ -3324,8 +3347,19 @@ export function CaptureAnnotationWorkbench({
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="mt-1 flex items-center justify-between text-xs text-slate-500">
|
||||
<span>
|
||||
<div className="capture-description-text-tools mt-1 flex items-center justify-between text-xs text-slate-500">
|
||||
{focusedLayout && !isInvalid ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setExpandedDescription((value) => !value);
|
||||
descriptionInputRef.current?.focus({ preventScroll: true });
|
||||
}}
|
||||
>
|
||||
{expandedDescription ? "收起描述编辑" : "展开描述编辑"}
|
||||
</button>
|
||||
) : null}
|
||||
<span className="capture-description-text-hint">
|
||||
{isInvalid ? "无效片段自动完成描述确认" : "可从字典填入后修改,也可直接填写"}
|
||||
</span>
|
||||
<span>
|
||||
|
||||
@ -2,6 +2,7 @@ import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { BookOpen, Check, X } from "lucide-react";
|
||||
import type { ReactNode, RefObject } from "react";
|
||||
import { WorkspaceDictionaryPanel } from "./WorkspaceDictionaryPanel";
|
||||
import { dictionaryKeyDown } from "../lib/annotation-shortcuts.js";
|
||||
|
||||
export function SliceNameDictionaryPicker({
|
||||
@ -15,6 +16,7 @@ export function SliceNameDictionaryPicker({
|
||||
triggerRef,
|
||||
onCloseFocus,
|
||||
portal = false,
|
||||
inline = false,
|
||||
}: {
|
||||
key?: string;
|
||||
items: { id: string; name: string }[];
|
||||
@ -27,6 +29,7 @@ export function SliceNameDictionaryPicker({
|
||||
triggerRef?: RefObject<HTMLButtonElement | null>;
|
||||
onCloseFocus?: () => void;
|
||||
portal?: boolean;
|
||||
inline?: boolean;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false),
|
||||
[search, setSearch] = useState("");
|
||||
@ -58,7 +61,7 @@ export function SliceNameDictionaryPicker({
|
||||
// A scrollable workbench must not clip the existing dictionary popup. Only
|
||||
// its position changes; selection, keyboard ownership and callbacks stay intact.
|
||||
useLayoutEffect(() => {
|
||||
if (!open || !portal) return;
|
||||
if (!open || !portal || inline) return;
|
||||
const place = () => {
|
||||
const popup = popupRef.current;
|
||||
const trigger = buttonRef.current;
|
||||
@ -78,7 +81,7 @@ export function SliceNameDictionaryPicker({
|
||||
window.removeEventListener("resize", place);
|
||||
window.removeEventListener("scroll", place, true);
|
||||
};
|
||||
}, [open, portal, search, items, loading, error, buttonRef]);
|
||||
}, [open, portal, inline, search, items, loading, error, buttonRef]);
|
||||
const showPopup = (popup: ReactNode) => (portal ? createPortal(popup, document.body) : popup);
|
||||
return (
|
||||
<div ref={root} className="shrink-0" data-dictionary-open={(open && !disabled) || undefined}>
|
||||
@ -100,7 +103,37 @@ export function SliceNameDictionaryPicker({
|
||||
<BookOpen className="h-3.5 w-3.5" />
|
||||
从切片字典选择
|
||||
</button>
|
||||
{open &&
|
||||
{open && !disabled && inline ? (
|
||||
<WorkspaceDictionaryPanel
|
||||
title="选择切片名称"
|
||||
searchLabel="搜索切片字典"
|
||||
items={items
|
||||
.filter((item, index) => items.findIndex((other) => other.name === item.name) === index)
|
||||
.map((item) => ({ id: item.id, text: item.name }))}
|
||||
value={value}
|
||||
status={
|
||||
loading ? (
|
||||
<p role="status">正在加载切片字典…</p>
|
||||
) : error ? (
|
||||
<div role="alert">
|
||||
{error}
|
||||
<button type="button" onClick={onRefresh}>
|
||||
重试加载
|
||||
</button>
|
||||
</div>
|
||||
) : !items.length ? (
|
||||
<p>本项目尚未配置切片字典,请联系管理员配置后再确认切片。</p>
|
||||
) : undefined
|
||||
}
|
||||
onSelect={(id) => {
|
||||
const item = items.find((item) => item.id === id);
|
||||
if (item) onSelect(item.name);
|
||||
close();
|
||||
}}
|
||||
onClose={close}
|
||||
/>
|
||||
) : (
|
||||
open &&
|
||||
!disabled &&
|
||||
showPopup(
|
||||
<div
|
||||
@ -160,7 +193,8 @@ export function SliceNameDictionaryPicker({
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-slate-500">↑ / ↓ 选择 · Enter 确认 · Esc 关闭;名称仅可从项目字典选择。</p>
|
||||
</div>,
|
||||
)}
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
86
src/components/WorkspaceDictionaryPanel.tsx
Normal file
86
src/components/WorkspaceDictionaryPanel.tsx
Normal file
@ -0,0 +1,86 @@
|
||||
import { useState } from "react";
|
||||
import type { ReactNode } from "react";
|
||||
import { dictionaryKeyDown } from "../lib/annotation-shortcuts.js";
|
||||
|
||||
/** Focused presentation only; callers retain dictionary selection and save ownership. */
|
||||
export function WorkspaceDictionaryPanel({
|
||||
title,
|
||||
searchLabel,
|
||||
items,
|
||||
value,
|
||||
status,
|
||||
onSelect,
|
||||
onClose,
|
||||
}: {
|
||||
title: string;
|
||||
searchLabel: string;
|
||||
items: { id: string; text: string; searchText?: string }[];
|
||||
value?: string;
|
||||
status?: ReactNode;
|
||||
onSelect: (id: string) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(0);
|
||||
const filtered = items.filter((item) =>
|
||||
(item.searchText || item.text).toLocaleLowerCase().includes(search.trim().toLocaleLowerCase()),
|
||||
);
|
||||
const pages = Math.max(1, Math.ceil(filtered.length / 2));
|
||||
const currentPage = Math.min(page, pages - 1);
|
||||
return (
|
||||
<div
|
||||
role="dialog"
|
||||
aria-label={title}
|
||||
className="workspace-dictionary-panel"
|
||||
onKeyDown={(event) => dictionaryKeyDown(event, onClose)}
|
||||
>
|
||||
<div className="workspace-dictionary-heading">
|
||||
<strong>{title}</strong>
|
||||
<button type="button" onClick={onClose}>
|
||||
返回编辑
|
||||
</button>
|
||||
</div>
|
||||
<input
|
||||
autoFocus
|
||||
aria-label={searchLabel}
|
||||
placeholder={searchLabel}
|
||||
value={search}
|
||||
onChange={(event) => {
|
||||
setSearch(event.target.value);
|
||||
setPage(0);
|
||||
}}
|
||||
/>
|
||||
<div className="workspace-dictionary-results">
|
||||
{status ||
|
||||
(filtered.length ? (
|
||||
filtered.slice(currentPage * 2, currentPage * 2 + 2).map((item) => (
|
||||
<button
|
||||
type="button"
|
||||
key={item.id}
|
||||
data-dictionary-option
|
||||
title={item.text}
|
||||
aria-pressed={item.text === value}
|
||||
onClick={() => onSelect(item.id)}
|
||||
>
|
||||
<span>{item.text}</span>
|
||||
</button>
|
||||
))
|
||||
) : (
|
||||
<p>没有匹配的词条。</p>
|
||||
))}
|
||||
</div>
|
||||
<nav aria-label={`${title}分页`}>
|
||||
<button type="button" disabled={currentPage === 0} onClick={() => setPage(currentPage - 1)}>
|
||||
上一页
|
||||
</button>
|
||||
<span>
|
||||
{currentPage + 1} / {pages} 页 · {filtered.length} 项
|
||||
</span>
|
||||
<button type="button" disabled={currentPage + 1 >= pages} onClick={() => setPage(currentPage + 1)}>
|
||||
下一页
|
||||
</button>
|
||||
</nav>
|
||||
<p>↑ / ↓ 选择 · Enter 填入 · Esc 返回;选择后仍需确认保存。</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -1044,3 +1044,106 @@
|
||||
.annotation-operations-page[data-workspace-compact] [data-testid="slice-annotation-timeline"] > .bg-blue-600 > span {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Dictionaries replace the fixed editor's contents, retaining its mounted draft. */
|
||||
.workspace-dictionary-panel {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 40;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-height: 0;
|
||||
padding: 8px;
|
||||
border: 1px solid var(--app-border);
|
||||
border-radius: 6px;
|
||||
background: var(--app-panel);
|
||||
color: var(--app-text);
|
||||
visibility: visible;
|
||||
font-size: 12px;
|
||||
}
|
||||
.workspace-dictionary-heading,
|
||||
.workspace-dictionary-panel nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 6px;
|
||||
flex: none;
|
||||
}
|
||||
.workspace-dictionary-panel input,
|
||||
.workspace-dictionary-panel button {
|
||||
border: 1px solid var(--app-border);
|
||||
border-radius: 4px;
|
||||
padding: 4px 8px;
|
||||
background: var(--app-panel);
|
||||
}
|
||||
.workspace-dictionary-panel button:disabled {
|
||||
opacity: 0.4;
|
||||
}
|
||||
.workspace-dictionary-panel input,
|
||||
.workspace-dictionary-panel > p {
|
||||
flex: none;
|
||||
}
|
||||
.workspace-dictionary-panel > p {
|
||||
font-size: 10px;
|
||||
}
|
||||
.workspace-dictionary-results {
|
||||
flex: 1 1 0;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
.workspace-dictionary-results > button {
|
||||
display: block;
|
||||
line-height: 16px;
|
||||
width: 100%;
|
||||
margin-bottom: 4px;
|
||||
text-align: left;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.workspace-dictionary-results > button > span {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
}
|
||||
.workspace-dictionary-results > button:focus,
|
||||
.workspace-dictionary-results > button[aria-pressed="true"] {
|
||||
background: var(--app-hover);
|
||||
outline: 2px solid #fb923c;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.annotation-operations-page[data-workspace-compact] .capture-slice-name-editor > .relative {
|
||||
position: static;
|
||||
}
|
||||
.annotation-operations-page[data-workspace-compact] .capture-stage-editor:has(.workspace-dictionary-panel) > *,
|
||||
.annotation-operations-page[data-workspace-compact]
|
||||
[data-testid="annotation-description-editor"]:has(.workspace-dictionary-panel)
|
||||
> :not(.workspace-dictionary-panel) {
|
||||
visibility: hidden;
|
||||
}
|
||||
.annotation-operations-page[data-workspace-compact] .capture-description-text-hint {
|
||||
display: none;
|
||||
}
|
||||
.annotation-operations-page[data-workspace-compact] .capture-description-text-tools {
|
||||
flex: none;
|
||||
gap: 4px;
|
||||
}
|
||||
.annotation-operations-page[data-workspace-compact] .capture-description-text-tools button {
|
||||
border: 1px solid var(--app-border);
|
||||
border-radius: 3px;
|
||||
padding: 2px 4px;
|
||||
}
|
||||
.annotation-operations-page[data-workspace-compact] [data-expanded-description] > .capture-description-boundaries,
|
||||
.annotation-operations-page[data-workspace-compact] [data-expanded-description] > .capture-description-help {
|
||||
display: none;
|
||||
}
|
||||
.annotation-operations-page[data-workspace-compact] [aria-label="动作描述"] {
|
||||
overflow: auto;
|
||||
}
|
||||
/* Override the existing slice-name input's flex basis inside this replacement panel. */
|
||||
.annotation-operations-page[data-workspace-compact] .workspace-dictionary-panel > input {
|
||||
flex: 0 0 28px;
|
||||
height: 28px;
|
||||
min-height: 28px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
312
tests/browser/annotation-workspace-dictionaries.mjs
Normal file
312
tests/browser/annotation-workspace-dictionaries.mjs
Normal file
@ -0,0 +1,312 @@
|
||||
// Real local browser/API boundaries: inline dictionaries must not move media,
|
||||
// and long drafts must survive presentation changes until explicitly saved.
|
||||
import assert from "node:assert/strict";
|
||||
import { chromium } from "playwright";
|
||||
const browser = await chromium.launch({
|
||||
executablePath: "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
||||
headless: true,
|
||||
args: ["--no-proxy-server"],
|
||||
});
|
||||
const context = await browser.newContext({
|
||||
storageState: "local-data/verification/annotation-workspace-layout/auth.json",
|
||||
viewport: { width: 1280, height: 640 },
|
||||
});
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(10000);
|
||||
const button = (name) => page.getByRole("button", { name, exact: true });
|
||||
const read = async (task) => {
|
||||
const r = await context.request.get(
|
||||
`http://127.0.0.1:5173/api/human-items/${task.replace("annotation-task-", "human-item-")}`,
|
||||
);
|
||||
assert.ok(r.ok());
|
||||
return (await r.json()).item;
|
||||
};
|
||||
const rects = () => page.locator("video").evaluateAll((vs) => vs.map((v) => v.getBoundingClientRect().toJSON()));
|
||||
const reachable = async (l) =>
|
||||
assert.ok(
|
||||
await l.evaluate((e) => {
|
||||
const r = e.getBoundingClientRect();
|
||||
return (
|
||||
r.width > 0 &&
|
||||
r.height > 0 &&
|
||||
r.x >= 0 &&
|
||||
r.y >= 0 &&
|
||||
r.right <= innerWidth &&
|
||||
r.bottom <= innerHeight &&
|
||||
e.contains(document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2))
|
||||
);
|
||||
}),
|
||||
`reachable ${(await l.getAttribute("aria-label")) || (await l.innerText())}`,
|
||||
);
|
||||
const open = async (task) => {
|
||||
await page.goto(
|
||||
`http://127.0.0.1:5173/plugins/annotation-qa/workflows/all/work?projectId=project-workspace-layout-acceptance&taskId=${task}`,
|
||||
);
|
||||
await button("继续工作").click();
|
||||
if (await button("进入专注视图").count()) await button("进入专注视图").click();
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.querySelectorAll("video").length === 2 &&
|
||||
[...document.querySelectorAll("video")].every((v) => v.readyState >= 2),
|
||||
null,
|
||||
{ timeout: 60000 },
|
||||
);
|
||||
};
|
||||
try {
|
||||
for (const stage of ["slice", "annotate"]) {
|
||||
const task = `annotation-task-workspace-layout-acceptance-${stage === "slice" ? "pool-01" : "annotate-primary"}`;
|
||||
await open(task);
|
||||
const writes = [];
|
||||
page.on("request", (r) => {
|
||||
if (r.method() !== "GET" && (r.url().includes(`/tasks/${task}/`) || r.url().includes("random-claims")))
|
||||
writes.push(r.url());
|
||||
});
|
||||
const bench = page.getByTestId("capture-annotation-workbench");
|
||||
if (stage === "annotate") await page.getByTestId("annotation-description-block").first().click();
|
||||
const editor = page.locator(
|
||||
stage === "slice" ? ".capture-stage-editor" : '[data-testid="annotation-description-editor"]',
|
||||
);
|
||||
const old = await read(task),
|
||||
before = await rects();
|
||||
await bench.focus();
|
||||
await page.keyboard.press("f");
|
||||
const dialog = page.getByRole("dialog", { name: stage === "slice" ? "选择切片名称" : "选择动作描述", exact: true });
|
||||
await dialog.waitFor();
|
||||
const dr = await dialog.boundingBox(),
|
||||
er = await editor.boundingBox();
|
||||
assert.ok(
|
||||
dr.x >= er.x &&
|
||||
dr.y >= er.y &&
|
||||
dr.x + dr.width <= er.x + er.width + 1 &&
|
||||
dr.y + dr.height <= er.y + er.height + 1,
|
||||
"dictionary replaces content inside fixed editor",
|
||||
);
|
||||
assert.deepEqual(await rects(), before, "dictionary cannot displace video");
|
||||
const search = dialog.getByRole("textbox", { name: stage === "slice" ? "搜索切片字典" : "搜索描述字典" });
|
||||
await reachable(search);
|
||||
await reachable(dialog.getByRole("button", { name: "下一页", exact: true }));
|
||||
for (const option of await dialog.locator("[data-dictionary-option]").all()) await reachable(option);
|
||||
const first = await dialog.locator("[data-dictionary-option]").allTextContents();
|
||||
assert.ok(await dialog.getByRole("button", { name: "下一页", exact: true }).isEnabled(), "fixture spans pages");
|
||||
await dialog.getByRole("button", { name: "下一页", exact: true }).click();
|
||||
assert.notDeepEqual(await dialog.locator("[data-dictionary-option]").allTextContents(), first);
|
||||
await search.fill("不存在的词条xyz");
|
||||
assert.equal(await dialog.locator("[data-dictionary-option]").count(), 0);
|
||||
await search.fill("");
|
||||
await search.press("ArrowDown");
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.keyboard.press("ArrowUp");
|
||||
const chosen = await page.locator(":focus").innerText();
|
||||
await page.keyboard.press("Enter");
|
||||
await dialog.waitFor({ state: "detached" });
|
||||
assert.equal((await read(task)).version, old.version, "dictionary does not save");
|
||||
if (stage === "slice") assert.equal(await page.getByLabel("切片名称:").inputValue(), chosen.trim());
|
||||
else assert.equal(await page.getByRole("textbox", { name: "动作描述", exact: true }).inputValue(), chosen.trim());
|
||||
await bench.focus();
|
||||
await page.keyboard.press("d");
|
||||
await dialog.waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
await dialog.waitFor({ state: "detached" });
|
||||
assert.ok(await bench.evaluate((e) => e === document.activeElement), "one Esc returns workbench focus");
|
||||
await page.keyboard.press("Space");
|
||||
await page.waitForFunction(() => !document.querySelector("video").paused);
|
||||
assert.equal(await dialog.count(), 0);
|
||||
await page.keyboard.press("Space");
|
||||
// Read the entire long option inside the list, with controls outside its scroll area.
|
||||
await bench.focus();
|
||||
await page.keyboard.press("f");
|
||||
await search.fill(stage === "slice" ? "布局长名称验收" : "布局长文本模板");
|
||||
const longOption = dialog.locator("[data-dictionary-option]");
|
||||
await longOption.first().waitFor();
|
||||
assert.equal(await longOption.count(), 1);
|
||||
const longValue = await longOption.innerText();
|
||||
assert.ok(longValue.length >= (stage === "slice" ? 100 : 1000));
|
||||
for (const [width, height] of [
|
||||
[1280, 640],
|
||||
[1366, 680],
|
||||
[1440, 800],
|
||||
[1920, 980],
|
||||
[2560, 1320],
|
||||
]) {
|
||||
await page.setViewportSize({ width, height });
|
||||
for (const control of [
|
||||
longOption,
|
||||
search,
|
||||
dialog.getByRole("button", { name: "上一页", exact: true }),
|
||||
dialog.getByRole("button", { name: "下一页", exact: true }),
|
||||
dialog.getByRole("button", { name: "返回编辑", exact: true }),
|
||||
])
|
||||
await reachable(control);
|
||||
assert.ok(
|
||||
await page.evaluate(
|
||||
() =>
|
||||
document.documentElement.scrollHeight <= innerHeight && document.documentElement.scrollWidth <= innerWidth,
|
||||
),
|
||||
);
|
||||
}
|
||||
await page.setViewportSize({ width: 1280, height: 640 });
|
||||
assert.ok(
|
||||
await longOption.evaluate((e) => {
|
||||
const r = e.getBoundingClientRect(),
|
||||
list = e.parentElement.getBoundingClientRect();
|
||||
return list.height >= 48 && r.y >= list.y && e.contains(document.elementFromPoint(r.x + 12, r.y + 12));
|
||||
}),
|
||||
"long dictionary result is visibly readable, not only keyboard-selectable",
|
||||
);
|
||||
await page.screenshot({
|
||||
path: `local-data/verification/annotation-workspace-layout/task05-${stage}-dictionary.png`,
|
||||
});
|
||||
await search.press("Enter");
|
||||
assert.equal((await read(task)).version, old.version);
|
||||
assert.equal(
|
||||
await page
|
||||
.getByRole("textbox", { name: stage === "slice" ? "切片名称:" : "动作描述", exact: true })
|
||||
.inputValue(),
|
||||
longValue,
|
||||
);
|
||||
// Runtime fallback retains the original popup, selection contract and single-Esc focus.
|
||||
await button("切回原布局").click();
|
||||
await bench.focus();
|
||||
await page.keyboard.press("d");
|
||||
await dialog.waitFor();
|
||||
if (stage === "slice") await dialog.getByRole("textbox", { name: "搜索切片字典" }).fill("布局验收切片 003");
|
||||
else assert.equal(await dialog.getByRole("textbox").count(), 0, "original description popup remains unchanged");
|
||||
await page.keyboard.press("Escape");
|
||||
assert.ok(await bench.evaluate((e) => e === document.activeElement));
|
||||
await button("进入专注视图").click();
|
||||
console.log("PASS inline paging/search/long option/five sizes/keyboard/no-save and original popup", stage);
|
||||
assert.equal(writes.length, 0, "dictionary, original fallback and native selection issue no writes");
|
||||
if (stage === "slice") {
|
||||
// All names must be chosen before the real generation review can open.
|
||||
while (await button("下一片").isEnabled()) {
|
||||
await button("下一片").click();
|
||||
await bench.focus();
|
||||
await page.keyboard.press("f");
|
||||
await search.fill("布局长名称验收");
|
||||
await dialog.locator("[data-dictionary-option]").first().waitFor();
|
||||
await search.press("Enter");
|
||||
}
|
||||
await bench.focus();
|
||||
await page.keyboard.press("Control+Enter");
|
||||
await page.getByRole("dialog", { name: "确认生成切片", exact: true }).waitFor();
|
||||
await reachable(button("确认生成"));
|
||||
await reachable(button("返回编辑"));
|
||||
assert.ok(
|
||||
await page
|
||||
.getByRole("dialog", { name: "确认生成切片", exact: true })
|
||||
.getByText(longValue, { exact: false })
|
||||
.count(),
|
||||
);
|
||||
await button("返回编辑").click();
|
||||
assert.equal((await read(task)).version, old.version);
|
||||
continue;
|
||||
}
|
||||
const input = page.getByRole("textbox", { name: "动作描述", exact: true });
|
||||
const original = old.subject.payload.annotationWorkspace.segments[0].description;
|
||||
const text = `Task05 长描述 ${Date.now()}\n` + "中文动作描述内容与完整阅读。".repeat(160);
|
||||
await input.fill(text);
|
||||
await input.press("Meta+a");
|
||||
await input.press("Meta+x");
|
||||
assert.equal(await input.inputValue(), "", "native cut owns the text selection");
|
||||
await button("展开描述编辑").click();
|
||||
await input.press("Meta+z");
|
||||
assert.equal(await input.inputValue(), text, "native undo survives expanding the same textarea");
|
||||
await button("收起描述编辑").click();
|
||||
// Browser-dispatched composition events exercise application ownership; not a system IME test.
|
||||
await input.dispatchEvent("compositionstart", { data: "中文" });
|
||||
for (const key of ["f", "d", "Enter", "Escape", "z"])
|
||||
await input.dispatchEvent("keydown", { key, isComposing: true, ctrlKey: key === "Enter" || key === "z" });
|
||||
await input.dispatchEvent("compositionend", { data: "中文" });
|
||||
assert.equal(await input.inputValue(), text);
|
||||
assert.equal(await dialog.count(), 0);
|
||||
assert.equal((await read(task)).version, old.version);
|
||||
console.log("PASS native cut/undo and supplemental composition shortcut ownership");
|
||||
const inputNode = await input.elementHandle(),
|
||||
videos = await page.locator("video").elementHandles();
|
||||
assert.ok(await input.evaluate((e) => e.scrollHeight > e.clientHeight), "long text scrolls internally");
|
||||
const collapsed = await input.boundingBox();
|
||||
await button("展开描述编辑").click();
|
||||
assert.ok((await input.boundingBox()).height > collapsed.height, "same textarea expands");
|
||||
assert.ok(await inputNode.evaluate((e) => e.isConnected));
|
||||
for (const [width, height] of [
|
||||
[1280, 640],
|
||||
[1366, 680],
|
||||
[1440, 800],
|
||||
[1920, 980],
|
||||
[2560, 1320],
|
||||
]) {
|
||||
await page.setViewportSize({ width, height });
|
||||
for (const name of ["收起描述编辑", "确认保存描述", "取消编辑", "完成任务并提交质检"])
|
||||
await reachable(button(name));
|
||||
const g = await page.locator("video").evaluateAll((vs) =>
|
||||
vs.map((v) => {
|
||||
const r = v.getBoundingClientRect(),
|
||||
s = Math.min(r.width / v.videoWidth, r.height / v.videoHeight);
|
||||
return [v.videoWidth * s, v.videoHeight * s];
|
||||
}),
|
||||
);
|
||||
assert.ok(g.every(([w, h]) => w >= 400 && h >= 325));
|
||||
assert.ok(await page.evaluate(() => document.documentElement.scrollHeight <= innerHeight));
|
||||
console.log("PASS expanded geometry", width, height, JSON.stringify(g));
|
||||
}
|
||||
await page.setViewportSize({ width: 1280, height: 640 });
|
||||
await page.screenshot({ path: "local-data/verification/annotation-workspace-layout/task05-expanded.png" });
|
||||
await button("收起描述编辑").click();
|
||||
assert.equal(await input.inputValue(), text);
|
||||
await button("展开描述编辑").click();
|
||||
for (const name of ["切回原布局", "进入专注视图"]) {
|
||||
await button(name).click();
|
||||
assert.equal(await input.inputValue(), text);
|
||||
assert.ok(await inputNode.evaluate((e) => e.isConnected));
|
||||
for (const v of videos) assert.ok(await v.evaluate((e) => e.isConnected));
|
||||
}
|
||||
await bench.focus();
|
||||
await page.keyboard.press("Control+ArrowRight");
|
||||
await page.keyboard.press("Control+ArrowLeft");
|
||||
assert.equal(await input.inputValue(), text);
|
||||
assert.equal((await read(task)).version, old.version);
|
||||
await button("完成任务并提交质检").click();
|
||||
await page.getByRole("dialog", { name: "请先处理未保存草稿", exact: true }).waitFor();
|
||||
await reachable(button("返回编辑"));
|
||||
await button("返回编辑").click();
|
||||
assert.equal(await input.inputValue(), text);
|
||||
assert.equal(writes.length, 0, "expanded text and drafts do not implicitly save");
|
||||
await input.press("Control+Enter");
|
||||
await input.waitFor({ state: "detached" });
|
||||
let saved = await read(task);
|
||||
assert.equal(saved.version, old.version + 1);
|
||||
assert.ok(saved.subject.payload.annotationWorkspace.segments.some((s) => s.description === text));
|
||||
const mutation = () =>
|
||||
page.waitForResponse((r) => r.url().endsWith("/annotation-confirmations") && r.request().method() === "POST");
|
||||
let response = mutation();
|
||||
await button("撤销").click();
|
||||
assert.ok((await response).ok());
|
||||
assert.ok((await read(task)).subject.payload.annotationWorkspace.segments.some((s) => s.description === original));
|
||||
await page.waitForTimeout(1100);
|
||||
response = mutation();
|
||||
await button("重做").click();
|
||||
assert.ok((await response).ok());
|
||||
assert.ok((await read(task)).subject.payload.annotationWorkspace.segments.some((s) => s.description === text));
|
||||
assert.equal(writes.length, 3, "only explicit save, undo and redo write");
|
||||
const persisted = await read(task);
|
||||
await page.getByTestId("annotation-description-block").first().click();
|
||||
await input.fill(text + " 未保存修改");
|
||||
await button("展开描述编辑").click();
|
||||
await reachable(button("取消编辑"));
|
||||
await button("取消编辑").click();
|
||||
assert.equal((await read(task)).version, persisted.version);
|
||||
await page.getByTestId("annotation-description-block").first().click();
|
||||
assert.equal(await input.inputValue(), text);
|
||||
await button("取消编辑").click();
|
||||
console.log(
|
||||
"PASS expanded draft/layout/navigation/guard/cancel and public save/undo/redo",
|
||||
JSON.stringify({ before: old.version, after: (await read(task)).version }),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
await page.screenshot({ path: "local-data/verification/annotation-workspace-layout/task05-error.png" });
|
||||
throw e;
|
||||
} finally {
|
||||
await context.close();
|
||||
await browser.close();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user