Files
dbx/packages/app-tests/tableStructureEditorPresentation.test.ts
T
Abeautifulsnow 310cc22b37 Fix/disable table comment for unsupported db (#518)
* fix(structure-editor): disable table comment input for databases that don't support comments (e.g. SQLite)

## 背景说明
SQLite 不支持表注释(COMMENT),但表注释输入框始终可编辑。用户修改注释后,SQL 预览显示暂无变更且应用变更按钮不可用,造成困惑的 UX。

## 修改内容
- 新增 isTableCommentDisabled 计算属性,基于 structureCapabilities.comment 控制禁用状态
- 表注释 Input 添加 :disabled 绑定,禁用时输入框变灰不可编辑
- 禁用时在输入框右侧显示 Info 图标,hover 显示 Tooltip 说明
- 三语言(zh-CN / en / es)新增 tableCommentUnsupported 翻译

## 影响范围
- SQLite、DuckDB 及未知数据库类型:输入框被禁用 + Tooltip 提示
- MySQL、PostgreSQL、ClickHouse 等支持注释的数据库:完全不受影响
- 后端 generate_comment_ddl 已有对等过滤(仅 Postgres/Oracle/ClickHouse 生成 COMMENT SQL)

## 测试
- 建议补充:dbType 为 sqlite 时 isTableCommentDisabled 为 true 的单元测试

* test(structure-editor): add tests for table comment disabled state and unsupported DB capabilities
2026-05-29 12:29:50 +08:00

91 lines
4.4 KiB
TypeScript

import { readFileSync } from "node:fs";
import { strict as assert } from "node:assert";
import test from "node:test";
const source = readFileSync("apps/desktop/src/components/structure/TableStructureEditor.vue", "utf8");
const clickhouseSource = readFileSync("crates/dbx-core/src/db/clickhouse_driver.rs", "utf8");
test("column comments can be expanded into a multiline editor", () => {
assert.match(source, /PopoverContent/);
assert.match(source, /v-model="column\.comment"/);
assert.match(source, /<textarea[\s\S]*v-model="column\.comment"/);
assert.match(source, /t\("structureEditor\.editComment"\)/);
});
test("structure editor keeps columns when optional metadata fails", () => {
assert.match(source, /const nextColumns = await api\.getColumns/);
assert.match(source, /api\.listIndexes[\s\S]*?\.catch\(\(\) => \[\]\)/);
assert.match(source, /api\.listForeignKeys[\s\S]*?\.catch\(\(\) => \[\]\)/);
assert.match(source, /api\.listTriggers[\s\S]*?\.catch\(\(\) => \[\]\)/);
});
test("ClickHouse column metadata preserves comments for structure editing", () => {
assert.match(clickhouseSource, /SELECT name, type, default_kind, default_expression, is_in_primary_key, comment/);
assert.match(clickhouseSource, /comment:\s*row\.get\(5\)/);
});
test("structure editor loads table metadata on mount", () => {
assert.match(source, /async function loadStructure/);
assert.match(source, /api\.getColumns/);
assert.match(source, /api\.listIndexes/);
assert.match(source, /api\.listForeignKeys/);
assert.match(source, /api\.listTriggers/);
});
test("structure editor gates controls through table structure capabilities", () => {
assert.match(source, /getTableStructureCapabilities/);
assert.match(source, /const structureCapabilities = computed/);
assert.match(source, /function isColumnNameDisabled/);
assert.match(source, /function isColumnTypeDisabled/);
assert.match(source, /function isColumnDefaultDisabled/);
assert.match(source, /function isColumnCommentDisabled/);
assert.match(source, /function canDropColumn/);
assert.match(source, /function canEditIndexDraft/);
assert.match(source, /structureCapabilities\.value\.createIndex/);
assert.match(source, /structureCapabilities\.value\.dropIndex/);
assert.match(source, /structureCapabilities\.value\.indexInclude/);
assert.match(source, /structureCapabilities\.value\.indexFilter/);
});
test("structure editor exposes column order controls", () => {
assert.match(source, /function moveColumn/);
assert.match(source, /@click="moveColumn\(index, -1\)"/);
assert.match(source, /@click="moveColumn\(index, 1\)"/);
assert.match(source, /t\(['"]structureEditor\.moveColumnUp['"]\)/);
assert.match(source, /t\(['"]structureEditor\.moveColumnDown['"]\)/);
});
test("structure editor uses a dense wide layout for large tables", () => {
assert.match(source, /grid-cols-\[minmax\(0,1fr\)_300px\]/);
assert.match(source, /data-structure-density="compact"/);
assert.match(source, /class="h-6 min-w-28 text-\[11px\]"/);
assert.match(source, /w-36/);
assert.match(source, /w-24/);
});
test("structure editor keeps the table body vertically scrollable", () => {
assert.match(source, /class="flex h-full min-h-0 flex-col gap-2 overflow-hidden p-3 text-\[11px\]"/);
assert.match(source, /class="grid min-h-0 flex-1 grid-cols-\[minmax\(0,1fr\)_300px\] gap-2 overflow-hidden"/);
assert.match(source, /class="min-h-0 min-w-0 overflow-hidden rounded-md border"/);
assert.match(source, /class="flex h-full min-h-0 flex-col"/);
assert.match(source, /<TabsContent value="columns" class="m-0 min-h-0 flex-1 overflow-auto p-0">/);
});
test("new column input is focused after adding a field", () => {
assert.match(source, /import \{ computed, nextTick, onMounted, ref, watch \} from "vue"/);
assert.match(source, /async function addColumn/);
assert.match(source, /activeTab\.value = "columns"/);
assert.match(source, /await nextTick\(\)/);
assert.match(source, /data-new-column-row="true"/);
assert.match(source, /data-column-name-input/);
assert.match(source, /input\?\.focus\(\)/);
});
test("table comment input is disabled and shows tooltip when database does not support comments", () => {
assert.match(source, /isTableCommentDisabled/);
assert.match(source, /:disabled="isTableCommentDisabled"/);
assert.match(source, /v-if="isTableCommentDisabled"/);
assert.match(source, /Tooltip/);
assert.match(source, /tableCommentUnsupported/);
});