дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
- Introspected tree folder labels (tables, views, routines, keys, …) are localized. - Database/schema introspection pickers get Select all filtered. - New › Data Source lists recently added data source types in a Recent section first, seeded from existing sources on first use. - New PostgreSQL data sources default to the postgres database. - Modify Table is resizable, its content following the window size. Co-authored-by: wangyuewen-china <[email protected]>
70 рядки
2.8 KiB
TypeScript
70 рядки
2.8 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { newMenu } from "./treeMenu";
|
|
import { RECENT_DATABASE_VENDORS_KEY, readRecentVendors, rememberRecentVendor } from "./recentVendors";
|
|
import { useDatabase } from "./store";
|
|
|
|
const recentIds = () => readRecentVendors().map((vendor) => vendor.id);
|
|
const dataSourceSubmenu = () => {
|
|
const item = newMenu().find((entry) => "label" in entry && entry.label === "Data Source");
|
|
if (!item || !("submenu" in item) || !item.submenu) throw new Error("missing Data Source submenu");
|
|
return item.submenu;
|
|
};
|
|
|
|
beforeEach(() => {
|
|
localStorage.removeItem(RECENT_DATABASE_VENDORS_KEY);
|
|
useDatabase.setState({ sources: [] });
|
|
});
|
|
|
|
describe("recent data source types", () => {
|
|
it("keeps the newest first, drops duplicates and ignores unknown entries", () => {
|
|
rememberRecentVendor("postgres");
|
|
rememberRecentVendor("sqlServer");
|
|
rememberRecentVendor("postgres");
|
|
localStorage.setItem(
|
|
RECENT_DATABASE_VENDORS_KEY,
|
|
JSON.stringify(["postgres", "sqlServer", "postgres", "missing", 7]),
|
|
);
|
|
|
|
expect(recentIds()).toEqual(["postgres", "sqlServer"]);
|
|
});
|
|
|
|
it("shows recent types above the full list and removes their duplicates", () => {
|
|
rememberRecentVendor("postgres");
|
|
rememberRecentVendor("sqlServer");
|
|
const submenu = dataSourceSubmenu();
|
|
|
|
expect(submenu[0]).toEqual({ kind: "header", label: "Recent" });
|
|
expect(submenu.slice(1, 3)).toEqual([
|
|
expect.objectContaining({ label: "Microsoft SQL Server", icon: "db-sqlserver" }),
|
|
expect.objectContaining({ label: "PostgreSQL", icon: "db-postgres" }),
|
|
]);
|
|
expect(submenu[3]).toEqual({ kind: "separator" });
|
|
const labels = submenu.flatMap((item) => ("label" in item ? [item.label] : []));
|
|
expect(labels.filter((label) => label === "PostgreSQL")).toHaveLength(1);
|
|
expect(labels.filter((label) => label === "Microsoft SQL Server")).toHaveLength(1);
|
|
});
|
|
|
|
it("uses existing data sources as recent types on first use", () => {
|
|
useDatabase.setState({
|
|
sources: [
|
|
{ id: "pg", name: "Warehouse", driver: "postgres" },
|
|
{ id: "mysql", name: "Shop", driver: "mysql" },
|
|
{ id: "pg-2", name: "Reporting", driver: "postgres" },
|
|
],
|
|
});
|
|
const submenu = dataSourceSubmenu();
|
|
|
|
expect(submenu[0]).toEqual({ kind: "header", label: "Recent" });
|
|
expect(submenu.slice(1, 3)).toEqual([
|
|
expect.objectContaining({ label: "PostgreSQL" }),
|
|
expect.objectContaining({ label: "MySQL" }),
|
|
]);
|
|
const labels = submenu.flatMap((item) => ("label" in item ? [item.label] : []));
|
|
expect(labels.filter((label) => label === "PostgreSQL")).toHaveLength(1);
|
|
});
|
|
|
|
it("has no recent section while no data source exists", () => {
|
|
expect(dataSourceSubmenu().some((item) => item.kind === "header")).toBe(false);
|
|
});
|
|
});
|