Skip to content

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

:white_check_mark: Repair frontend regression test fixtures

Danield0864c825714
diff --git a/app/src/protyle/render/listMindmap/pinch.test.ts b/app/src/protyle/render/listMindmap/pinch.test.ts
index 4c83ed1805..3bb00584c8 100644
--- a/app/src/protyle/render/listMindmap/pinch.test.ts
+++ b/app/src/protyle/render/listMindmap/pinch.test.ts
@@ -23,7 +23,7 @@ const setup = () => {
let cancelled = 0;
Object.assign(target, {
scale: 1, offsetX: 0, offsetY: 0, pinching: false,
- viewport: {contains: (element: {outside?: boolean}) => !element.outside,
+ viewport: {contains: (element: {outside?: boolean} | null) => !!element && !element.outside,
getBoundingClientRect: () => ({left: 10, top: 20})},
cancelPointer: () => { cancelled++; target.pendingPointerId = undefined; },
boundedPan: (x: number, y: number) => ({x, y}), draw: () => {},
@@ -32,7 +32,7 @@ const setup = () => {
};
const touch = (clientX: number, clientY = 120, excluded = false, outside = false) => ({
- clientX, clientY, target: {closest: () => excluded, outside},
+ clientX, clientY, target: {closest: () => excluded ? {} : null, outside},
});
const event = (...touches: ReturnType<typeof touch>[]) => ({touches, preventDefault() {}});
diff --git a/app/src/protyle/render/listMindmap/toggle.test.ts b/app/src/protyle/render/listMindmap/toggle.test.ts
index 014c3e1376..b495e0b32e 100644
--- a/app/src/protyle/render/listMindmap/toggle.test.ts
+++ b/app/src/protyle/render/listMindmap/toggle.test.ts
@@ -3,6 +3,7 @@ import {readFileSync} from "node:fs";
import test from "node:test";
import {runInNewContext} from "node:vm";
import {createSourceFile, isVariableStatement, ScriptTarget, transpileModule} from "typescript";
+import {isProtyleListItemFragment, registerProtyleRuntimeCapabilities} from "../../runtimeCapabilities";
const source = createSourceFile("index.ts", readFileSync("src/protyle/render/listMindmap/index.ts", "utf8"),
ScriptTarget.ES2021, true);
@@ -30,6 +31,7 @@ const setup = () => {
const updates: string[] = [];
const context: any = {
Constants: {CB_GET_HISTORY: "history", CUSTOM_SY_LIST_MINDMAP: attribute},
+ isProtyleListItemFragment,
roots: new WeakMap(), hideElements: () => {}, readListMindmap: () => {},
cleanListMindmapHTML: (html: string) => html,
retagMindmapBranch: (_element: Element, toMindmap: boolean) => {
@@ -94,6 +96,20 @@ test("read-only, history and lightweight editors cannot persist embedded view ch
}
});
+test("list item fragments can persist embedded view changes unless disabled or showing history", () => {
+ for (const mode of ["editable", "disabled", "history"]) {
+ const {owner, list, operations, api} = setup();
+ owner.lite = true;
+ registerProtyleRuntimeCapabilities(owner as unknown as IProtyle, {listItemFragment: true});
+ owner.disabled = mode === "disabled";
+ if (mode === "history") {
+ owner.options.action.push("history");
+ }
+ api.toggleListMindmap(owner, list);
+ assert.equal(operations.length, mode === "editable" ? 1 : 0);
+ }
+});
+
test("removed lists and blocks without IDs cannot submit view changes", () => {
for (const removed of [false, true]) {
const {list, owner, api, operations} = setup();
diff --git a/app/src/protyle/util/tableCellRichLute.test.ts b/app/src/protyle/util/tableCellRichLute.test.ts
index 51cf636c05..c25dbe2632 100644
--- a/app/src/protyle/util/tableCellRichLute.test.ts
+++ b/app/src/protyle/util/tableCellRichLute.test.ts
@@ -533,7 +533,8 @@ test("table cells insert code through slash and Enter without losing soft breaks
const hint = createSourceFile("hint.ts", read("../hint/index.ts"), ScriptTarget.Latest, true);
const hintClass = hint.statements.find(isClassDeclaration);
const fill = hintClass.members.find(member => isMethodDeclaration(member) && member.name.getText(hint) === "fill");
- const hintSource = compile("const isProtyleListItemFragment = () => false; class Hint {" + fill.getText(hint) + "}");
+ const hintSource = compile(read("../../block/superBlock.ts") +
+ "\nconst isProtyleListItemFragment = () => false; class Hint {" + fill.getText(hint) + "}");
const editor = read("../render/tableCellRichEditor.ts");
const start = editor.indexOf('host.addEventListener("keydown", event => {');
const end = editor.indexOf("}, {capture: true, signal});", start) + "}, {capture: true, signal});".length;
diff --git a/app/tests/avRelationTemplate.test.js b/app/tests/avRelationTemplate.test.js
index f524d4e20c..02d0698740 100644
--- a/app/tests/avRelationTemplate.test.js
+++ b/app/tests/avRelationTemplate.test.js
@@ -186,7 +186,7 @@ const runElectron = async () => {
let exitCode = 0;
try {
const ts = require("typescript");
- const sources = Object.fromEntries(["cell", "cellValue", "attributeValue", "relationLayout"].map(name => ["./" + name,
+ const sources = Object.fromEntries(["cell", "cellValue", "attributeValue", "blockIcon", "relationLayout"].map(name => ["./" + name,
ts.transpileModule(readFileSync(path.join(__dirname, `../src/protyle/render/av/${name}.ts`), "utf8"),
{compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020}}).outputText]));
const relationSource = readFileSync(path.join(__dirname, "../src/protyle/render/av/relation.ts"), "utf8");
@@ -208,7 +208,9 @@ ${relationSource.slice(deselectStart, deselectEnd)} };`,
${relationSource.slice(positionStart, positionEnd)} return positionMenu; };`,
{compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020}}).outputText;
await win.loadURL("data:text/html,<html><body></body></html>");
- await win.webContents.executeJavaScript(`(${runCases.toString()})(${JSON.stringify(sources)})`);
+ const failure = await win.webContents.executeJavaScript(`Promise.resolve().then(() =>
+ (${runCases.toString()})(${JSON.stringify(sources)})).then(() => null, error => error.stack || String(error))`);
+ assert.equal(failure, null);
console.log("AV relation template cases passed");
} catch (error) {
console.error(error);
diff --git a/app/tests/newRefDocAtPath.test.js b/app/tests/newRefDocAtPath.test.js
index e418aca88a..5c0b977bec 100644
--- a/app/tests/newRefDocAtPath.test.js
+++ b/app/tests/newRefDocAtPath.test.js
@@ -36,7 +36,7 @@ const fixture = () => {
const protyle = {
notebookId: "source", path: "/source.sy", block: {rootID: "sourceDoc"},
wysiwyg: {element: {contains: node => node === text}}, toolbar: {range},
- element: {clientWidth: 800},
+ element: {clientWidth: 800}, options: {},
};
const requests = [];
const inserted = [];
@@ -202,7 +202,8 @@ test("typed and searched reference suggestions offer location selection includin
const databaseFixture = (view = "table", isDetached = true) => {
const f = fixture();
- const cell = {isConnected: true};
+ const cell = {isConnected: true, hasAttribute: () => false};
+ f.text.parentElement = {closest: () => cell};
const row = {dataset: {id: "original-item"}, contains: node => node === cell};
let currentValue = {type: "block", isDetached, block: {id: isDetached ? "" : "old-doc", content: "Original"}};
Object.assign(f.block, {