mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
The query console's Data source dropdown mixed databases into the source list, and SQL Server's second dropdown listed databases. As in DataGrip, the dropdown now lists data sources only, and a database.schema switcher next to it opens a searchable database -> schema tree that loads a database's schemas on expand and moves the console to the picked database; one-level drivers keep a flat schema list and SQLite has none. SQL Server's console schema is now a real schema (SCHEMA_NAME()) that scopes resolution and completion, since a session's default schema can't be changed, while the pooled connection still returns to its database. Tree speed search also opens with Cmd/Ctrl+F, as in IDEA. Closes #4577 Co-authored-by: faizanalhassan <53539447+faizanalhassan@users.noreply.github.com>
38 lines
1.8 KiB
TypeScript
38 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import { parseSchemaTreeValue, schemaTreeRows, schemaTreeValue } from "./model";
|
||
|
||
describe("console database › schema switcher", () => {
|
||
it("round-trips database and schema values", () => {
|
||
expect(parseSchemaTreeValue(schemaTreeValue("shop"))).toEqual({ database: "shop", schema: null });
|
||
expect(parseSchemaTreeValue(schemaTreeValue("shop", "public"))).toEqual({ database: "shop", schema: "public" });
|
||
expect(parseSchemaTreeValue(schemaTreeValue("a.b", "c:d"))).toEqual({ database: "a.b", schema: "c:d" });
|
||
});
|
||
|
||
it("lists schemas under expanded databases only", () => {
|
||
const schemas: Record<string, string[]> = { shop: ["public", "audit"], crm: ["public"] };
|
||
const rows = schemaTreeRows(["shop", "crm"], new Set(["shop"]), (d) => schemas[d]);
|
||
expect(rows.map((r) => [r.label, r.tree])).toEqual([
|
||
["shop", { depth: 0, expanded: true }],
|
||
["public", { depth: 1 }],
|
||
["audit", { depth: 1 }],
|
||
["crm", { depth: 0, expanded: false }],
|
||
]);
|
||
expect(rows[1]!.value).toBe(schemaTreeValue("shop", "public"));
|
||
});
|
||
|
||
it("shows a disabled loading row while an expanded database's schemas load", () => {
|
||
const rows = schemaTreeRows(["shop"], new Set(["shop"]), () => undefined);
|
||
expect(rows[1]).toMatchObject({ label: "Loading…", disabled: true, tree: { depth: 1 } });
|
||
});
|
||
|
||
it("shows the error when an expanded database's schemas cannot be read", () => {
|
||
const rows = schemaTreeRows(["shop"], new Set(["shop"]), () => ({ error: "timed out" }));
|
||
expect(rows[1]).toMatchObject({ label: "timed out", verbatim: true, disabled: true });
|
||
});
|
||
|
||
it("lets a search for the database name keep its schemas", () => {
|
||
const rows = schemaTreeRows(["shop"], new Set(["shop"]), () => ["public"]);
|
||
expect(rows[1]).toMatchObject({ label: "public", keywords: "shop" });
|
||
});
|
||
});
|