mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-10 16:53:35 +08:00
- 后端读取 SQL 文件失败时返回 file_not_found 结构化错误码 - 前端识别文件被删除或移动的场景,允许用户确认关闭标签 - 保留权限、网络盘异常等非缺失错误的关闭拦截,避免误丢草稿 - 补充前后端测试覆盖缺失文件识别与标签关闭提示 Close #566
60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
getSQLFileTabPath,
|
|
hasSQLFileTabUnsavedChanges,
|
|
isSQLFileMissingErrorMessage,
|
|
isSQLFileMissingReadResult,
|
|
isSQLFileQueryTab,
|
|
normalizeSQLFileReadContent,
|
|
} from './sqlFileTabDirty';
|
|
|
|
describe('sqlFileTabDirty', () => {
|
|
it('only treats query tabs with filePath as SQL file tabs', () => {
|
|
expect(isSQLFileQueryTab({ type: 'query', filePath: '/tmp/a.sql' })).toBe(true);
|
|
expect(isSQLFileQueryTab({ type: 'query', filePath: ' ' })).toBe(false);
|
|
expect(isSQLFileQueryTab({ type: 'table', filePath: '/tmp/a.sql' } as any)).toBe(false);
|
|
expect(getSQLFileTabPath({ type: 'query', filePath: ' /tmp/a.sql ' })).toBe('/tmp/a.sql');
|
|
});
|
|
|
|
it('normalizes old and new SQL file read payloads', () => {
|
|
expect(normalizeSQLFileReadContent('select 1;')).toBe('select 1;');
|
|
expect(normalizeSQLFileReadContent({ content: 'select 2;', filePath: '/tmp/a.sql' })).toBe('select 2;');
|
|
expect(normalizeSQLFileReadContent({ isLargeFile: true, filePath: '/tmp/a.sql' })).toBe('');
|
|
});
|
|
|
|
it('detects unsaved changes by comparing tab query with disk content', () => {
|
|
expect(hasSQLFileTabUnsavedChanges({
|
|
type: 'query',
|
|
filePath: '/tmp/a.sql',
|
|
query: 'select 1;',
|
|
} as any, 'select 1;')).toBe(false);
|
|
|
|
expect(hasSQLFileTabUnsavedChanges({
|
|
type: 'query',
|
|
filePath: '/tmp/a.sql',
|
|
query: 'select 2;',
|
|
} as any, 'select 1;')).toBe(true);
|
|
});
|
|
|
|
it('detects missing SQL file read failures by structured error code', () => {
|
|
expect(isSQLFileMissingReadResult({
|
|
success: false,
|
|
message: '无法读取文件信息: stat /tmp/missing.sql: no such file or directory',
|
|
data: { errorCode: 'file_not_found', filePath: '/tmp/missing.sql' },
|
|
})).toBe(true);
|
|
|
|
expect(isSQLFileMissingReadResult({
|
|
success: false,
|
|
message: '无法读取文件信息: permission denied',
|
|
data: { filePath: '/tmp/report.sql' },
|
|
})).toBe(false);
|
|
});
|
|
|
|
it('keeps platform-specific missing file messages as a fallback', () => {
|
|
expect(isSQLFileMissingErrorMessage('GetFileAttributesEx C:\\Users\\me\\missing.sql: The system cannot find the file specified.')).toBe(true);
|
|
expect(isSQLFileMissingErrorMessage('stat /Users/me/missing.sql: no such file or directory')).toBe(true);
|
|
expect(isSQLFileMissingErrorMessage('无法读取文件信息: 权限不足')).toBe(false);
|
|
});
|
|
});
|