Files
MyGoNavi/frontend/src/components/QueryEditorToolbar.i18n.test.ts
2026-06-28 12:08:40 +08:00

74 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
const source = readFileSync(new URL('./QueryEditorToolbar.tsx', import.meta.url), 'utf8');
const legacyLiterals = [
'隐藏结果区',
'显示结果区',
'生成 SQL',
'解释 SQL',
'优化 SQL',
'Schema 分析',
'选择连接',
'选择数据库',
'最大返回行数',
'最大行数500',
'最大行数1000',
'最大行数5000',
'最大行数20000',
'最大行数:不限',
'运行',
'停止',
'保存',
'更多',
'美化 SQL',
'美化',
'结果',
];
const requiredKeys = [
'query_editor.placeholder.connection',
'query_editor.placeholder.database',
'query_editor.max_rows.tooltip',
'query_editor.max_rows.option_500',
'query_editor.max_rows.option_1000',
'query_editor.max_rows.option_5000',
'query_editor.max_rows.option_20000',
'query_editor.max_rows.option_unlimited',
'query_editor.action.run',
'query_editor.action.run_with_shortcut',
'query_editor.action.stop',
'query_editor.action.save',
'query_editor.action.save_with_shortcut',
'query_editor.action.more',
'query_editor.action.format',
'query_editor.action.format_sql',
'query_editor.action.format_sql_with_shortcut',
'query_editor.action.ai_generate_sql_menu',
'query_editor.action.ai_explain_sql_menu',
'query_editor.action.ai_optimize_sql_menu',
'query_editor.action.ai_schema_analysis',
'query_editor.action.show_results_panel',
'query_editor.action.hide_results_panel',
'query_editor.action.show_results_panel_with_shortcut',
'query_editor.action.hide_results_panel_with_shortcut',
'query_editor.action.results',
];
describe('QueryEditorToolbar i18n', () => {
it('uses localized keys for toolbar chrome', () => {
expect(source).toContain("import { useOptionalI18n } from '../i18n/provider';");
expect(source).toContain('const i18n = useOptionalI18n();');
expect(source).toContain('const t = i18n?.t ?? defaultTranslate;');
for (const key of requiredKeys) {
expect(source).toContain(key);
}
for (const literal of legacyLiterals) {
expect(source).not.toContain(literal);
}
});
});