Файли
openidea/e2e/databasePluginMenu.spec.ts
T
葛俊таgejun123456 b7c2d4eacb feat(plugins): expose database table menus and read-only schema (#7372)
Plugin API 1.20 adds wit/database.wit with describe-table behind the database.schema capability: a read-only view of a connected source's table (columns, keys, indexes) through DbManager::connected_table_details. Plugins can contribute database.table.context menu entries (needs_api 20) that receive the non-secret table identity and the when keys databaseDriver, databaseObjectKind, databaseSchema, databaseTable and databaseSelectionCount.

Co-authored-by: gejun123456 <[email protected]>
2026-12-02 14:25:35 +08:00

81 рядки
3.4 KiB
TypeScript

import { expect, stubDesktop, test } from "./fixtures";
test("table menu contributions preserve selected table identities", async ({ workbench: page }, info) => {
await stubDesktop(page);
await page.evaluate(async () => {
const storePath = "/src/features/database/store.ts";
const contributionsPath = "/src/workbench/contributions.ts";
const { useDatabase } = await import(storePath);
const { toolWindowService } = await import(contributionsPath);
useDatabase.setState({
sources: [{ id: "local", name: "Inventory", driver: "sqlite", file: "inventory.sqlite" }],
loaded: true,
connected: new Set(["local"]),
schemas: { local: { status: "ok", value: ["main"] } },
foldersLoaded: true,
tables: {
["local\u0000main"]: {
status: "ok",
value: [
{ name: "users", kind: "table" },
{ name: "orders", kind: "table" },
],
},
},
});
toolWindowService().show("database", true);
});
const panel = page.locator('section[aria-label="Database"]');
const source = panel.getByRole("treeitem").filter({ hasText: "Inventory" });
await source.locator("[data-tree-toggle]").click();
const schema = panel.getByRole("treeitem").filter({ hasText: /^main/ });
if (await schema.count()) await schema.locator("[data-tree-toggle]").click();
await panel
.getByRole("treeitem")
.filter({ hasText: /^tables/ })
.locator("[data-tree-toggle]")
.click();
const users = panel.getByRole("treeitem").filter({ hasText: /^users/ });
await expect(users).toBeVisible();
await users.click({ button: "right" });
await expect(page.getByRole("menu").last()).toBeVisible();
await page.screenshot({ path: info.outputPath("before.png"), animations: "disabled" });
await page.keyboard.press("Escape");
await page.evaluate(async () => {
const actionsPath = "/src/platform/actions.ts";
const projectionPath = "/src/features/plugins/projection.ts";
const { registerAction } = await import(actionsPath);
const { syncUiContributions } = await import(projectionPath);
registerAction({
id: "plugin.mapper.generate",
title: "Generate MyBatis mapper",
run: ({ arg }: { arg?: unknown }) => {
Object.assign(window, { __tableSelection: arg });
},
});
syncUiContributions(
[
{
pluginId: "mapper",
point: "menus",
key: "database.table.context/generate",
decl: { menu: "database.table.context", command: "generate", when: "databaseObjectKind == table" },
},
],
[{ id: "mapper", name: "Mapper generator", enabled: true, status: "active", icon: null }],
);
});
await users.click({ button: "right" });
const generate = page.getByRole("menuitem", { name: "Generate MyBatis mapper" });
await expect(generate).toBeVisible();
await page.screenshot({ path: info.outputPath("after.png"), animations: "disabled" });
await generate.click();
await expect
.poll(() => page.evaluate(() => (window as unknown as { __tableSelection?: string }).__tableSelection))
.toBeTruthy();
const selection = await page.evaluate(() => (window as unknown as { __tableSelection: string }).__tableSelection);
expect(JSON.parse(selection)).toEqual({
tables: [{ sourceId: "local", catalog: null, schema: "main", table: "users", kind: "table", driver: "sqlite" }],
});
});