Skip to content

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

:white_check_mark: Update frontend regression fixtures and assertions https://github.com/siyuan-note/siyuan/issues/19474

Danieldc55a0635ad1
diff --git a/app/electron/remoteKernel.test.js b/app/electron/remoteKernel.test.js
index 7c5507425b..4828489316 100644
--- a/app/electron/remoteKernel.test.js
+++ b/app/electron/remoteKernel.test.js
@@ -211,10 +211,10 @@ test("remote document CSP only permits hashed packaged inline scripts", () => {
assert.equal(policy.includes("style()"), false);
});
-test("remote document CSP covers the packaged app, window, and authorization pages", () => {
+test("remote document CSP covers the app templates and authorization page", () => {
const documentPaths = [
- path.join(__dirname, "../stage/build/app/index.html"),
- path.join(__dirname, "../stage/build/app/window.html"),
+ path.join(__dirname, "../src/assets/template/app/index.tpl"),
+ path.join(__dirname, "../src/assets/template/app/window.tpl"),
path.join(__dirname, "remote-auth.html"),
];
documentPaths.forEach((documentPath) => {
diff --git a/app/electron/windowMessaging.test.js b/app/electron/windowMessaging.test.js
index 10d1ef7a91..04aefb9d71 100644
--- a/app/electron/windowMessaging.test.js
+++ b/app/electron/windowMessaging.test.js
@@ -91,7 +91,7 @@ test("未登记内核目标的窗口既不能发送也不能接收", () => {
});
test("主进程 handler 按发送方与内核目标接线到 dispatchWindowMessage", () => {
- const source = fs.readFileSync(path.join(__dirname, "main.js"), "utf8");
+ const source = fs.readFileSync(path.join(__dirname, "main.js"), "utf8").replace(/\r\n/g, "\n");
const marker = "ipcMain.on(\"siyuan-send-windows\", (event, data) => {";
const markerOffset = source.indexOf(marker);
assert.notEqual(markerOffset, -1);
diff --git a/app/src/plugin/topBar.test.ts b/app/src/plugin/topBar.test.ts
index 3d89aee3c3..861daa21d3 100644
--- a/app/src/plugin/topBar.test.ts
+++ b/app/src/plugin/topBar.test.ts
@@ -255,6 +255,7 @@ test("visibility menu leaves custom controls blank while preserving ordinary plu
{getAttribute: () => "#iconClock"} : null});
const dependencies = {
TOP_BAR_ROOT_PATH: "topBar",
+ isInMobileApp: () => false,
STATUS_BAR_ROOT_PATH: "statusBar",
buildEntryVisibilityMenuItems: (_path: string, runtime: {getEntryIcon: (path: string) => object}) => [
runtime.getEntryIcon("topBar.custom"), runtime.getEntryIcon("topBar.icon"),
@@ -287,6 +288,7 @@ test("plugin menu supports custom content without SVG icons", () => {
Constants: {},
isBazaarAvailable: () => true,
isMobile: () => false,
+ isInMobileApp: () => false,
hasPluginSetting: () => false,
};
const exports: {openTopBarMenu?: typeof import("./openTopBarMenu").openTopBarMenu} = {};
diff --git a/app/src/protyle/preview/image.test.ts b/app/src/protyle/preview/image.test.ts
index cd3f83f484..47415b31dd 100644
--- a/app/src/protyle/preview/image.test.ts
+++ b/app/src/protyle/preview/image.test.ts
@@ -6,8 +6,11 @@ import {ModuleKind, ScriptTarget, transpileModule} from "typescript";
test("image preview initializes its toolbar when ready is dispatched on the source element", async () => {
const actions = ["zoom-in", "zoom-out", "one-to-one", "reset", "prev", "play", "next",
- "rotate-left", "rotate-right", "flip-horizontal", "flip-vertical", "copy", "copy-file", "close"];
+ "rotate-left", "rotate-right", "flip-horizontal", "flip-vertical", "copy", "copy-file"];
class Classes extends Set<string> {
+ public remove(name: string) {
+ this.delete(name);
+ }
public toggle(name: string, force: boolean) {
if (force) {
this.add(name);
@@ -31,6 +34,9 @@ test("image preview initializes its toolbar when ready is dispatched on the sour
const sourceElement = new EventTarget();
class TestViewer {
public viewed = true;
+ public viewer = {
+ querySelector: (selector: string) => buttons.get(selector.replace(".viewer-navigation > ", "")),
+ };
public image = {src: "blob:first"};
public toolbar = {
querySelector: (selector: string) => {
@@ -83,11 +89,12 @@ test("image preview initializes its toolbar when ready is dispatched on the sour
assert.match(buttons.get(".viewer-copy").innerHTML, /#iconImage/);
assert.match(buttons.get(".viewer-copy-file").innerHTML, /#iconFile/);
assert.equal(buttons.get(".viewer-copy").attributes.get("aria-label"), "Copy as PNG");
- buttons.forEach(button => {
+ buttons.forEach((button, selector) => {
assert.ok(button.classList.has("ariaLabel"));
assert.equal(button.attributes.has("title"), false);
assert.ok(button.attributes.get("aria-label"));
- assert.equal(button.attributes.get("data-position"), "north");
+ assert.equal(button.attributes.get("data-position"), selector === ".viewer-prev" ? "east" :
+ selector === ".viewer-next" ? "west" : "north");
});
instance.options.toolbar.copy();
instance.image.src = "blob:second";
diff --git a/app/src/protyle/toolbar/entryVisibility.test.ts b/app/src/protyle/toolbar/entryVisibility.test.ts
index 8c78e475e4..0ff3677643 100644
--- a/app/src/protyle/toolbar/entryVisibility.test.ts
+++ b/app/src/protyle/toolbar/entryVisibility.test.ts
@@ -29,7 +29,9 @@ test("font entries merge into old profiles while preserving plugin slots and hid
saved.splice(saved.indexOf("strong"), 0, "plugin:unloaded:action");
const merged = mergeEntryOrderPreservingUnknown(defaults, saved, undefined, separators);
assert.ok(merged.includes("plugin:unloaded:action"));
- assert.deepEqual(merged.filter(key => !["font-family", "font-size"].includes(key)), saved);
+ assert.equal(merged.indexOf("plugin:unloaded:action"), saved.indexOf("plugin:unloaded:action"));
+ assert.deepEqual(merged.filter(key => !["font-family", "font-size", "plugin:unloaded:action"].includes(key)),
+ saved.filter(key => key !== "plugin:unloaded:action"));
const items = defaults.map(key => ({key, separator: separators.has(key)}));
const result = resolve(items, {order: merged, hidden: ["text", "font-family"]});
assert.equal(result.visible.some(item => item.key === "text" || item.key === "font-family"), false);
diff --git a/app/src/protyle/wysiwyg/transactionAV.test.ts b/app/src/protyle/wysiwyg/transactionAV.test.ts
index 2b0e35c2c9..9aa6250a4c 100644
--- a/app/src/protyle/wysiwyg/transactionAV.test.ts
+++ b/app/src/protyle/wysiwyg/transactionAV.test.ts
@@ -4,6 +4,7 @@ import {test} from "node:test";
import {runInNewContext} from "node:vm";
import {ModuleKind, ScriptTarget, transpileModule} from "typescript";
import {queueTransaction, queueTransactionBatch, waitForPendingTransactions} from "../util/transactionQueue";
+import {getEditorTransaction} from "../util/transactionContract";
const compiled = transpileModule(readFileSync("src/protyle/wysiwyg/transaction.ts", "utf8"), {
compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},
@@ -18,6 +19,7 @@ const fixture = () => {
let finish: (success: boolean) => void;
const exports: any = {};
const dependencies = {
+ getEditorTransaction,
Constants: {},
queueTransaction,
queueTransactionBatch,
diff --git a/app/src/util/fileTreeReorder.test.ts b/app/src/util/fileTreeReorder.test.ts
index 42950a3b91..deb615304d 100644
--- a/app/src/util/fileTreeReorder.test.ts
+++ b/app/src/util/fileTreeReorder.test.ts
@@ -51,7 +51,7 @@ test("canceling or closing a conflict dialog does not move documents", async ()
test("confirmation applies the full selection and relative anchor", async () => {
const f = fixture([preview(true), applied], true);
- assert.equal(await f.sort(), applied.data);
+ assert.deepEqual({...await f.sort()}, applied.data);
assert.equal(f.requests.length, 2);
assert.equal(f.requests[1].removeSorts, true);
assert.equal(f.requests[1].sourceIDs.join(","), "a,b");
diff --git a/app/src/util/fontPreview.test.ts b/app/src/util/fontPreview.test.ts
index c43f894c30..e634a3b571 100644
--- a/app/src/util/fontPreview.test.ts
+++ b/app/src/util/fontPreview.test.ts
@@ -2,9 +2,8 @@ import * as assert from "node:assert/strict";
import test from "node:test";
import {observeFontPreview} from "./fontPreview";
-test("font previews defer loading, discard invisible items and stop after cleanup", async () => {
- const saved = new Map(["window", "document", "IntersectionObserver", "getComputedStyle", "setTimeout", "clearTimeout",
- "requestAnimationFrame", "cancelAnimationFrame"].map(key =>
+test("font previews load near the viewport, reveal settled labels and stop after cleanup", async () => {
+ const saved = new Map(["window", "document", "IntersectionObserver", "getComputedStyle"].map(key =>
[key, Object.getOwnPropertyDescriptor(globalThis, key)]));
let callback: (entries: unknown[]) => void;
let finish: () => void;
@@ -12,8 +11,6 @@ test("font previews defer loading, discard invisible items and stop after cleanu
let loads = 0;
let applies = 0;
let disconnected = false;
- let scheduled: () => void;
- let nextFrame: () => void;
const pending = () => new Promise<void>((resolve, fail) => {
finish = resolve;
reject = fail;
@@ -26,15 +23,11 @@ test("font previews defer loading, discard invisible items and stop after cleanu
}},
};
const item = {querySelector: () => label};
- const list = {querySelectorAll: () => [item], addEventListener() {}, removeEventListener() {}} as unknown as HTMLElement;
+ const list = {querySelectorAll: () => [item]} as unknown as HTMLElement;
const emit = (visible: boolean) => callback([{target: item, isIntersecting: visible}]);
const apply = () => { applies++; label.style.fontFamily = "Preview"; };
try {
Object.assign(globalThis, {
- setTimeout: (cb: () => void) => { scheduled = cb; return 1; },
- clearTimeout: () => { scheduled = undefined; },
- requestAnimationFrame: (cb: () => void) => { nextFrame = cb; return 1; },
- cancelAnimationFrame: () => { nextFrame = undefined; },
window: {IntersectionObserver: true},
document: {fonts: {load: () => { loads++; return loading; }}},
getComputedStyle: () => ({fontWeight: "400", fontSize: "16px", fontFamily: "Preview"}),
@@ -42,7 +35,7 @@ test("font previews defer loading, discard invisible items and stop after cleanu
constructor(cb: typeof callback, options: IntersectionObserverInit) {
callback = cb;
assert.equal(options.root, list);
- assert.equal(options.rootMargin, undefined);
+ assert.equal(options.rootMargin, "100px 0px");
}
observe() {}
unobserve() {}
@@ -50,27 +43,18 @@ test("font previews defer loading, discard invisible items and stop after cleanu
},
});
const cleanup = observeFontPreview(list, apply);
- assert.equal(label.style.visibility, "");
- emit(false);
- assert.equal(loads, 0);
- emit(true);
- assert.equal(loads, 0);
+ assert.equal(label.style.visibility, "hidden");
emit(false);
- scheduled();
assert.equal(loads, 0);
emit(true);
- scheduled();
assert.equal(loads, 1);
+ assert.equal(applies, 1);
+ assert.equal(label.style.visibility, "hidden");
emit(true);
- scheduled();
assert.equal(loads, 1);
- assert.equal(label.style.visibility, "");
finish();
await loading;
assert.equal(label.style.visibility, "");
- emit(false);
- emit(true);
- assert.equal(applies, 1);
assert.equal(label.style.fontFamily, "Preview");
cleanup();
assert.equal(disconnected, true);
@@ -78,7 +62,6 @@ test("font previews defer loading, discard invisible items and stop after cleanu
loading = pending();
const cleanupFailure = observeFontPreview(list, apply);
emit(true);
- scheduled();
reject(new Error("Font unavailable"));
await loading.catch(() => {});
assert.equal(label.style.visibility, "");
@@ -88,29 +71,22 @@ test("font previews defer loading, discard invisible items and stop after cleanu
loading = pending();
const cleanupPending = observeFontPreview(list, apply);
emit(true);
- scheduled();
cleanupPending();
finish();
await loading;
- assert.equal(label.style.visibility, "");
- assert.equal(scheduled, undefined);
+ assert.equal(label.style.visibility, "hidden");
+ const previousLoads = loads;
+ callback([{target: {querySelector: () => label}, isIntersecting: true}]);
+ assert.equal(loads, previousLoads);
loading = pending();
- const cleanupQueue = observeFontPreview(list, apply);
- const secondItem = {querySelector: () => label};
- callback([{target: item, isIntersecting: true}, {target: secondItem, isIntersecting: true}]);
- scheduled();
- const firstLoadCount = loads;
- assert.equal(nextFrame, undefined);
+ Object.assign(globalThis, {window: {}});
+ const cleanupFallback = observeFontPreview(list, apply);
+ assert.equal(loads, previousLoads + 1);
finish();
await loading;
- await Promise.resolve();
- assert.equal(loads, firstLoadCount);
- assert.equal(typeof nextFrame, "function");
- nextFrame();
- assert.equal(loads, firstLoadCount + 1);
- cleanupQueue();
- assert.equal(nextFrame, undefined);
+ assert.equal(label.style.visibility, "");
+ cleanupFallback();
} finally {
saved.forEach((descriptor, key) => {
if (descriptor) {
diff --git a/app/tests/backlinkReference.test.js b/app/tests/backlinkReference.test.js
index b2e94bbe0e..4bea4700be 100644
--- a/app/tests/backlinkReference.test.js
+++ b/app/tests/backlinkReference.test.js
@@ -6,7 +6,8 @@ const os = require("node:os");
const sources = () => {
const ts = require("typescript");
const modules = {};
- for (const name of ["protyle/wysiwyg/backlinkReference", "protyle/wysiwyg/renderBacklink", "protyle/util/clear"]) {
+ for (const name of ["protyle/wysiwyg/backlinkReference", "protyle/wysiwyg/renderBacklink", "protyle/util/clear",
+ "protyle/render/av/backlinkReuse", "util/escape", "asset/html"]) {
modules[name] = ts.transpileModule(readFileSync(path.join(__dirname, "../src", name + ".ts"), "utf8"), {
compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021},
}).outputText;
@@ -30,6 +31,7 @@ const runCases = async ({modules, css, lute: luteSource}) => {
const cache = {};
const noop = () => {};
const stubs = {
+ "protyle/wysiwyg/backlinkTypeFold": {setBacklinkTypeFoldExpandHandler: noop, updateBacklinkTypeFolds: noop},
"protyle/ui/initUI": {removeLoading: noop},
"protyle/util/processCode": {processRender: noop},
"protyle/render/highlightRender": {highlightRender: noop},
diff --git a/app/tests/mobileBacklinks.test.js b/app/tests/mobileBacklinks.test.js
index 24f308dcc3..a09d313e46 100644
--- a/app/tests/mobileBacklinks.test.js
+++ b/app/tests/mobileBacklinks.test.js
@@ -10,7 +10,8 @@ const sources = () => {
for (const name of ["layout/dock/BacklinkContent", "layout/dock/backlinkRefresh",
"layout/dock/backlinkReadingAnchor", "layout/dock/backlinkSourceFilter", "mobile/util/secondaryEditors",
"mobile/util/backlinkPanels", "mobile/util/openBacklinks", "mobile/util/bindBottomSheetDrag", "mobile/util/bindBottomSheetDialog", "protyle/util/transactionQueue",
- "util/escape", "dialog/index"]) {
+ "util/escape", "dialog/index", "layout/dock/panelSearch", "protyle/wysiwyg/backlinkTypeFold",
+ "layout/dock/backlinkMentionCache", "layout/dock/bottomBacklinkScroll"]) {
modules[name] = ts.transpileModule(preprocess(
readFileSync(path.join(__dirname, "../src", name + ".ts"), "utf8"),
{MOBILE: true, BROWSER: true}, false, true), {
@@ -27,6 +28,9 @@ const runCases = async (sources) => {
const requests = [];
const tick = () => new Promise(resolve => setTimeout(resolve, 10));
const stubs = {
+ "editor/assetOpen": {normalizeAssetOpenConfig: value => value},
+ "layout/dock/backlinkRefFilterMenu": {loadBacklinkRefFilterMenu: noop},
+ "protyle/render/av/editorSession": {hasAVEditorSession: () => false},
"layout/Model": {Model: class {constructor({app}) {this.app = app;} connect() {throw Error("mobile panel opened a desktop socket");}}},
"util/Tree": {Tree: class {
constructor(options) {this.element = options.element; this.options = options;}
@@ -44,7 +48,7 @@ const runCases = async (sources) => {
}},
"mobile/editor": {openMobileFileById: noop},
"util/fetch": {fetchPost: (url, data, callback) => new Promise(resolve => {
- requests.push({url, data, reply: response => {callback?.({data: response}); resolve();}});
+ requests.push({url, data, reply: response => {callback?.({code: 0, data: response}); resolve();}});
})},
"constants": {Constants: {TIMEOUT_LOAD: 0, TIMEOUT_OPENDIALOG: 0, TIMEOUT_DBLCLICK: 0}},
"protyle/util/compatibility": {updateHotkeyAfterTip: () => "", isNotCtrl: () => true},