fix: repair resource tab and slash menu regressions

This commit is contained in:
lix-2026
2026-05-20 17:47:09 +08:00
parent bbd9dab701
commit 4c62ea7e35
8 changed files with 404 additions and 17 deletions
@@ -78,6 +78,50 @@ async function insertMindmapThroughSlash(page) {
});
}
async function assertSlashMenuAnchorsAfterMindmap(page) {
const editor = page.locator('.document-pane[data-pane-role="primary"] .editor-surface .ProseMirror[contenteditable="true"]').first();
await editor.click({ timeout: UI_TIMEOUT_MS });
await page.keyboard.press(process.platform === "darwin" ? "Meta+End" : "Control+End");
await page.keyboard.type("/");
await page.getByTestId("mnote-leptos-tiptap-slash-menu").waitFor({ state: "visible", timeout: UI_TIMEOUT_MS });
await page.waitForFunction(
() => document.querySelector('[data-testid="mnote-leptos-tiptap-slash-menu"]')?.getAttribute("data-mnote-slash-positioned") === "host",
null,
{ timeout: UI_TIMEOUT_MS },
);
const state = await page.evaluate(() => {
const menu = document.querySelector('[data-testid="mnote-leptos-tiptap-slash-menu"]');
const mindmap = document.querySelector('[data-testid="mnote-mindmap-editor-root"]');
const menuRect = menu?.getBoundingClientRect();
const mindmapRect = mindmap?.getBoundingClientRect();
const pointNode = menuRect
? document.elementFromPoint(menuRect.left + 24, menuRect.top + 24)
: null;
return {
menuRect: menuRect ? { top: menuRect.top, bottom: menuRect.bottom, left: menuRect.left, right: menuRect.right } : null,
mindmapRect: mindmapRect ? { top: mindmapRect.top, bottom: mindmapRect.bottom, left: mindmapRect.left, right: mindmapRect.right } : null,
menuPosition: menu instanceof HTMLElement ? getComputedStyle(menu).position : "",
menuZIndex: menu instanceof HTMLElement ? getComputedStyle(menu).zIndex : "",
hostPositioned: menu instanceof HTMLElement ? menu.getAttribute("data-mnote-slash-positioned") || "" : "",
hitInsideMenu: Boolean(pointNode && menu && menu.contains(pointNode)),
viewportHeight: window.innerHeight,
};
});
assert(state.menuRect, `slash 菜单应可见: ${JSON.stringify(state)}`);
assert.equal(state.menuPosition, "fixed", `slash 菜单应由宿主定位到 viewport 层: ${JSON.stringify(state)}`);
assert(Number(state.menuZIndex) >= 120, `slash 菜单层级应高于 mindmap/块工具: ${JSON.stringify(state)}`);
assert(state.hitInsideMenu, `slash 菜单不应被思维导图或其它层遮挡: ${JSON.stringify(state)}`);
assert(state.menuRect.top >= 0 && state.menuRect.bottom <= state.viewportHeight, `slash 菜单不应超出视口: ${JSON.stringify(state)}`);
if (state.mindmapRect) {
assert(
state.menuRect.top > state.mindmapRect.top - 80,
`mindmap 后输入 / 时菜单不应回退到编辑器左上固定旧位置: ${JSON.stringify(state)}`,
);
}
await page.keyboard.press("Escape");
return state;
}
async function readState(page) {
return page.evaluate(() => {
const editorRoot = document.querySelector('[data-testid="mnote-leptos-tiptap-island-editor-root"]');
@@ -285,6 +329,7 @@ async function main() {
{ timeout: UI_TIMEOUT_MS },
);
result.saveAfterInsert = await waitForStableEditorSave(page, networkRecords, "after-insert");
result.slashMenuAfterMindmap = await assertSlashMenuAnchorsAfterMindmap(page);
result.diskAfterInsert = fs.readdirSync(pageDir).sort();
assert(result.diskAfterInsert.includes("CleanPage.md"), `页面 Markdown 应存在: ${result.diskAfterInsert.join(",")}`);