Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:white_check_mark: Align frontend test fixtures with current source behavior

Jeffrey Chende3f9abe1c25
diff --git a/app/src/layout/dock/agent/agentSkill.test.ts b/app/src/layout/dock/agent/agentSkill.test.ts
index a85b39a0f2..3d43f25d04 100644
--- a/app/src/layout/dock/agent/agentSkill.test.ts
+++ b/app/src/layout/dock/agent/agentSkill.test.ts
@@ -55,6 +55,8 @@ const browserCases = async (source: string) => {
const hint = {
element, source: "hint", enableExtend: true, enableSlash: true, splitChar: "/",
consumeRefBracketClose: api.Hint.prototype.consumeRefBracketClose,
+ // 用例只覆盖命令填充,表格单元格接管由 fillCommand 用例覆盖
+ openNewTableCell: () => {},
genHTML: (items: IHintData[], _protyle?: IProtyle, reset = false) => {
if (reset && items.length === 0) {
element.classList.add("fn__none");
diff --git a/app/src/protyle/render/listMindmap/arrows.test.ts b/app/src/protyle/render/listMindmap/arrows.test.ts
index c84ee52340..60d05ca3a8 100644
--- a/app/src/protyle/render/listMindmap/arrows.test.ts
+++ b/app/src/protyle/render/listMindmap/arrows.test.ts
@@ -50,6 +50,8 @@ const setup = (arrowDirection?: ListMindmapRelation["arrowDirection"]) => {
const sandbox: any = {
buildListMindmapConnectors,
Path2D: TestPath, window: {devicePixelRatio: 1},
+ // 绘制入口会取消上一帧的合并绘制请求,替身环境没有帧调度
+ cancelAnimationFrame: () => {}, requestAnimationFrame: () => 1,
getComputedStyle: (element: {style?: {color?: string}}) => ({
getPropertyValue: () => "", color: element.style?.color || "black",
}),
diff --git a/app/src/protyle/util/tableCellRichLute.test.ts b/app/src/protyle/util/tableCellRichLute.test.ts
index 79af8b269e..a2efe58aa9 100644
--- a/app/src/protyle/util/tableCellRichLute.test.ts
+++ b/app/src/protyle/util/tableCellRichLute.test.ts
@@ -507,7 +507,9 @@ const browserCases = async (source: string, enterSource: string, hintSource: str
const range = prepare(prefix + "/");
range.setStart(range.startContainer, prefix.length);
const context = {source: "hint", splitChar: "/", lastIndex: -1, fixImageCursor: () => {},
- consumeRefBracketClose: Hint.prototype.consumeRefBracketClose};
+ consumeRefBracketClose: Hint.prototype.consumeRefBracketClose,
+ // 选区不在表格单元格内时接管不生效,这里只验证代码块插入
+ openNewTableCell: () => {}};
fill.call(context, "```", protyle, false);
const code = verifyCode(wysiwyg, window.siyuan.storage.codeLanguage);
check.equal(calls.rendered, code);
diff --git a/app/tests/automationPanel.test.js b/app/tests/automationPanel.test.js
index 65fdf3daa3..efd61229cc 100644
--- a/app/tests/automationPanel.test.js
+++ b/app/tests/automationPanel.test.js
@@ -237,14 +237,19 @@ const runCases = async (sources, css, mobile) => {
['[data-actions] [data-index="0"]', '[data-actions] [data-action="remove-action"]'],
['[data-field-id="finished"]', '[data-actions] [data-action="remove-field"]'],
];
- assert.equal(matchMedia("(hover: none), (any-pointer: coarse)").matches, mobile, "touch devices have visible removal controls");
+ // 可见性由媒体查询决定:带触摸屏的桌面主机在未模拟触控时同样命中 coarse 指针
+ const touchControls = matchMedia("(hover: none), (any-pointer: coarse)").matches;
+ if (mobile) {
+ assert.ok(matchMedia("(hover: none)").matches, "touch emulation switches the hover capability");
+ }
for (const [rowSelector, buttonSelector] of removals) {
const button = get(buttonSelector);
button.scrollIntoView({block: "center"});
await require("electron").ipcRenderer.invoke("automation-pointer", window.innerWidth - 2, 2);
await tick();
const before = button.getBoundingClientRect();
- assert.equal(getComputedStyle(button).opacity, mobile ? "1" : "0", "removal is contextual on desktop and visible on touch");
+ assert.equal(getComputedStyle(button).opacity, touchControls ? "1" : "0",
+ "removal is contextual on desktop and visible on touch");
button.focus();
assert.equal(getComputedStyle(button).opacity, "1", "keyboard focus reveals the removal button");
button.blur();
@@ -416,8 +421,10 @@ const runCases = async (sources, css, mobile) => {
await change("[data-mode]", "currentTime");
const theme = document.createElement("style");
await require("electron").ipcRenderer.invoke("automation-size", mobile ? 360 : 560, 620);
- for (let attempt = 0; window.innerHeight !== 620 && attempt < 100; attempt++) { await tick(); }
- assert.equal(window.innerHeight, 620, "the resized viewport is ready before testing assignment scrolling");
+ // 非 100% 缩放下窗口内容高度可能有 1 像素的取整偏差
+ for (let attempt = 0; Math.abs(window.innerHeight - 620) > 1 && attempt < 100; attempt++) { await tick(); }
+ assert.ok(Math.abs(window.innerHeight - 620) <= 1,
+ `the resized viewport is ready before testing assignment scrolling: ${window.innerHeight}`);
get("[data-mode]").scrollIntoView({block: "center"});
await tick();
const scroller = get(".b3-menu__items");
@@ -498,7 +505,7 @@ const runCases = async (sources, css, mobile) => {
await require("electron").ipcRenderer.invoke("automation-capture", `${mobile ? "mobile" : "desktop"}-${width}-${name}`);
get('[data-action="add-action"]').scrollIntoView({block: "nearest"});
await tick();
- assert.ok(get('[data-action="add-action"]').getBoundingClientRect().bottom <= 901,
+ assert.ok(get('[data-action="add-action"]').getBoundingClientRect().bottom <= window.innerHeight + 1,
`${mobile}/${width}: actions remain reachable by scrolling: ${JSON.stringify(get('[data-action="add-action"]').getBoundingClientRect())}`);
await require("electron").ipcRenderer.invoke("automation-capture", `${mobile ? "mobile" : "desktop"}-${width}-${name}-actions`);
}
diff --git a/app/tests/fillCommand.test.js b/app/tests/fillCommand.test.js
index f6b5692488..fd8ec9ac5e 100644
--- a/app/tests/fillCommand.test.js
+++ b/app/tests/fillCommand.test.js
@@ -47,7 +47,7 @@ const compile = () => {
extract("wysiwyg/list", ["updateListOrder"]),
extract("wysiwyg/listContext", ["getOrderedListMarkerUpdates"]),
extract("hint/blockHintRange", ["shouldCaptureHintUndoFocus"]),
- extract("util/insertHTML", ["markFoldHeadingChildren", "insertHTML"]),
+ extract("util/insertHTML", ["markFoldHeadingChildren", "focusInsertedBlock", "insertHTML"]),
extract("wysiwyg/transaction", ["updateTransaction"]),
`const keyboardHandler = (protyle, event) => {
const editorElement = protyle.wysiwyg.element;
diff --git a/app/tests/listContainerGutter.test.js b/app/tests/listContainerGutter.test.js
index 51bb6ae733..fa678eee18 100644
--- a/app/tests/listContainerGutter.test.js
+++ b/app/tests/listContainerGutter.test.js
@@ -103,7 +103,7 @@ const cases = (source, fullSource, css) => {
getLangByType: type => type,
setDragTipGhost: noop, stringifyBlockDragData: JSON.stringify, restoreGutterRange: noop,
setFold: (_owner, element) => {folded.push(element.dataset.nodeId); return {fold: 1};},
- markGutterForFoldRestore: () => true,
+ markGutterForFoldRestore: () => true, isGutterTouchDragging: noop,
toggleMenu: options => options.build(null, {show: callback => callback()}),
};
const render = new Function(...Object.keys(dependencies), source + "\nreturn render;")(...Object.values(dependencies));