fix(mnote-web): 即时显示页面内新建思维导图
This commit is contained in:
@@ -41,6 +41,44 @@ async function readCreatedState(page, documentId) {
|
||||
}, documentId);
|
||||
}
|
||||
|
||||
async function insertMindmapThroughSlash(page) {
|
||||
const editor = page
|
||||
.locator('[data-testid="mnote-leptos-tiptap-island-editor-root"] .editor-surface .ProseMirror[contenteditable="true"]')
|
||||
.first();
|
||||
await editor.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
|
||||
await editor.click({ timeout: UI_TIMEOUT_MS });
|
||||
await page.keyboard.type("/");
|
||||
const item = page.getByTestId("slash-item-mindmap").first();
|
||||
await item.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
|
||||
await item.click({ timeout: UI_TIMEOUT_MS });
|
||||
const root = page.getByTestId("mnote-mindmap-editor-root").first();
|
||||
await root.waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
|
||||
const mindmapId = await root.evaluate((node) => node instanceof HTMLElement ? node.dataset.mnoteMindmapId || "" : "");
|
||||
assert(mindmapId, "新建思维导图后缺少 mindmapId");
|
||||
return mindmapId;
|
||||
}
|
||||
|
||||
async function readMindmapAssetState(page, documentId, mindmapId) {
|
||||
return page.evaluate(
|
||||
({ documentId: docId, mindmapId: assetId }) => {
|
||||
const rows = Array.from(document.querySelectorAll("#sidebar-file-tree-root .tree-row[data-shell-mode=\"filetree\"]"))
|
||||
.filter((row) => row.getAttribute("data-asset-id") === assetId)
|
||||
.map((row) => ({
|
||||
rowId: row.getAttribute("data-row-id"),
|
||||
docId: row.getAttribute("data-doc-id") || row.getAttribute("data-document-id"),
|
||||
title: row.textContent?.trim() || "",
|
||||
kind: row.querySelector(".tree-kind-badge")?.getAttribute("data-kind") || "",
|
||||
}));
|
||||
return {
|
||||
rows,
|
||||
localApplied: document.documentElement.getAttribute("data-mnote-assets-local-applied") || "",
|
||||
expectedDocId: docId,
|
||||
};
|
||||
},
|
||||
{ documentId, mindmapId },
|
||||
);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await fs.mkdir(OUT_DIR, { recursive: true });
|
||||
const browser = await chromium.launch({ headless: process.env.HEADFUL !== "1" });
|
||||
@@ -49,7 +87,7 @@ async function main() {
|
||||
const requests = [];
|
||||
page.on("response", (response) => {
|
||||
const url = response.url();
|
||||
if (url.includes("/api/tree/commands") || url.includes("/api/sidebar") || url.includes("/api/tree/events")) {
|
||||
if (url.includes("/api/tree/commands") || url.includes("/api/sidebar") || url.includes("/api/tree/events") || url.includes("/api/mindmap/")) {
|
||||
requests.push({ url, status: response.status() });
|
||||
}
|
||||
});
|
||||
@@ -78,6 +116,20 @@ async function main() {
|
||||
assert.equal(afterCreate.pageRows, 1, "Page Tree 应立即出现新页面");
|
||||
assert.deepEqual(afterCreate.fileRows.sort(), [`doc:${createdDocumentId}`, `index:${createdDocumentId}`].sort(), "File Tree 应立即出现新页面 doc/index 行");
|
||||
|
||||
const mindmapId = await insertMindmapThroughSlash(page);
|
||||
await page.waitForFunction(
|
||||
({ assetId }) => {
|
||||
return Boolean(document.querySelector(`#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-asset-id="${CSS.escape(assetId)}"]`));
|
||||
},
|
||||
{ assetId: mindmapId },
|
||||
{ timeout: UI_TIMEOUT_MS },
|
||||
);
|
||||
const afterMindmapCreate = await readMindmapAssetState(page, createdDocumentId, mindmapId);
|
||||
assert.equal(afterMindmapCreate.localApplied, "true", "新建思维导图应由 assets-changed 本地 apply 到 File Tree");
|
||||
assert.equal(afterMindmapCreate.rows.length, 1, "File Tree 应立即出现新建思维导图 asset 行");
|
||||
assert.equal(afterMindmapCreate.rows[0].rowId, `asset:${mindmapId}`, "File Tree mindmap rowId 应匹配 asset id");
|
||||
assert.equal(afterMindmapCreate.rows[0].docId, createdDocumentId, "File Tree mindmap asset 应挂在当前页面下");
|
||||
|
||||
const rowSelector = `#sidebar-tree-root .tree-row[data-shell-mode="page"][data-node-id="${cssString(createdDocumentId)}"]`;
|
||||
await page.locator(rowSelector).scrollIntoViewIfNeeded({ timeout: UI_TIMEOUT_MS });
|
||||
page.once("dialog", async (dialog) => {
|
||||
@@ -105,7 +157,9 @@ async function main() {
|
||||
baseUrl: BASE_URL,
|
||||
beforeCount,
|
||||
createdDocumentId,
|
||||
mindmapId,
|
||||
afterCreate,
|
||||
afterMindmapCreate,
|
||||
afterDelete,
|
||||
requests,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user