feat(M7): FR-G1/G4/G5 图谱卡片补全——卡片加文档图标+库内路径副文本(G1); scaleExtent改0.1-2+背景rect绑zoom不拦截点击+适配视图+缩放控件(G4); 点击卡片openDoc(d.id)+切回编辑视图(G5); graph E2E 3 项

This commit is contained in:
hunter-dev
2026-08-26 15:40:56 +08:00
parent 1f3ede9956
commit 52474012c0
4 changed files with 124 additions and 29 deletions
+58 -1
View File
@@ -37,6 +37,63 @@ test('知识图谱:卡片+连线(消费 IPC.graph)', async () => {
// UI:先经 TitleBar 切到图谱视图(view 默认 editor),再切「知识图谱」模式
await a.page.getByTitle('切换 编辑器/图谱').click();
await a.page.getByRole('button', { name: '知识图谱' }).click();
await expect(a.page.locator('svg rect')).toHaveCount(4, { timeout: 10000 });
await expect(a.page.locator('svg rect')).toHaveCount(5, { timeout: 10000 });
await a.app.close();
});
// FR-G4:画布控件——适配视图 + 缩放控件可见
test('FR-G4:画布控件可见 + 适配视图', async () => {
const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-g4-'));
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: 'x', isFolder: false });
await a.invoke('file:create', { basePath: '', name: 'y', isFolder: false });
await a.invoke('doc:write', { path: 'x.md', meta: { title: 'X篇', links: ['y.md'] }, body: '# X' });
await a.invoke('doc:write', { path: 'y.md', meta: { title: 'Y篇' }, body: '# Y' });
await a.page.getByTitle('切换 编辑器/图谱').click();
await a.page.getByRole('button', { name: '知识图谱' }).click();
await a.page.waitForTimeout(1000);
// 控件应可见
await expect(a.page.getByTestId('graph-controls')).toBeVisible({ timeout: 10000 });
// 点击适配视图不应报错
await a.page.getByTestId('fit-view-btn').click({ force: true });
await a.page.waitForTimeout(500);
await a.app.close();
});
// FR-G5:点击卡片切回编辑视图
test('FR-G5:点击卡片切回编辑视图', async () => {
const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-g5-'));
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: 'g5doc', isFolder: false });
await a.invoke('doc:write', { path: 'g5doc.md', meta: { title: 'G5doc' }, body: '# G5' });
await a.page.getByTitle('切换 编辑器/图谱').click();
await a.page.getByRole('button', { name: '知识图谱' }).click();
await a.page.waitForTimeout(3000);
// FR-G5:点击卡片切回编辑视图——直接用 evaluate dispatch click
const result = await a.page.evaluate(() => {
const texts = document.querySelectorAll('svg text');
for (const t of texts) {
if (t.textContent && t.textContent.includes('G5doc')) {
const g = t.closest('g') as Element | null;
if (g) { g.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true })); return true; }
}
}
return false;
});
expect(result).toBe(true);
await a.page.waitForTimeout(1000);
// 验证 openDoc 被调用——store currentPath 应改变
const storeState = await a.page.evaluate(() => {
const s = (window as any).__STORE__;
return s ? { currentPath: s.getState().currentPath } : null;
});
expect(storeState?.currentPath).toContain('g5doc');
await expect(a.page.locator('.ProseMirror')).toBeVisible({ timeout: 5000 });
await a.app.close();
});