mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-22 13:17:10 +08:00
🐛 fix(query-editor): 修复切换查询页后 SQL 美化方言误判
- 同步查询页的 connectionId 与 dbName 状态 - 美化时按活动连接和 tab 上下文兜底选择格式化方言 - 补充 PostgreSQL ::date 场景回归测试 Close #494
This commit is contained in:
@@ -522,8 +522,20 @@ describe('QueryEditor external SQL save', () => {
|
||||
backendApp.DBGetDatabases.mockResolvedValue({ success: true, data: [] });
|
||||
backendApp.DBGetTables.mockResolvedValue({ success: true, data: [] });
|
||||
backendApp.GenerateQueryID.mockResolvedValue('query-1');
|
||||
storeState.connections[0].config.type = 'mysql';
|
||||
storeState.connections[0].config.database = 'main';
|
||||
storeState.connections = [
|
||||
{
|
||||
id: 'conn-1',
|
||||
name: 'local',
|
||||
config: {
|
||||
type: 'mysql',
|
||||
host: '127.0.0.1',
|
||||
port: 3306,
|
||||
user: 'root',
|
||||
password: '',
|
||||
database: 'main',
|
||||
},
|
||||
},
|
||||
];
|
||||
storeState.appearance.uiVersion = 'legacy';
|
||||
autoFetchState.visible = false;
|
||||
dataGridState.latestProps = null;
|
||||
@@ -1508,6 +1520,79 @@ describe('QueryEditor external SQL save', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('formats postgres cast syntax after switching to another query tab connection', async () => {
|
||||
let renderer!: ReactTestRenderer;
|
||||
storeState.connections = [
|
||||
{
|
||||
id: 'conn-1',
|
||||
name: 'mysql-local',
|
||||
config: {
|
||||
type: 'mysql',
|
||||
host: '127.0.0.1',
|
||||
port: 3306,
|
||||
user: 'root',
|
||||
password: '',
|
||||
database: 'main',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'conn-2',
|
||||
name: 'pg-local',
|
||||
config: {
|
||||
type: 'postgres',
|
||||
host: '127.0.0.1',
|
||||
port: 5432,
|
||||
user: 'postgres',
|
||||
password: '',
|
||||
database: 'main',
|
||||
},
|
||||
},
|
||||
];
|
||||
const pgSql = [
|
||||
'SELECT',
|
||||
' *,',
|
||||
' is_del = 0',
|
||||
'FROM',
|
||||
' wm_stock',
|
||||
'WHERE',
|
||||
' 1 = 1',
|
||||
' AND is_del = 0',
|
||||
" and create_date > '2025-06-25'::date;",
|
||||
].join('\n');
|
||||
|
||||
await act(async () => {
|
||||
renderer = create(<QueryEditor tab={createTab({ id: 'tab-1', connectionId: 'conn-1', query: 'select 1;' })} />);
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
renderer.update(
|
||||
<QueryEditor
|
||||
tab={createTab({
|
||||
id: 'tab-2',
|
||||
connectionId: 'conn-2',
|
||||
dbName: 'main',
|
||||
query: pgSql,
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
|
||||
const formatButton = findButton(renderer, '美化');
|
||||
await act(async () => {
|
||||
await formatButton.props.onClick();
|
||||
});
|
||||
|
||||
expect(messageApi.error).not.toHaveBeenCalled();
|
||||
expect(editorState.editor.executeEdits).toHaveBeenCalledWith(
|
||||
'gonavi-format-sql',
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
text: expect.stringContaining("'2025-06-25'::date;"),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it('shows object info via editor ctrl+q action', async () => {
|
||||
editorState.value = 'select users.id from users';
|
||||
autoFetchState.visible = true;
|
||||
|
||||
Reference in New Issue
Block a user