Files
dbx/packages/app-tests/tableClipboard.test.ts
T
miracle 0c91fecf5d feat(editor): add table copy/paste keyboard shortcuts
* feat: add table copy/paste with configurable structure and data options

- Implement Navicat-style table copy/paste functionality
- Support multi-table selection and batch operations
- Configurable paste modes: structure+data (default), structure only, data only
- Backend: add build_copy_table_data_sql API (INSERT INTO ... SELECT)
- TreeItem.vue: copy/paste context menus, paste dialog with mode selection
- ObjectBrowser.vue: batch toolbar buttons, context menu, paste dialog
- Refactor TreeClipboard type to support multi-table entries
- Add i18n keys for all 7 locale files (en, zh-CN, zh-TW, ja, es, it, pt-BR)

* Fix table paste shortcuts

* Fix Kafka MQ sidebar detection

* Restrict table paste scope

* Support data copy for primary SQL databases
2026-07-01 12:49:37 +08:00

62 lines
3.2 KiB
TypeScript

import { strict as assert } from "node:assert";
import { test } from "vitest";
import type { ColumnInfo } from "../../apps/desktop/src/types/database.ts";
import { defaultPasteTableMode, pasteTableModeCopiesData, supportsWholeRowTableDataCopy, tableClipboardMatchesTarget, tableDataCopyColumnOptions } from "../../apps/desktop/src/lib/tableClipboard.ts";
test("table clipboard entries must match the paste target context", () => {
const target = { connectionId: "c1", database: "app", schema: "public" };
assert.equal(tableClipboardMatchesTarget([{ connectionId: "c1", database: "app", schema: "public" }], target), true);
assert.equal(tableClipboardMatchesTarget([{ connectionId: "c2", database: "app", schema: "public" }], target), false);
assert.equal(tableClipboardMatchesTarget([{ connectionId: "c1", database: "other", schema: "public" }], target), false);
assert.equal(tableClipboardMatchesTarget([{ connectionId: "c1", database: "app", schema: "audit" }], target), false);
assert.equal(tableClipboardMatchesTarget([], target), false);
assert.equal(tableClipboardMatchesTarget([{ connectionId: "c1", database: "app" }], null), false);
});
test("whole-row table data copy is enabled for known database types", () => {
assert.equal(supportsWholeRowTableDataCopy("mysql"), true);
assert.equal(supportsWholeRowTableDataCopy("postgres"), true);
assert.equal(supportsWholeRowTableDataCopy("sqlserver"), true);
assert.equal(supportsWholeRowTableDataCopy(undefined), false);
assert.equal(supportsWholeRowTableDataCopy("sqlite"), true);
assert.equal(defaultPasteTableMode("mysql"), "structure-and-data");
assert.equal(defaultPasteTableMode(undefined), "structure-only");
assert.equal(defaultPasteTableMode("sqlite"), "structure-and-data");
assert.equal(pasteTableModeCopiesData("structure-and-data"), true);
assert.equal(pasteTableModeCopiesData("data-only"), true);
assert.equal(pasteTableModeCopiesData("structure-only"), false);
});
test("table data copy uses only writable columns for first-class databases", () => {
const column = (name: string, extra: string | null): ColumnInfo => ({
name,
data_type: "int",
is_nullable: true,
column_default: null,
is_primary_key: name === "id",
extra,
comment: null,
numeric_precision: null,
numeric_scale: null,
character_maximum_length: null,
});
const columns = [column("id", "identity(1,1)"), column("name", null), column("full_name", "computed")];
assert.deepEqual(tableDataCopyColumnOptions("sqlserver", columns), {
columns: ["id", "name"],
postgresOverridingSystemValue: false,
sqlserverIdentityInsert: true,
});
assert.deepEqual(tableDataCopyColumnOptions("postgres", [{ ...columns[0], extra: "generated always as identity" }, { ...columns[1] }, { ...columns[2], extra: "generated always as (name) stored" }]), {
columns: ["id", "name"],
postgresOverridingSystemValue: true,
sqlserverIdentityInsert: false,
});
assert.deepEqual(tableDataCopyColumnOptions("mysql", [{ ...columns[0], extra: "auto_increment" }, { ...columns[1] }, { ...columns[2], extra: "STORED GENERATED" }]), {
columns: ["id", "name"],
postgresOverridingSystemValue: false,
sqlserverIdentityInsert: false,
});
});