- 思维导图: pill/chip 样式节点, 类型着色(root/folder/doc), 图标, 子节点计数徽标 - 知识图谱: 卡片圆角+投影+类型图标+星标, 悬停高亮 - 点击文档节点(思维导图/图谱)切换到编辑器界面 - 新增思维导图跳转 E2E 测试
54 lines
2.5 KiB
TypeScript
54 lines
2.5 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
||
import { _electron as electron } from 'playwright';
|
||
import { promises as fs } from 'node:fs';
|
||
import nodePath from 'node:path';
|
||
import os from 'node:os';
|
||
|
||
const MAIN_JS = nodePath.join(process.cwd(), 'dist-electron/main/index.js');
|
||
|
||
async function launch(userData: string) {
|
||
const app = await electron.launch({ args: ['--user-data-dir=' + userData, MAIN_JS] });
|
||
const page = await app.firstWindow();
|
||
await page.waitForLoadState('domcontentloaded');
|
||
await page.waitForTimeout(800);
|
||
const invoke = (ch: string, args: any) => page.evaluate(({ ch, args }) => (globalThis as any).dsh.invoke(ch, args), { ch, args });
|
||
return { app, page, invoke };
|
||
}
|
||
|
||
// 点击思维导图中的文档节点:应打开文档并切回编辑器界面
|
||
test('思维导图点击文档节点 → 打开文档并切回编辑界面', async () => {
|
||
const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-mmnav-'));
|
||
const ud = nodePath.join(tmp, 'ud'); const v = nodePath.join(tmp, 'v');
|
||
await fs.mkdir(ud, { recursive: true }); await fs.mkdir(v, { recursive: true });
|
||
const a = await launch(ud);
|
||
await a.invoke('vault:switch', { root: v });
|
||
await a.invoke('file:create', { basePath: '', name: 'MindNav', isFolder: false });
|
||
await a.invoke('doc:write', { path: 'MindNav.md', meta: { title: 'MindNav' }, body: '# MindNav' });
|
||
await a.page.evaluate(() => (globalThis as any).__STORE__?.getState?.().loadTree());
|
||
await a.page.waitForTimeout(800);
|
||
// 切到图谱视图(默认思维导图模式)
|
||
await a.page.getByTitle('切换 编辑器/图谱').click();
|
||
await a.page.waitForTimeout(2500);
|
||
// 找到思维导图中的文档节点并点击(.mm-pill.mm-doc)
|
||
const clicked = await a.page.evaluate(() => {
|
||
const pills = document.querySelectorAll('.mm-pill.mm-doc');
|
||
for (const p of pills) {
|
||
if (p.textContent && p.textContent.includes('MindNav')) {
|
||
(p as HTMLElement).dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }));
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
});
|
||
expect(clicked).toBe(true);
|
||
await a.page.waitForTimeout(1500);
|
||
// 应打开文档并切回编辑器视图(ProseMirror 可见)
|
||
await expect(a.page.locator('.ProseMirror')).toBeVisible({ timeout: 5000 });
|
||
const storeState = await a.page.evaluate(() => {
|
||
const s = (window as any).__STORE__;
|
||
return s ? { currentPath: s.getState().currentPath } : null;
|
||
});
|
||
expect(storeState?.currentPath).toContain('MindNav');
|
||
await a.app.close();
|
||
});
|