feat(sidebar): show connection group paths
This commit is contained in:
14 files changed
+251
-10
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { findConnectionGroupPath } from "@/lib/sidebar/sidebarLayout";
|
||||
import type { SidebarLayout } from "@/types/database";
|
||||
|
||||
const layout: SidebarLayout = {
|
||||
groups: [
|
||||
{ id: "project", name: "Project", collapsed: false },
|
||||
{ id: "staging", name: "Staging", collapsed: false },
|
||||
],
|
||||
order: [
|
||||
{
|
||||
type: "group",
|
||||
id: "project",
|
||||
children: [
|
||||
{
|
||||
type: "group",
|
||||
id: "staging",
|
||||
children: [{ type: "connection", id: "nested" }],
|
||||
},
|
||||
{ type: "connection", id: "grouped" },
|
||||
],
|
||||
},
|
||||
{ type: "connection", id: "root" },
|
||||
],
|
||||
};
|
||||
|
||||
describe("findConnectionGroupPath", () => {
|
||||
it("returns every containing group from root to leaf", () => {
|
||||
expect(findConnectionGroupPath(layout, "nested")).toEqual(["Project", "Staging"]);
|
||||
expect(findConnectionGroupPath(layout, "grouped")).toEqual(["Project"]);
|
||||
});
|
||||
|
||||
it("distinguishes a top-level connection from a missing connection", () => {
|
||||
expect(findConnectionGroupPath(layout, "root")).toEqual([]);
|
||||
expect(findConnectionGroupPath(layout, "missing")).toBeNull();
|
||||
});
|
||||
});
|
||||
+63
-3
@@ -1,6 +1,28 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { middleEllipsis, queryResultBaseSql, queryResultExecutionSql, resultSourceRange, tabularResultItems } from "@/lib/tabs/tabPresentation";
|
||||
import type { QueryTab } from "@/types/database";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { connectionGroupDisplayName, middleEllipsis, queryResultBaseSql, queryResultExecutionSql, resultSourceRange, tabTooltipLines, tabularResultItems } from "@/lib/tabs/tabPresentation";
|
||||
import type { ConnectionConfig, QueryTab } from "@/types/database";
|
||||
|
||||
const translations: Record<string, string> = {
|
||||
"tabs.tooltipConnection": "Connection:",
|
||||
"tabs.tooltipGroup": "Group:",
|
||||
"tabs.tooltipDatabase": "Database:",
|
||||
"connectionGroup.ungroupedLabel": "Ungrouped",
|
||||
"editor.noDatabase": "No database",
|
||||
};
|
||||
|
||||
const translate = (key: string) => translations[key] ?? key;
|
||||
|
||||
beforeEach(() => {
|
||||
const values = new Map<string, string>();
|
||||
vi.stubGlobal("localStorage", {
|
||||
getItem: vi.fn((key: string) => values.get(key) ?? null),
|
||||
setItem: vi.fn((key: string, value: string) => values.set(key, value)),
|
||||
removeItem: vi.fn((key: string) => values.delete(key)),
|
||||
});
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
function queryTab(overrides: Partial<QueryTab>): QueryTab {
|
||||
return {
|
||||
@@ -110,6 +132,44 @@ describe("query result labels", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("tab group presentation", () => {
|
||||
it("adds the full, live group path to tab tooltips", () => {
|
||||
const store = useConnectionStore();
|
||||
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", database: "app" } as ConnectionConfig];
|
||||
store.sidebarLayout = {
|
||||
groups: [
|
||||
{ id: "project", name: "Project", collapsed: false },
|
||||
{ id: "staging", name: "Staging", collapsed: false },
|
||||
],
|
||||
order: [
|
||||
{
|
||||
type: "group",
|
||||
id: "project",
|
||||
children: [{ type: "group", id: "staging", children: [{ type: "connection", id: "conn-1" }] }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
expect(connectionGroupDisplayName("conn-1", translate)).toBe("Project / Staging");
|
||||
expect(tabTooltipLines(queryTab({ database: "app" }), translate)).toEqual([
|
||||
{ label: "Connection:", value: "PostgreSQL" },
|
||||
{ label: "Group:", value: "Project / Staging" },
|
||||
{ label: "Database:", value: "app" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("labels a top-level connection as ungrouped", () => {
|
||||
const store = useConnectionStore();
|
||||
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", database: "app" } as ConnectionConfig];
|
||||
store.sidebarLayout = {
|
||||
groups: [],
|
||||
order: [{ type: "connection", id: "conn-1" }],
|
||||
};
|
||||
|
||||
expect(connectionGroupDisplayName("conn-1", translate)).toBe("Ungrouped");
|
||||
});
|
||||
});
|
||||
|
||||
describe("query result source ranges", () => {
|
||||
it("prefers the preserved editor range for a selected duplicate statement", () => {
|
||||
const sql = "SELECT * FROM users;\nSELECT * FROM users;";
|
||||
|
||||
Reference in new issue
Block a user