fix local markdown attachment regressions

This commit is contained in:
lix-2026
2026-05-29 11:13:05 +08:00
parent 1109e3c0d8
commit cbe789e034
63 changed files with 3249 additions and 1502 deletions
@@ -73,6 +73,18 @@ async function waitForVisibleText(page, text) {
);
}
async function waitForAnyPageTreeNode(page, documentIdPrefix) {
await page.waitForFunction(
(prefix) => Array.from(document.querySelectorAll("#sidebar-tree-root .tree-row[data-node-id]"))
.some((row) => {
const id = row.getAttribute("data-node-id") || "";
return id.startsWith(prefix);
}),
documentIdPrefix,
{ timeout: UI_TIMEOUT_MS },
);
}
async function waitForGone(page, selector) {
await page.locator(selector).waitFor({ state: "detached", timeout: UI_TIMEOUT_MS });
}
@@ -84,6 +96,30 @@ async function waitForFileTreeRow(page, rowId) {
});
}
async function expandFileTreeFolder(page, rowId) {
const rowSelector = `.tree-row[data-row-id="${rowId}"]`;
await page.locator(rowSelector).waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
await page.waitForFunction(
(selector) => {
const row = document.querySelector(selector);
return !!row;
},
rowSelector,
{ timeout: UI_TIMEOUT_MS },
);
const expanded = await page.locator(rowSelector).getAttribute("aria-expanded").catch(() => null);
if (expanded === "true") return;
await page.locator(`${rowSelector} [data-rust-action="toggle"]`).click({ timeout: UI_TIMEOUT_MS });
await page.waitForFunction(
(selector) => {
const row = document.querySelector(selector);
return row && row.getAttribute("aria-expanded") === "true";
},
rowSelector,
{ timeout: UI_TIMEOUT_MS },
);
}
async function waitForFileTreeRowGone(page, rowId) {
await waitForGone(page, `.tree-row[data-row-id="${rowId}"]`);
}
@@ -108,15 +144,18 @@ async function waitForPageTreeNodeGone(page, documentId) {
async function waitForLocalFolderWatchProjectionApplied(page) {
await page.waitForFunction(
() => document.documentElement.getAttribute("data-mnote-local-folder-watch-applied") === "projection",
() => {
const value = document.documentElement.getAttribute("data-mnote-local-folder-watch-applied") || "";
return value === "projection" || value === "watch_batch";
},
{ timeout: UI_TIMEOUT_MS },
);
const appliedValue = await page.evaluate(
() => document.documentElement.getAttribute("data-mnote-local-folder-watch-applied"),
);
assert(
appliedValue === "projection",
`local_folder watch 应通过 projection 应用,实际 data-mnote-local-folder-watch-applied=${appliedValue}`,
appliedValue === "projection" || appliedValue === "watch_batch",
`local_folder 变更应通过事件驱动 projection/watch_batch 应用,实际 data-mnote-local-folder-watch-applied=${appliedValue}`,
);
}
@@ -159,15 +198,19 @@ async function run() {
}
});
const steps = [];
const steps = [];
try {
await quickLogin(page);
await page.goto(treeUrl(root, "page"), { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
await waitForVisibleText(page, "Local Root");
await waitForVisibleText(page, "stable");
await page.waitForResponse((response) => response.url().includes("/api/tree/local-folder-watch") && response.ok(), {
timeout: UI_TIMEOUT_MS,
}).catch(() => {});
await waitForAnyPageTreeNode(page, "local-md:");
await waitForPageTreeNode(page, localMdDocumentId("docs/stable.md"));
await page.waitForFunction(
() => {
const transport = document.documentElement.getAttribute("data-mnote-tree-live-transport") || "";
return transport === "local-folder-events";
},
{ timeout: UI_TIMEOUT_MS },
);
await page.waitForTimeout(100);
navigationEvents.length = 0;
@@ -195,10 +238,15 @@ async function run() {
await page.goto(treeUrl(root, "filetree"), { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
await waitForFileTreeRow(page, "local:folder:docs");
await expandFileTreeFolder(page, "local:folder:docs");
await waitForFileTreeRow(page, "local:asset:docs/stable-asset.txt");
await page.waitForResponse((response) => response.url().includes("/api/tree/local-folder-watch") && response.ok(), {
timeout: UI_TIMEOUT_MS,
}).catch(() => {});
await page.waitForFunction(
() => {
const transport = document.documentElement.getAttribute("data-mnote-tree-live-transport") || "";
return transport === "local-folder-events";
},
{ timeout: UI_TIMEOUT_MS },
);
await page.waitForTimeout(100);
navigationEvents.length = 0;