refactor: extract filetree projection helpers
This commit is contained in:
@@ -106,8 +106,25 @@ async function waitForPageTreeNodeGone(page, documentId) {
|
||||
);
|
||||
}
|
||||
|
||||
async function runStep(label, navigationEvents, action) {
|
||||
async function waitForLocalFolderWatchProjectionApplied(page) {
|
||||
await page.waitForFunction(
|
||||
() => document.documentElement.getAttribute("data-mnote-local-folder-watch-applied") === "projection",
|
||||
{ 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}`,
|
||||
);
|
||||
}
|
||||
|
||||
async function runStep(page, label, navigationEvents, action) {
|
||||
const before = navigationEvents.length;
|
||||
await page.evaluate(() => {
|
||||
document.documentElement.removeAttribute("data-mnote-local-folder-watch-applied");
|
||||
});
|
||||
await action();
|
||||
const after = navigationEvents.length;
|
||||
assert(after === before, `${label} 不应触发浏览器导航或 reload,before=${before} after=${after}`);
|
||||
@@ -147,30 +164,33 @@ async function run() {
|
||||
await quickLogin(page);
|
||||
await page.goto(treeUrl(root, "page"), { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
|
||||
await waitForVisibleText(page, "Local Root");
|
||||
await waitForVisibleText(page, "Stable Page");
|
||||
await waitForVisibleText(page, "stable");
|
||||
await page.waitForResponse((response) => response.url().includes("/api/tree/local-folder-watch") && response.ok(), {
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
}).catch(() => {});
|
||||
await page.waitForTimeout(100);
|
||||
navigationEvents.length = 0;
|
||||
|
||||
steps.push(await runStep("Markdown 外部创建后 page tree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "Markdown 外部创建后 page tree 原地更新", navigationEvents, async () => {
|
||||
fs.writeFileSync(path.join(root, "docs", "watcher-create.md"), "# Watcher Create\n", "utf8");
|
||||
await waitForPageTreeNode(page, localMdDocumentId("docs/watcher-create.md"));
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("Markdown 外部重命名后 page tree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "Markdown 外部重命名后 page tree 原地更新", navigationEvents, async () => {
|
||||
fs.renameSync(
|
||||
path.join(root, "docs", "watcher-create.md"),
|
||||
path.join(root, "docs", "watcher-renamed.md"),
|
||||
);
|
||||
await waitForPageTreeNode(page, localMdDocumentId("docs/watcher-renamed.md"));
|
||||
await waitForPageTreeNodeGone(page, localMdDocumentId("docs/watcher-create.md"));
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("Markdown 外部删除后 page tree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "Markdown 外部删除后 page tree 原地更新", navigationEvents, async () => {
|
||||
fs.rmSync(path.join(root, "docs", "watcher-renamed.md"));
|
||||
await waitForPageTreeNodeGone(page, localMdDocumentId("docs/watcher-renamed.md"));
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
await page.goto(treeUrl(root, "filetree"), { waitUntil: "domcontentloaded", timeout: UI_TIMEOUT_MS });
|
||||
@@ -182,61 +202,70 @@ async function run() {
|
||||
await page.waitForTimeout(100);
|
||||
navigationEvents.length = 0;
|
||||
|
||||
steps.push(await runStep("Markdown 外部创建后 filetree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "Markdown 外部创建后 filetree 原地更新", navigationEvents, async () => {
|
||||
fs.writeFileSync(path.join(root, "docs", "watcher-filetree-md.md"), "# Watcher Filetree Markdown\n", "utf8");
|
||||
await waitForFileTreeRow(page, "local:markdown:docs/watcher-filetree-md.md");
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("Markdown 外部重命名后 filetree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "Markdown 外部重命名后 filetree 原地更新", navigationEvents, async () => {
|
||||
fs.renameSync(
|
||||
path.join(root, "docs", "watcher-filetree-md.md"),
|
||||
path.join(root, "docs", "watcher-filetree-md-renamed.md"),
|
||||
);
|
||||
await waitForFileTreeRow(page, "local:markdown:docs/watcher-filetree-md-renamed.md");
|
||||
await waitForFileTreeRowGone(page, "local:markdown:docs/watcher-filetree-md.md");
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("Markdown 外部删除后 filetree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "Markdown 外部删除后 filetree 原地更新", navigationEvents, async () => {
|
||||
fs.rmSync(path.join(root, "docs", "watcher-filetree-md-renamed.md"));
|
||||
await waitForFileTreeRowGone(page, "local:markdown:docs/watcher-filetree-md-renamed.md");
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("非 md 资源外部创建后 filetree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "非 md 资源外部创建后 filetree 原地更新", navigationEvents, async () => {
|
||||
fs.writeFileSync(path.join(root, "docs", "watcher-asset.txt"), "watcher asset", "utf8");
|
||||
await waitForFileTreeRow(page, "local:asset:docs/watcher-asset.txt");
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("非 md 资源外部重命名后 filetree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "非 md 资源外部重命名后 filetree 原地更新", navigationEvents, async () => {
|
||||
fs.renameSync(
|
||||
path.join(root, "docs", "watcher-asset.txt"),
|
||||
path.join(root, "docs", "watcher-asset-renamed.txt"),
|
||||
);
|
||||
await waitForFileTreeRow(page, "local:asset:docs/watcher-asset-renamed.txt");
|
||||
await waitForFileTreeRowGone(page, "local:asset:docs/watcher-asset.txt");
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("非 md 资源外部删除后 filetree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "非 md 资源外部删除后 filetree 原地更新", navigationEvents, async () => {
|
||||
fs.rmSync(path.join(root, "docs", "watcher-asset-renamed.txt"));
|
||||
await waitForFileTreeRowGone(page, "local:asset:docs/watcher-asset-renamed.txt");
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("第二类非 md 资源外部创建后 filetree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "第二类非 md 资源外部创建后 filetree 原地更新", navigationEvents, async () => {
|
||||
fs.writeFileSync(path.join(root, "docs", "watcher-image.png"), "png", "utf8");
|
||||
await waitForFileTreeRow(page, "local:asset:docs/watcher-image.png");
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("第二类非 md 资源外部重命名后 filetree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "第二类非 md 资源外部重命名后 filetree 原地更新", navigationEvents, async () => {
|
||||
fs.renameSync(
|
||||
path.join(root, "docs", "watcher-image.png"),
|
||||
path.join(root, "docs", "watcher-image-renamed.png"),
|
||||
);
|
||||
await waitForFileTreeRow(page, "local:asset:docs/watcher-image-renamed.png");
|
||||
await waitForFileTreeRowGone(page, "local:asset:docs/watcher-image.png");
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
steps.push(await runStep("第二类非 md 资源外部删除后 filetree 原地更新", navigationEvents, async () => {
|
||||
steps.push(await runStep(page, "第二类非 md 资源外部删除后 filetree 原地更新", navigationEvents, async () => {
|
||||
fs.rmSync(path.join(root, "docs", "watcher-image-renamed.png"));
|
||||
await waitForFileTreeRowGone(page, "local:asset:docs/watcher-image-renamed.png");
|
||||
await waitForLocalFolderWatchProjectionApplied(page);
|
||||
}));
|
||||
|
||||
const result = {
|
||||
|
||||
Reference in New Issue
Block a user