Files
openidea/src/features/database/schemaTree.test.ts
T
Hafiz Faizan ul hassanandfaizanalhassan a679e8086f feat(database): pick data source, then database and schema in the query console (#4614)
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>
2026-11-20 06:04:34 +08:00

38 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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" });
});
});