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" }], }); });