Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

test(grid): align varbinary copy specs with GBK fallback behavior

t8y2300fc029a9e5
diff --git a/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts
index 4665d6bfd6..8c62501879 100644
--- a/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts
+++ b/apps/desktop/src/composables/__tests__/useDataGridExport.spec.ts
@@ -1644,14 +1644,14 @@ describe("useDataGridExport VARBINARY 文本复制 (#7471)", () => {
expect(parseDataGridClipboard("abc")).toEqual([["0x616263"]]);
});
- it("非文本 VARBINARY 保持 0x/hex,避免破坏任意 bytes", async () => {
+ it("恰好构成合法 GBK 序列的 VARBINARY 按解码文本复制(与网格显示一致)", async () => {
const matrix: CellSelectionMatrix = { rowIndexes: [0], columnIndexes: [1], columns: ["name"], rows: [["0xdeadbeef"]] };
- vi.mocked(extractDataGridSelection).mockResolvedValueOnce({ text: "0xdeadbeef", mimeType: "text/plain", fileExtension: "txt", rowCount: 1, columnCount: 1 });
+ vi.mocked(extractDataGridSelection).mockResolvedValueOnce({ text: "蕲撅", mimeType: "text/plain", fileExtension: "txt", rowCount: 1, columnCount: 1 });
const state = createExportState(varbinTable, ["id", "name"], matrix, [1, "0xdeadbeef"]);
await expect(state.copyWithPreference("smart")).resolves.toBe(true);
- expect(extractDataGridSelection).toHaveBeenCalledWith(expect.objectContaining({ extractor: "raw", rows: [["0xdeadbeef"]] }));
+ expect(extractDataGridSelection).toHaveBeenCalledWith(expect.objectContaining({ extractor: "raw", rows: [["蕲撅"]] }));
});
it("多选 TSV 复制同样对文本型 VARBINARY 解码", async () => {
@@ -1702,12 +1702,12 @@ describe("useDataGridExport VARBINARY 文本复制 (#7471)", () => {
expect(extractDataGridSelection).not.toHaveBeenCalled();
});
- it("右键「复制单元格」对非文本 VARBINARY 保持 0x/hex", async () => {
+ it("右键「复制单元格」对 GBK 可解码 VARBINARY 复制解码文本", async () => {
const state = createExportState(varbinTable, ["id", "name"], undefined, [1, "0xdeadbeef"], undefined, undefined, [], DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS, false, undefined, false, 1, 1);
await state.copyCell();
- expect(copyToClipboard).toHaveBeenCalledWith("0xdeadbeef");
+ expect(copyToClipboard).toHaveBeenCalledWith("蕲撅");
});
it("复制整行 JSON 时呈现文本型 VARBINARY", async () => {
diff --git a/packages/app-tests/dataGridDetail.test.ts b/packages/app-tests/dataGridDetail.test.ts
index 0d719749e9..da0234ab99 100644
--- a/packages/app-tests/dataGridDetail.test.ts
+++ b/packages/app-tests/dataGridDetail.test.ts
@@ -227,7 +227,7 @@ test("dataGridRowDetailJson and dataGridRowDetailTsv format copy payloads", () =
assert.equal(dataGridRowDetailTsv(detail), "1\tAda\t");
});
-test("data grid detail copy renders textual MySQL VARBINARY while preserving non-text bytes", () => {
+test("data grid detail copy renders textual and GBK-decodable MySQL VARBINARY as text", () => {
const rowDetail = buildDataGridRowDetail({
rowIndex: 0,
rowId: 1,
@@ -245,8 +245,9 @@ test("data grid detail copy renders textual MySQL VARBINARY while preserving non
displayValue: (value) => String(value),
});
- assert.equal(dataGridRowDetailJson(rowDetail, undefined, "mysql"), '{\n "name": "abc",\n "payload": "0xdeadbeef"\n}');
- assert.equal(dataGridRowDetailTsv(rowDetail, "mysql"), "abc\t0xdeadbeef");
+ // 0xdeadbeef 恰好全部组成合法 GBK 序列:MySQL 连接按 GBK 解码复制(与网格显示一致),见 binaryCellDownload.test.ts。
+ assert.equal(dataGridRowDetailJson(rowDetail, undefined, "mysql"), '{\n "name": "abc",\n "payload": "蕲撅"\n}');
+ assert.equal(dataGridRowDetailTsv(rowDetail, "mysql"), "abc\t蕲撅");
assert.equal(dataGridColumnDetailJson(columnDetail!, "mysql"), '[\n {\n "row": 1,\n "value": "abc"\n }\n]');
assert.equal(dataGridColumnDetailTsv(columnDetail!, "mysql"), "abc");
// 非 MySQL binary 及非文本 VARBINARY 不应被误转成字符串或 replacement character。