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。

fix(ci): update nested layout and grid tests

t8y2364054122219
diff --git a/apps/desktop/src/lib/sidebarLayout.ts b/apps/desktop/src/lib/sidebarLayout.ts
index 819d75f446..1fb01c057f 100644
--- a/apps/desktop/src/lib/sidebarLayout.ts
+++ b/apps/desktop/src/lib/sidebarLayout.ts
@@ -50,7 +50,7 @@ export function reconcileLayout(connectionIds: string[], layout: SidebarLayout |
for (const entry of entries) {
if (entry.type !== "group") continue;
usedGroupIds.add(entry.id);
- collectGroups(entry.children ?? []);
+ collectGroups(entryChildren(entry));
}
};
collectGroups(order);
@@ -101,7 +101,7 @@ export function buildTreeNodesFromLayout(layout: SidebarLayout, connections: Con
label: group.name,
type: "connection-group",
isExpanded: !group.collapsed,
- children: orderPinnedFirst(build(entry.children ?? [])),
+ children: orderPinnedFirst(build(entryChildren(entry))),
});
}
return nodes;
@@ -116,7 +116,7 @@ export function findConnectionLocation(layout: SidebarLayout, connectionId: stri
const entry = entries[i];
if (entry.type === "connection" && entry.id === connectionId) return { entries, entryIndex: i, groupId };
if (entry.type === "group") {
- const found = visit(entry.children ?? [], entry.id);
+ const found = visit(entryChildren(entry), entry.id);
if (found) return found;
}
}
@@ -129,14 +129,14 @@ function findGroupEntry(entries: SidebarOrderEntry[], groupId: string): Extract<
for (const entry of entries) {
if (entry.type !== "group") continue;
if (entry.id === groupId) return entry;
- const found = findGroupEntry(entry.children ?? [], groupId);
+ const found = findGroupEntry(entryChildren(entry), groupId);
if (found) return found;
}
return null;
}
function cloneEntries(entries: SidebarOrderEntry[]): SidebarOrderEntry[] {
- return entries.map((entry) => (entry.type === "group" ? { type: "group", id: entry.id, children: cloneEntries(entry.children ?? []) } : { ...entry }));
+ return entries.map((entry) => (entry.type === "group" ? { type: "group", id: entry.id, children: cloneEntries(entryChildren(entry)) } : { ...entry }));
}
function removeEntry(entries: SidebarOrderEntry[], id: string): SidebarOrderEntry | null {
@@ -163,7 +163,14 @@ function removeConnectionFromEntries(entries: SidebarOrderEntry[], connectionId:
function containsGroup(entry: SidebarOrderEntry, groupId: string): boolean {
if (entry.type !== "group") return false;
if (entry.id === groupId) return true;
- return (entry.children ?? []).some((child) => containsGroup(child, groupId));
+ return entryChildren(entry).some((child) => containsGroup(child, groupId));
+}
+
+function expandGroup(layout: SidebarLayout, groupId: string): SidebarLayout {
+ return {
+ ...layout,
+ groups: layout.groups.map((group) => (group.id === groupId ? { ...group, collapsed: false } : group)),
+ };
}
export function moveConnectionToGroup(layout: SidebarLayout, connectionId: string, targetGroupId: string | null): SidebarLayout {
@@ -174,7 +181,7 @@ export function moveConnectionToGroup(layout: SidebarLayout, connectionId: strin
const group = findGroupEntry(order, targetGroupId);
if (group) {
group.children = [...(group.children ?? []), entry];
- return { ...layout, order };
+ return { ...expandGroup(layout, targetGroupId), order };
}
}
@@ -256,7 +263,7 @@ export function deleteGroup(layout: SidebarLayout, groupId: string): SidebarLayo
for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
if (entry.type === "group" && entry.id === groupId) {
- entries.splice(i, 1, ...(entry.children ?? []));
+ entries.splice(i, 1, ...entryChildren(entry));
return true;
}
if (entry.type === "group") {
diff --git a/packages/app-tests/dataGridEditor.test.ts b/packages/app-tests/dataGridEditor.test.ts
index 408b39d5f3..bd2f2ed245 100644
--- a/packages/app-tests/dataGridEditor.test.ts
+++ b/packages/app-tests/dataGridEditor.test.ts
@@ -18,9 +18,10 @@ function installBrowserTestGlobals() {
length: 0,
};
globalThis.fetch = (async (input, init) => {
- if (String(input) !== "/api/query/prepare-data-grid-save") {
- return new Response("unexpected request", { status: 500 });
+ if (String(input) === "/api/history/save") {
+ return new Response("null", { status: 200, headers: { "Content-Type": "application/json" } });
}
+ if (String(input) !== "/api/query/prepare-data-grid-save") return new Response("unexpected request", { status: 500 });
const body = JSON.parse(String(init?.body ?? "{}"));
const options = body.options as DataGridSaveStatementOptions;
return new Response(
@@ -168,9 +169,11 @@ test("cloning a row copies non-generated primary key values without executing sa
primaryKeys: ["code", "year"],
})),
onExecuteSql: computed(() => undefined),
- customSave: computed(() => async () => {
- saveCalls += 1;
- }),
+ customSaveHandler: computed(() => ({
+ save: async () => {
+ saveCalls += 1;
+ },
+ })),
sql: computed(() => undefined),
searchText: ref(""),
whereFilterInput: ref(""),
@@ -247,7 +250,7 @@ test("cloning a row clears auto-generated key columns", async () => {
primaryKeys: ["id"],
})),
onExecuteSql: computed(() => undefined),
- customSave: computed(() => undefined),
+ customSaveHandler: computed(() => undefined),
sql: computed(() => undefined),
searchText: ref(""),
whereFilterInput: ref(""),
@@ -301,7 +304,7 @@ test("saving deleted rows reloads current table data", async () => {
primaryKeys: ["id"],
})),
onExecuteSql: computed(() => undefined),
- customSave: computed(() => async () => {}),
+ customSaveHandler: computed(() => ({ save: async () => {} })),
sql: computed(() => "SELECT id, name FROM people"),
searchText: ref("ada"),
whereFilterInput: ref("name ILIKE '%a%'"),
@@ -360,7 +363,7 @@ test("saving inserted rows reloads current table data", async () => {
onExecuteSql: computed(() => async (sql: string) => {
executedSql.push(sql);
}),
- customSave: computed(() => undefined),
+ customSaveHandler: computed(() => undefined),
sql: computed(() => "SELECT id, name FROM people"),
searchText: ref("linus"),
whereFilterInput: ref("name ILIKE '%l%'"),
@@ -406,7 +409,7 @@ test("saving edited rows without deletes does not reload table data", async () =
primaryKeys: ["id"],
})),
onExecuteSql: computed(() => undefined),
- customSave: computed(() => async () => {}),
+ customSaveHandler: computed(() => ({ save: async () => {} })),
sql: computed(() => "SELECT id, name FROM people"),
searchText: ref(""),
whereFilterInput: ref(""),
@@ -463,7 +466,7 @@ test("saving manually typed JSON from a MySQL grid normalizes smart quotes", asy
onExecuteSql: computed(() => async (sql: string) => {
executedSql.push(sql);
}),
- customSave: computed(() => undefined),
+ customSaveHandler: computed(() => undefined),
sql: computed(() => "SELECT id, payload FROM settings"),
searchText: ref(""),
whereFilterInput: ref(""),
@@ -518,7 +521,7 @@ test("saving manually typed JSON arrays from a Postgres array column uses array
onExecuteSql: computed(() => async (sql: string) => {
executedSql.push(sql);
}),
- customSave: computed(() => undefined),
+ customSaveHandler: computed(() => undefined),
sql: computed(() => "SELECT id, tags FROM articles"),
searchText: ref(""),
whereFilterInput: ref(""),
@@ -595,7 +598,7 @@ test("failed table data save records a failed history entry", async () => {
primaryKeys: ["id"],
})),
onExecuteSql: computed(() => undefined),
- customSave: computed(() => undefined),
+ customSaveHandler: computed(() => undefined),
sql: computed(() => "SELECT id, title FROM pp_questions"),
searchText: ref(""),
whereFilterInput: ref(""),
diff --git a/packages/app-tests/sidebarLayout.test.ts b/packages/app-tests/sidebarLayout.test.ts
index 2f37ca3b99..2a0aa0fdc6 100644
--- a/packages/app-tests/sidebarLayout.test.ts
+++ b/packages/app-tests/sidebarLayout.test.ts
@@ -15,6 +15,11 @@ function conn(id: string, name?: string): ConnectionConfig {
};
}
+function groupConnectionIds(entry: SidebarLayout["order"][number]): string[] {
+ assert.equal(entry.type, "group");
+ return (entry.children ?? []).filter((child) => child.type === "connection").map((child) => child.id);
+}
+
// --- reconcileLayout ---
test("reconcileLayout returns all connections ungrouped when layout is null", () => {
@@ -48,7 +53,7 @@ test("reconcileLayout removes stale connections from layout", () => {
const result = reconcileLayout(["a", "b"], layout);
const groupEntry = result.order.find((e) => e.type === "group");
assert.ok(groupEntry && groupEntry.type === "group");
- assert.deepEqual(groupEntry.connectionIds, ["a"]);
+ assert.deepEqual(groupConnectionIds(groupEntry), ["a"]);
assert.equal(result.order.length, 2);
});
@@ -161,7 +166,7 @@ test("moveConnectionToGroup moves connection into a group", () => {
const result = moveConnectionToGroup(layout, "a", "g1");
const groupEntry = result.order.find((e) => e.type === "group" && e.id === "g1");
assert.ok(groupEntry && groupEntry.type === "group");
- assert.deepEqual(groupEntry.connectionIds, ["a"]);
+ assert.deepEqual(groupConnectionIds(groupEntry), ["a"]);
assert.equal(result.order.length, 1);
});
@@ -221,7 +226,7 @@ test("reorderEntry moves connection inside a group", () => {
assert.equal(result.order.length, 1);
const groupEntry = result.order[0];
assert.ok(groupEntry.type === "group");
- assert.deepEqual(groupEntry.connectionIds, ["a"]);
+ assert.deepEqual(groupConnectionIds(groupEntry), ["a"]);
});
test("reorderEntry is a no-op when dragging to same position", () => {
@@ -251,7 +256,7 @@ test("appendConnectionToLayout adds to target group and expands it", () => {
assert.equal(result.groups[0].collapsed, false);
assert.ok(groupEntry.type === "group");
- assert.deepEqual(groupEntry.connectionIds, ["a", "b"]);
+ assert.deepEqual(groupConnectionIds(groupEntry), ["a", "b"]);
});
test("removeConnectionFromSidebarLayout removes from ungrouped", () => {
@@ -268,5 +273,5 @@ test("removeConnectionFromSidebarLayout removes from inside a group", () => {
const result = removeConnectionFromSidebarLayout(layout, "a");
const groupEntry = result.order[0];
assert.ok(groupEntry.type === "group");
- assert.deepEqual(groupEntry.connectionIds, ["b"]);
+ assert.deepEqual(groupConnectionIds(groupEntry), ["b"]);
});