Файли
openidea/src/features/database/renameDatabase.test.ts
T
l0ng-aiтаClaude Opus 5.5 0379d597be fix(database): rename databases and schemas from the tree
Rename… (db.rename, Shift+F6) did nothing on a database or schema node:
canRename accepted only tables, columns, views and PostgreSQL indexes, and
database nodes have no schema object.

Databases of a server that creates them (PostgreSQL, SQL Server) rename with
ALTER DATABASE after closing the IDE's sessions on them; the connected
database and read-only sources keep Rename disabled, as Drop does. Schemas
rename with ALTER SCHEMA on PostgreSQL and Snowflake. Both use the rename
dialog with its SQL preview and refresh the tree.

Fixes #5205

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-22 21:22:40 +08:00

50 рядки
2.1 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { getAction } from "@/platform/actions";
import type { DbNode } from "./nodes";
import { useDatabase } from "./store";
import { registerDatabaseTreeActions } from "./treeActions";
import { nodeMenu } from "./treeMenu";
const database = (current: boolean): DbNode => ({ kind: "database", key: "db", id: "pg:shop", name: "shop", current });
const schema: DbNode = { kind: "schema", id: "pg:shop", key: "schema", schema: "sales" };
const renameItem = (n: DbNode) =>
nodeMenu(n).find((item) => "action" in item && item.action === "db.rename") as { disabled?: boolean } | undefined;
let dispose: () => void;
beforeEach(() => {
dispose = registerDatabaseTreeActions();
useDatabase.setState({ sources: [{ id: "pg", driver: "postgres" }], dialog: null, loaded: true });
});
afterEach(() => dispose());
describe("Rename on databases and schemas", () => {
it("is offered on a database other than the connected one", () => {
expect(renameItem(database(false))?.disabled).toBe(false);
expect(renameItem(database(true))?.disabled).toBe(true);
});
it("is offered on a schema", () => {
expect(renameItem(schema)?.disabled).toBe(false);
});
it("is not offered on a read-only data source", () => {
useDatabase.setState({ sources: [{ id: "pg", driver: "postgres", readOnly: true }] });
expect(renameItem(database(false))?.disabled).toBe(true);
});
it("opens the rename dialog through db.rename", async () => {
await getAction("db.rename")!.run({ arg: database(false) } as never);
expect(useDatabase.getState().dialog).toEqual({ kind: "renameDatabase", id: "pg", database: "shop" });
useDatabase.setState({ dialog: null });
await getAction("db.rename")!.run({ arg: database(true) } as never);
expect(useDatabase.getState().dialog).toBeNull();
await getAction("db.rename")!.run({ arg: schema } as never);
expect(useDatabase.getState().dialog).toMatchObject({
kind: "rename",
id: "pg:shop",
object: { kind: "schema", name: "sales" },
});
});
});