mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-20 12:21:54 +08:00
✨ feat(external-sql): 完善外部 SQL 目录文件管理
- 新增外部 SQL 文件的新建、重命名、删除和目录管理接口 - 后端限制 SQL 目录只加载 .sql 文件并补充目录操作测试 - 前端补齐 Wails 类型、浏览器 mock 和外部 SQL 树过滤逻辑 - 支持从外部 SQL 文件标签定位到侧栏目录节点
This commit is contained in:
@@ -10,8 +10,6 @@ describe('externalSqlTree helpers', () => {
|
||||
id: 'dir-1',
|
||||
name: 'scripts',
|
||||
path: 'D:/sql/scripts',
|
||||
connectionId: 'conn-1',
|
||||
dbName: 'demo',
|
||||
createdAt: 1,
|
||||
},
|
||||
];
|
||||
@@ -33,14 +31,12 @@ describe('externalSqlTree helpers', () => {
|
||||
};
|
||||
|
||||
const node = buildExternalSQLRootNode({
|
||||
dbNodeKey: 'conn-1-demo',
|
||||
connectionId: 'conn-1',
|
||||
dbName: 'demo',
|
||||
directories,
|
||||
directoryTrees: trees,
|
||||
});
|
||||
|
||||
expect(node.type).toBe('external-sql-root');
|
||||
expect(node.key).toBe('external-sql-root');
|
||||
expect(node.title).toBe('外部 SQL 目录 (1)');
|
||||
expect(node.children).toHaveLength(1);
|
||||
expect(node.children?.[0]).toMatchObject({
|
||||
@@ -65,4 +61,77 @@ describe('externalSqlTree helpers', () => {
|
||||
expect(first).toContain('demo');
|
||||
expect(first).not.toBe(second);
|
||||
});
|
||||
|
||||
it('filters non-sql file entries even when the backend returns them', () => {
|
||||
const directories: ExternalSQLDirectory[] = [
|
||||
{
|
||||
id: 'dir-1',
|
||||
name: 'scripts',
|
||||
path: 'D:/sql/scripts',
|
||||
createdAt: 1,
|
||||
},
|
||||
];
|
||||
const trees: Record<string, ExternalSQLTreeEntry[]> = {
|
||||
'dir-1': [
|
||||
{
|
||||
name: 'readme.md',
|
||||
path: 'D:/sql/scripts/readme.md',
|
||||
isDir: false,
|
||||
},
|
||||
{
|
||||
name: 'nested',
|
||||
path: 'D:/sql/scripts/nested',
|
||||
isDir: true,
|
||||
children: [
|
||||
{
|
||||
name: 'notes.txt',
|
||||
path: 'D:/sql/scripts/nested/notes.txt',
|
||||
isDir: false,
|
||||
},
|
||||
{
|
||||
name: 'report.SQL',
|
||||
path: 'D:/sql/scripts/nested/report.SQL',
|
||||
isDir: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'docs',
|
||||
path: 'D:/sql/scripts/docs',
|
||||
isDir: true,
|
||||
children: [
|
||||
{
|
||||
name: 'manual.md',
|
||||
path: 'D:/sql/scripts/docs/manual.md',
|
||||
isDir: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const node = buildExternalSQLRootNode({
|
||||
directories,
|
||||
directoryTrees: trees,
|
||||
});
|
||||
|
||||
const folderChildren = node.children?.[0].children || [];
|
||||
const docsFolder = folderChildren.find((child) => child.title === 'docs');
|
||||
const nestedFolder = folderChildren.find((child) => child.title === 'nested');
|
||||
expect(folderChildren).toHaveLength(2);
|
||||
expect(docsFolder).toMatchObject({
|
||||
title: 'docs',
|
||||
type: 'external-sql-folder',
|
||||
});
|
||||
expect(docsFolder?.children).toBeUndefined();
|
||||
expect(nestedFolder).toMatchObject({
|
||||
title: 'nested',
|
||||
type: 'external-sql-folder',
|
||||
});
|
||||
expect(nestedFolder?.children).toHaveLength(1);
|
||||
expect(nestedFolder?.children?.[0]).toMatchObject({
|
||||
title: 'report.SQL',
|
||||
type: 'external-sql-file',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user