Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
test(e2e): add schema editor e2e coverage (BYT-9802) (#20725)
zchpeterdcc03f7282c6
diff --git a/frontend/tests/e2e/framework/global-setup.ts b/frontend/tests/e2e/framework/global-setup.tsindex ae3c138556..6819f0cb46 100644--- a/frontend/tests/e2e/framework/global-setup.ts+++ b/frontend/tests/e2e/framework/global-setup.ts@@ -1,9 +1,23 @@import { saveTestEnv } from "./env";-import { cleanupOrphans, startServer } from "./mode-start-new-bytebase";+import { cleanupOrphans, startServer, stopServer } from "./mode-start-new-bytebase";async function globalSetup() {cleanupOrphans();- const { baseURL, adminEmail, adminPassword } = await startServer();++ let server: Awaited<ReturnType<typeof startServer>>;+ try {+ server = await startServer();+ } catch (err) {+ // startServer spawns the server process and creates its temp data dir+ // before it can fail (e.g. a /healthz timeout when the boot is slow).+ // Playwright does NOT run globalTeardown when globalSetup throws, so tear+ // the half-started server down here — otherwise a failed boot orphans a+ // process group and temp dir that starve every subsequent run's boot.+ stopServer();+ throw err;+ }++ const { baseURL, adminEmail, adminPassword } = server;saveTestEnv({baseURL, adminEmail, adminPassword,project: "", instance: "", instanceId: "", database: "", databaseId: "",diff --git a/frontend/tests/e2e/schema-editor/schema-editor-columns.spec.ts b/frontend/tests/e2e/schema-editor/schema-editor-columns.spec.tsnew file mode 100644index 0000000000..ce31909c71--- /dev/null+++ b/frontend/tests/e2e/schema-editor/schema-editor-columns.spec.ts@@ -0,0 +1,220 @@+// Schema editor — column editing (TableColumnEditor + DataTypeCell ++// DefaultValueCell).+//+// Covers:+// - Add column; edit column name (backspace works — BYT-9802 sibling lock).+// - Select a column type from the dropdown (BYT-9802 lock — a potential+// customer reported "couldn't select the column type from the editor").+// - Type a custom free-text type.+// - Primary is disabled on an existing table (PK only editable on created).+// - Drop a created column (spliced out) vs an existing column (excluded from+// the generated DDL) and restore it.+// - Default-value editing reflected in the generated DDL.+//+// Bug locks (Layer 2) — one root cause, two symptoms: on a NEWLY-CREATED table,+// column edits routed through refreshStatus() never re-render the editor+// because refreshTableEditStatus short-circuits for `created` tables and never+// bumps editStatus.version (refreshEditStatus.ts:95). Symptoms:+// 1. The DDL Preview stays frozen at the table's creation state.+// 2. The Primary / Not-Null checkboxes don't reflect a toggle (and PK is only+// editable on created tables, so the PK toggle is effectively unusable).++import {+ test,+ expect,+ type Page,+ type BrowserContext,+} from "@playwright/test";+import { loadTestEnv, type TestEnv } from "../framework/env";+import { BytebaseApiClient } from "../framework/api-client";+import { SchemaEditorPage } from "./schema-editor.page";+import { createSchemaEditorPlan } from "./schema-editor-helpers";++test.setTimeout(120_000);++let env: TestEnv & { api: BytebaseApiClient };+let ctx: BrowserContext;+let page: Page;+let se: SchemaEditorPage;+let projectId: string;+let planId: string;++test.beforeAll(async ({ browser }) => {+ env = loadTestEnv();+ await env.api.login(env.adminEmail, env.adminPassword);+ ({ projectId, planId } = await createSchemaEditorPlan(env, "E2E SchemaEditor Columns"));+ ctx = await browser.newContext({ storageState: ".auth/state.json" });+ page = await ctx.newPage();+ se = new SchemaEditorPage(page, env.baseURL);+});++test.afterAll(async () => {+ await ctx?.close();+});++// Create a uniquely-named table (opens in a tab with a default `id` column).+async function newTable(): Promise<string> {+ const name = `e2e_col_${Date.now()}_${Math.floor(Math.random() * 1e4)}`;+ await se.createTable(name);+ return name;+}++test.describe("column editing", () => {+ test.describe.configure({ mode: "serial" });++ test.beforeEach(async () => {+ await se.gotoPlan(projectId, planId);+ await se.open();+ await se.selectSchema("public");+ });++ test.afterEach(async () => {+ await se.close();+ });++ test("adds a new empty column row", async () => {+ await newTable();+ const before = await se.columnNameInputs().count();+ await se.addColumn();+ expect(await se.columnNameInputs().count()).toBe(before + 1);+ });++ test("selects a column type from the dropdown (BYT-9802)", async () => {+ await newTable();+ await se.addColumn();+ // The dropdown must open on click AND the selection must land in the cell.+ await se.selectColumnType(1, "boolean");+ await expect(se.columnTypeInputs().nth(1)).toHaveValue("boolean");+ });++ test("backspace deletes characters in the column-name input (BYT-9802)", async () => {+ await newTable();+ await se.addColumn();+ const nameInput = se.columnNameInputs().last();+ await nameInput.click();+ await page.keyboard.type("widget_label");+ await expect(nameInput).toHaveValue("widget_label");+ for (let i = 0; i < 5; i++) await page.keyboard.press("Backspace");+ await expect(nameInput).toHaveValue("widget_");+ });++ test("accepts a custom free-text column type", async () => {+ await newTable();+ await se.addColumn();+ const typeInput = se.columnTypeInputs().last();+ await typeInput.fill("varchar(255)");+ await expect(typeInput).toHaveValue("varchar(255)");+ });++ test("checking Primary on a created-table column forces Not-Null (in the DDL)", async () => {+ await newTable();+ await se.addColumn();+ await se.columnNameInputs().last().fill("zcode");+ await se.selectColumnType(1, "text");++ // Clicking Primary mutates the metadata immediately (adds the column to the+ // PK and sets nullable=false). Verify via the generated DDL rather than the+ // grid checkboxes: on a *created* table the grid only re-renders through the+ // delayed BYT-9802-preview path, so the checkbox UI updates late (~seconds)+ // and asserting on it is timing-fragile. The DDL reads metadata directly.+ await se.primaryCheckbox("zcode").click();+ await se.insertSql();++ const stmt = await se.planStatementText();+ expect(stmt).toMatch(/"zcode"\s+text\s+NOT NULL/); // PK forced NOT NULL+ expect(stmt).toMatch(/PRIMARY KEY\s*\([^;]*zcode/); // zcode joined the PK+ });++ test("Primary is disabled for every column on an existing table", async () => {+ await se.openTableFromList("department");+ // PK can only be changed on newly-created tables.+ await expect(se.primaryCheckbox("dept_no")).toBeDisabled();+ await expect(se.primaryCheckbox("dept_name")).toBeDisabled();+ });++ test("dropping a created column removes its row", async () => {+ await newTable();+ await se.addColumn();+ const nameInput = se.columnNameInputs().last();+ await nameInput.fill("zdrop");+ const before = await se.columnNameInputs().count();+ await se.dropColumnButton("zdrop").click();+ // A created column is spliced out entirely.+ await expect(se.columnNameInputs()).toHaveCount(before - 1);+ });++ test("dropping then restoring an existing column round-trips in the DDL", async () => {+ await se.openTableFromList("department");+ // Existing-table edits DO refresh the preview, so the DDL is the oracle.+ // Match the column *definition* (`"dept_name" text`) — a leftover UNIQUE+ // constraint keeps the bare name in the DDL even after the column is gone.+ // Poll for the initial (async) preview load before asserting.+ await expect+ .poll(async () => await se.previewText())+ .toContain('"dept_name" text');++ await se.dropColumnButton("dept_name").click();+ await expect+ .poll(async () => await se.previewText())+ .not.toContain('"dept_name" text');++ // The operations cell now shows Restore; click it to bring the column back.+ await se.dropColumnButton("dept_name").click();+ await expect+ .poll(async () => await se.previewText())+ .toContain('"dept_name" text');+ });++ test("editing a default value is reflected in the generated DDL", async () => {+ // Use an existing table so the live preview is the oracle (created-table+ // previews are stale — see the bug locks below).+ await se.openTableFromList("department");+ const defaultInput = se+ .columnRow("dept_name")+ .getByRole("textbox", { name: /Enter default value/ });+ await defaultInput.fill("n/a");+ await expect+ .poll(async () => await se.previewText())+ .toContain("DEFAULT");+ });+});++// Root cause: refreshTableEditStatus early-returns for `created` tables+// (refreshEditStatus.ts:95), so a column-value edit routed through+// refreshStatus() never bumps editStatus.version — and PreviewPane's+// mockedMetadata memo (keyed on editStatus.version) never recomputes, so the+// DDL Preview stays frozen at the table's creation state. Existing-table edits+// DO refresh the preview (they mark the column "updated" → version bumps).+test.describe("created-table edit reactivity (BUG BYT-9802-preview)", () => {+ test.describe.configure({ mode: "serial" });++ test.beforeEach(async () => {+ await se.gotoPlan(projectId, planId);+ await se.open();+ await se.selectSchema("public");+ });++ test.afterEach(async () => {+ await se.close();+ });++ // Repro: create table (id integer) → change id's type → preview still shows+ // "integer" even though the grid cell (and the inserted SQL) reflect "bigint".+ test.fail("changing a column type updates the preview DDL", async () => {+ await newTable();+ // Wait for the initial (async) preview to load, so the failure below is on+ // the stale type, not a not-yet-rendered preview.+ await expect.poll(async () => await se.previewText()).toContain("integer");++ await se.selectColumnType(0, "bigint");+ await expect(se.columnTypeInputs().nth(0)).toHaveValue("bigint"); // control++ // Bug: the preview should reflect the new type but stays "integer". Poll+ // (don't read once) so that when the bug is fixed the preview's async+ // schema-string refresh is given time to land — turning this into an+ // *unexpected pass* that signals the fix, rather than racing the refresh.+ await expect+ .poll(async () => await se.previewText())+ .toContain("bigint");+ });+});diff --git a/frontend/tests/e2e/schema-editor/schema-editor-create-table.spec.ts b/frontend/tests/e2e/schema-editor/schema-editor-create-table.spec.tsnew file mode 100644index 0000000000..927a4233a7--- /dev/null+++ b/frontend/tests/e2e/schema-editor/schema-editor-create-table.spec.ts@@ -0,0 +1,110 @@+// Schema editor — create-table flow (DatabaseEditor + TableNamePopover).+//+// Covers:+// - Creating a table from the "New table" toolbar button seeds a default+// `id` primary-key column and opens it in a tab.+// - Backspace works in the table-name input (BYT-9802 regression lock — a+// potential customer reported the backspace key "never worked").+// - Duplicate table-name validation blocks Create.+// - Cancel closes the popover without creating a table.++import {+ test,+ expect,+ type Page,+ type BrowserContext,+} from "@playwright/test";+import { loadTestEnv, type TestEnv } from "../framework/env";+import { BytebaseApiClient } from "../framework/api-client";+import { SchemaEditorPage } from "./schema-editor.page";+import { createSchemaEditorPlan } from "./schema-editor-helpers";++test.setTimeout(120_000);++let env: TestEnv & { api: BytebaseApiClient };+let ctx: BrowserContext;+let page: Page;+let se: SchemaEditorPage;+let projectId: string;+let planId: string;++test.beforeAll(async ({ browser }) => {+ env = loadTestEnv();+ await env.api.login(env.adminEmail, env.adminPassword);++ ({ projectId, planId } = await createSchemaEditorPlan(env, "E2E SchemaEditor CreateTable"));++ ctx = await browser.newContext({ storageState: ".auth/state.json" });+ page = await ctx.newPage();+ se = new SchemaEditorPage(page, env.baseURL);+ await se.gotoPlan(projectId, planId);+});++test.afterAll(async () => {+ await ctx?.close();+});++test.describe("create table", () => {+ test.describe.configure({ mode: "serial" });++ test.beforeEach(async () => {+ await se.gotoPlan(projectId, planId);+ await se.open();+ await se.selectSchema("public");+ });++ test.afterEach(async () => {+ await se.close();+ });++ test("creates a table with a default id primary-key column", async () => {+ const name = `e2e_widget_${Date.now()}`;+ await se.createTable(name);++ // The new table opens with its default `id` column in the grid.+ await expect(se.columnRow("id")).toBeVisible();++ // The generated DDL reflects the new table with an integer id PK. (Tab+ // labels are visually truncated, so the DDL is the stable oracle.) Poll —+ // the preview DDL is produced by an async getSchemaString RPC.+ await expect.poll(async () => await se.previewText()).toContain("CREATE TABLE");+ const preview = await se.previewText();+ expect(preview).toContain(name);+ expect(preview).toContain("PRIMARY KEY");+ expect(preview).toContain("id");+ });++ test("backspace deletes characters in the table-name input (BYT-9802)", async () => {+ await se.openNewTablePopover();+ // Type via the keyboard (not fill) so the Backspace key is exercised.+ await se.tableNameInput.click();+ await page.keyboard.type("abcdef");+ await expect(se.tableNameInput).toHaveValue("abcdef");+ await page.keyboard.press("Backspace");+ await page.keyboard.press("Backspace");+ await page.keyboard.press("Backspace");+ await expect(se.tableNameInput).toHaveValue("abc");+ await se.popoverCancelButton.click();+ });++ test("rejects a duplicate table name", async () => {+ await se.openNewTablePopover();+ await se.tableNameInput.fill("audit"); // pre-existing table in hr_test.public+ await expect(se.duplicateNameError).toBeVisible();+ await expect(se.popoverCreateButton).toBeDisabled();+ await se.popoverCancelButton.click();+ });++ test("cancel closes the popover without creating a table", async () => {+ const name = `e2e_cancel_${Date.now()}`;+ await se.openNewTablePopover();+ await se.tableNameInput.fill(name);+ await se.popoverCancelButton.click();+ await expect(se.tableNameInput).toBeHidden();+ // No table was created: we stay in the DatabaseEditor (its "New table"+ // toolbar button is shown), rather than switching to a new table tab+ // (which would show "Add column" instead).+ await expect(se.newTableToolbarButton).toBeVisible();+ await expect(se.addColumnButton).toBeHidden();+ });+});diff --git a/frontend/tests/e2e/schema-editor/schema-editor-diff-insert.spec.ts b/frontend/tests/e2e/schema-editor/schema-editor-diff-insert.spec.tsnew file mode 100644index 0000000000..e1fa2da554--- /dev/null+++ b/frontend/tests/e2e/schema-editor/schema-editor-diff-insert.spec.ts@@ -0,0 +1,95 @@+// Schema editor — DDL generation + insertion (SchemaEditorSheet ++// generateDiffDDL + PreviewPane) and the sheet chrome.+//+// Covers:+// - The full create-table CUJ: build a table + column in the editor, click+// "Insert SQL", and confirm the generated DDL lands in the plan statement.+// - The no-diff path: inserting with no edits shows "No changes to apply"+// and leaves the statement untouched.+// - Maximize / restore toggles the sheet size.++import {+ test,+ expect,+ type Page,+ type BrowserContext,+} from "@playwright/test";+import { loadTestEnv, type TestEnv } from "../framework/env";+import { BytebaseApiClient } from "../framework/api-client";+import { SchemaEditorPage } from "./schema-editor.page";+import { createSchemaEditorPlan } from "./schema-editor-helpers";++test.setTimeout(120_000);++let env: TestEnv & { api: BytebaseApiClient };+let ctx: BrowserContext;+let page: Page;+let se: SchemaEditorPage;+let projectId: string;+let planId: string;++test.beforeAll(async ({ browser }) => {+ env = loadTestEnv();+ await env.api.login(env.adminEmail, env.adminPassword);+ ({ projectId, planId } = await createSchemaEditorPlan(env, "E2E SchemaEditor DiffInsert"));+ ctx = await browser.newContext({ storageState: ".auth/state.json" });+ page = await ctx.newPage();+ se = new SchemaEditorPage(page, env.baseURL);+});++test.afterAll(async () => {+ await ctx?.close();+});++test.describe("generate and insert DDL", () => {+ test.describe.configure({ mode: "serial" });++ test.beforeEach(async () => {+ await se.gotoPlan(projectId, planId);+ await se.open();+ });++ test("inserts the generated CREATE TABLE into the plan statement", async () => {+ await se.selectSchema("public");+ const name = `e2e_ins_${Date.now()}`;+ await se.createTable(name);+ await se.addColumn();+ await se.columnNameInputs().last().fill("label");+ await se.selectColumnType(1, "text"); // reads metadata on insert, not preview++ await se.insertSql();++ // The generated DDL is written into the plan's statement editor. Insert+ // reads the edited metadata (not the preview), so the type is present.+ await expect+ .poll(async () => await se.planStatementText())+ .toContain("CREATE TABLE");+ const stmt = await se.planStatementText();+ expect(stmt).toContain(name);+ expect(stmt).toContain("label");+ expect(stmt).toContain("text");+ });++ test("shows 'No changes to apply' when inserting with no edits", async () => {+ // No edits made — the diff is empty.+ await se.insertSqlButton.click();+ await expect(page.getByText("No changes to apply")).toBeVisible({+ timeout: 10_000,+ });+ // The sheet stays open so the user can keep editing.+ await expect(se.sheet).toBeVisible();+ });++ test("maximize and restore toggles the sheet width", async () => {+ const normal = await se.sheet.boundingBox();+ await se.maximizeButton.click();+ await expect(se.restoreButton).toBeVisible();+ const maximized = await se.sheet.boundingBox();+ expect(maximized!.width).toBeGreaterThan(normal!.width);++ await se.restoreButton.click();+ await expect(se.maximizeButton).toBeVisible();+ const restored = await se.sheet.boundingBox();+ expect(restored!.width).toBeLessThan(maximized!.width);+ });+});diff --git a/frontend/tests/e2e/schema-editor/schema-editor-helpers.ts b/frontend/tests/e2e/schema-editor/schema-editor-helpers.tsnew file mode 100644index 0000000000..2f66c5ed98--- /dev/null+++ b/frontend/tests/e2e/schema-editor/schema-editor-helpers.ts@@ -0,0 +1,29 @@+import type { BytebaseApiClient } from "../framework/api-client";+import type { TestEnv } from "../framework/env";++// Create a DATABASE_CHANGE plan whose spec targets the Postgres `hr_test`+// sample database, so the plan's Statement section renders the "Schema editor"+// button (schemaEditorEligible = target engine is MySQL/TiDB/Postgres). The+// editor only generates SQL for insertion — it never applies to the DB — so+// creating throwaway tables against hr_test in the editor is side-effect free.+export async function createSchemaEditorPlan(+ env: TestEnv & { api: BytebaseApiClient },+ prefix: string+): Promise<{ projectId: string; planId: string; planName: string }> {+ const pg = await env.api.findDatabaseByShortName("hr_test");+ if (!pg) throw new Error("hr_test Postgres database not found");++ const ts = Date.now();+ const sheet = await env.api.createSheet(+ env.project,+ "-- edit via schema editor\n"+ );+ const plan = await env.api.createPlan(env.project, `${prefix} ${ts}`, [+ { id: `spec-${ts}`, targets: [pg.database], sheet },+ ]);+ return {+ projectId: env.project.split("/").pop()!,+ planId: plan.name.split("/").pop()!,+ planName: plan.name,+ };+}diff --git a/frontend/tests/e2e/schema-editor/schema-editor-objects.spec.ts b/frontend/tests/e2e/schema-editor/schema-editor-objects.spec.tsnew file mode 100644index 0000000000..c3419c1589--- /dev/null+++ b/frontend/tests/e2e/schema-editor/schema-editor-objects.spec.ts@@ -0,0 +1,81 @@+// Schema editor — schema-level objects (AsideTree "+" DropdownMenu ++// SchemaNameDialog).+//+// Scope notes:+// - Views / functions / procedures and the indexes / partitions tabs are+// engine-gated to MySQL/TiDB (core/spec.ts) and are NOT shown on the Postgres+// target used here — they need a MySQL target, covered separately.+// - Rename / drop table / drop schema live behind the tree's *hand-rolled*+// right-click context menu (a portaled <div> of <button>s, not a Base UI+// Menu). That menu opens under Playwright (a dispatched `contextmenu`), but+// its portaled items don't interact reliably (stability / click no-op),+// unlike the Base UI "+" DropdownMenu used below which drives cleanly. Those+// operations are left for a follow-up — ideally after the context menu is+// migrated to the shared Base UI DropdownMenu (or given data-testids) for+// parity and testability.+// - Create-schema IS Postgres-valid (engineSupportsMultiSchema(POSTGRES)).++import {+ test,+ expect,+ type Page,+ type BrowserContext,+} from "@playwright/test";+import { loadTestEnv, type TestEnv } from "../framework/env";+import { BytebaseApiClient } from "../framework/api-client";+import { SchemaEditorPage } from "./schema-editor.page";+import { createSchemaEditorPlan } from "./schema-editor-helpers";++test.setTimeout(120_000);++let env: TestEnv & { api: BytebaseApiClient };+let ctx: BrowserContext;+let page: Page;+let se: SchemaEditorPage;+let projectId: string;+let planId: string;++test.beforeAll(async ({ browser }) => {+ env = loadTestEnv();+ await env.api.login(env.adminEmail, env.adminPassword);+ ({ projectId, planId } = await createSchemaEditorPlan(env, "E2E SchemaEditor Objects"));+ ctx = await browser.newContext({ storageState: ".auth/state.json" });+ page = await ctx.newPage();+ se = new SchemaEditorPage(page, env.baseURL);+});++test.afterAll(async () => {+ await ctx?.close();+});++test.describe("schema operations", () => {+ test.describe.configure({ mode: "serial" });++ test.beforeEach(async () => {+ await se.gotoPlan(projectId, planId);+ await se.open();+ });++ test.afterEach(async () => {+ await se.close();+ });++ test("creates a new schema from the + menu", async () => {+ const name = `e2e_sch_${Date.now()}`;+ await se.createSchema(name);+ // The new schema appears as a tree node.+ await expect(se.treeItem(name)).toBeVisible({ timeout: 10_000 });+ });++ test("rejects a duplicate schema name", async () => {+ await se.createMenuTrigger.click();+ await se.createMenuItem("Create schema").click();+ await expect(se.schemaNameInput).toBeVisible();+ await se.schemaNameInput.fill("public"); // already exists+ await expect(page.getByText("Schema name already exists")).toBeVisible();+ await expect(+ se.schemaDialog.getByRole("button", { name: "Create", exact: true })+ ).toBeDisabled();+ await se.schemaDialog.getByRole("button", { name: "Cancel" }).click();+ });+});diff --git a/frontend/tests/e2e/schema-editor/schema-editor-tree-nav.spec.ts b/frontend/tests/e2e/schema-editor/schema-editor-tree-nav.spec.tsnew file mode 100644index 0000000000..b5106053f8--- /dev/null+++ b/frontend/tests/e2e/schema-editor/schema-editor-tree-nav.spec.ts@@ -0,0 +1,78 @@+// Schema editor — tree navigation + table-level operations (AsideTree ++// TabsContainer + TableList).+//+// Covers:+// - Opening multiple tables from the schema's table list navigates via tabs.+// - Dropping an existing table from the list produces a DROP TABLE in the+// generated statement.++import {+ test,+ expect,+ type Page,+ type BrowserContext,+} from "@playwright/test";+import { loadTestEnv, type TestEnv } from "../framework/env";+import { BytebaseApiClient } from "../framework/api-client";+import { SchemaEditorPage } from "./schema-editor.page";+import { createSchemaEditorPlan } from "./schema-editor-helpers";++test.setTimeout(120_000);++let env: TestEnv & { api: BytebaseApiClient };+let ctx: BrowserContext;+let page: Page;+let se: SchemaEditorPage;+let projectId: string;+let planId: string;++test.beforeAll(async ({ browser }) => {+ env = loadTestEnv();+ await env.api.login(env.adminEmail, env.adminPassword);+ ({ projectId, planId } = await createSchemaEditorPlan(env, "E2E SchemaEditor TreeNav"));+ ctx = await browser.newContext({ storageState: ".auth/state.json" });+ page = await ctx.newPage();+ se = new SchemaEditorPage(page, env.baseURL);+});++test.afterAll(async () => {+ await ctx?.close();+});++test.describe("tree navigation and table operations", () => {+ test.describe.configure({ mode: "serial" });++ test.beforeEach(async () => {+ await se.gotoPlan(projectId, planId);+ await se.open();+ await se.selectSchema("public");+ });++ test.afterEach(async () => {+ await se.close();+ });++ test("navigating between objects swaps the editor content", async () => {+ // Open an existing table; its columns render.+ await se.openTableFromList("department");+ await expect(se.columnRow("dept_no")).toBeVisible();++ // Navigate to a freshly-created table; the editor swaps to its columns and+ // the previous table's columns are no longer mounted.+ await se.selectSchema("public");+ const name = `e2e_nav_${Date.now()}`;+ await se.createTable(name);+ await expect(se.columnRow("id")).toBeVisible();+ await expect(se.columnRow("dept_no")).toHaveCount(0);+ });++ test("dropping a table from the list produces a DROP TABLE statement", async () => {+ await se.dropTableButton("salary").click();+ await se.insertSql();++ await expect+ .poll(async () => await se.planStatementText())+ .toContain("DROP TABLE");+ expect(await se.planStatementText()).toContain("salary");+ });+});diff --git a/frontend/tests/e2e/schema-editor/schema-editor.page.ts b/frontend/tests/e2e/schema-editor/schema-editor.page.tsnew file mode 100644index 0000000000..7521b283da--- /dev/null+++ b/frontend/tests/e2e/schema-editor/schema-editor.page.ts@@ -0,0 +1,275 @@+import { type Page, type Locator, expect } from "@playwright/test";++/**+ * Page object for the React Schema Editor (`SchemaEditorLite`), reached from a+ * plan's Statement section via the "Schema editor" button.+ *+ * Locator strategy (see the sheet/popover component structure):+ * - The editor is a Base UI Dialog whose accessible name is its title+ * "Schema editor" — scope everything rendered *inside* the sheet (tree, tabs,+ * column grid, toolbar, preview, footer) to `this.sheet`.+ * - The New-table popover, the column-type suggestion dropdown, the tree "+"+ * menu, and the name dialogs all portal to the shared overlay root as+ * *siblings* of the sheet, so they are located at page level, not under+ * `this.sheet`.+ * - The tree's create-object "+" button carries aria-label="Create" (an icon+ * button with no text). That collides by accessible name with the popover's+ * "Create" button, so the popover Create is matched by its visible text.+ */+export class SchemaEditorPage {+ readonly page: Page;+ readonly baseURL: string;++ // Plan statement section (outside the sheet).+ readonly openButton: Locator;+ readonly planStatementEditor: Locator;++ // Sheet container + footer.+ readonly sheet: Locator;+ readonly insertSqlButton: Locator;+ readonly sheetCancelButton: Locator;+ readonly sheetCloseButton: Locator;+ readonly maximizeButton: Locator;+ readonly restoreButton: Locator;++ // Toolbar (inside the sheet).+ readonly newTableToolbarButton: Locator;+ readonly addColumnButton: Locator;++ // Portaled overlays (page level).+ readonly tableNameInput: Locator;+ readonly popoverCreateButton: Locator;+ readonly popoverSaveButton: Locator;+ readonly popoverCancelButton: Locator;+ readonly duplicateNameError: Locator;++ constructor(page: Page, baseURL: string) {+ this.page = page;+ this.baseURL = baseURL;++ this.openButton = page.getByRole("button", { name: "Schema editor" });+ // The plan's own statement editor is the only Monaco on the page once the+ // sheet is closed.+ this.planStatementEditor = page.locator(".monaco-editor").first();++ this.sheet = page.getByRole("dialog", { name: "Schema editor" });+ this.insertSqlButton = this.sheet.getByRole("button", {+ name: "Insert SQL",+ });+ this.sheetCancelButton = this.sheet.getByRole("button", { name: "Cancel" });+ this.sheetCloseButton = this.sheet.getByRole("button", { name: "Close" });+ this.maximizeButton = this.sheet.getByRole("button", { name: "Maximize" });+ this.restoreButton = this.sheet.getByRole("button", { name: "Restore" });++ this.newTableToolbarButton = this.sheet.getByRole("button", {+ name: "New table",+ });+ this.addColumnButton = this.sheet.getByRole("button", {+ name: "Add column",+ });++ this.tableNameInput = page.getByRole("textbox", { name: "Table name" });+ // Popover Create/Save carry visible text; the tree "+" icon button shares+ // the "Create" accessible name but has no text, so filter by text.+ this.popoverCreateButton = page+ .getByRole("button", { name: "Create", exact: true })+ .filter({ hasText: "Create" });+ this.popoverSaveButton = page+ .getByRole("button", { name: "Save", exact: true })+ .filter({ hasText: "Save" });+ // The sheet footer also has a "Cancel"; scope the popover's Cancel to the+ // Create button's row (Cancel + Create are siblings in the popover).+ this.popoverCancelButton = this.popoverCreateButton+ .locator("..")+ .getByRole("button", { name: "Cancel" });+ this.duplicateNameError = page.getByText("Table name already exists");+ }++ async gotoPlan(projectId: string, planId: string): Promise<void> {+ await this.page.goto(`${this.baseURL}/projects/${projectId}/plans/${planId}`);+ await this.page.waitForLoadState("networkidle");+ }++ async open(): Promise<void> {+ await this.openButton.click();+ await expect(this.sheet).toBeVisible({ timeout: 15_000 });+ // Tree is ready once the schema nodes render.+ await expect(this.treeItem("public")).toBeVisible({ timeout: 15_000 });+ }++ async close(): Promise<void> {+ if (await this.sheet.isVisible().catch(() => false)) {+ await this.sheetCancelButton.click();+ await expect(this.sheet).toBeHidden({ timeout: 10_000 });+ }+ }++ // ---- Tree ----+ treeItem(name: string): Locator {+ return this.sheet.getByRole("treeitem", { name, exact: false });+ }++ async selectSchema(name: string): Promise<void> {+ await this.treeItem(name).click();+ }++ // ---- Tree "+" create menu (Base UI DropdownMenu → role=menuitem) ----+ get createMenuTrigger(): Locator {+ // The tree toolbar "+" button carries aria-label "Create" and has no text,+ // so it's the only "Create"-named button in the sheet when no popover is up.+ return this.sheet.getByRole("button", { name: "Create", exact: true });+ }++ createMenuItem(label: string): Locator {+ return this.page.getByRole("menuitem", { name: label });+ }++ // ---- Schema name dialog (create schema) ----+ get schemaDialog(): Locator {+ return this.page.getByRole("dialog", { name: "Create schema" });+ }++ get schemaNameInput(): Locator {+ return this.page.getByRole("textbox", { name: "Schema name" });+ }++ async createSchema(name: string): Promise<void> {+ await this.createMenuTrigger.click();+ await this.createMenuItem("Create schema").click();+ await expect(this.schemaNameInput).toBeVisible({ timeout: 10_000 });+ await this.schemaNameInput.fill(name);+ await this.schemaDialog+ .getByRole("button", { name: "Create", exact: true })+ .click();+ await expect(this.schemaDialog).toBeHidden({ timeout: 10_000 });+ }++ // ---- Create table (via toolbar) ----+ async openNewTablePopover(): Promise<void> {+ await this.newTableToolbarButton.click();+ await expect(this.tableNameInput).toBeVisible({ timeout: 10_000 });+ }++ async createTable(name: string): Promise<void> {+ await this.openNewTablePopover();+ await this.tableNameInput.fill(name);+ await expect(this.popoverCreateButton).toBeEnabled();+ await this.popoverCreateButton.click();+ await expect(this.tableNameInput).toBeHidden({ timeout: 10_000 });+ // The new table opens in a tab and renders its TableEditor asynchronously.+ // Wait for the toolbar (and thus the default `id` column) to render before+ // returning, so a follow-up addColumn()/column read doesn't race an+ // empty grid and capture a stale count.+ await expect(this.addColumnButton).toBeVisible({ timeout: 10_000 });+ await expect(this.columnRow("id")).toBeVisible({ timeout: 10_000 });+ }++ // ---- Column grid ----+ columnNameInputs(): Locator {+ return this.sheet.getByRole("textbox", { name: "Column name" });+ }++ columnTypeInputs(): Locator {+ return this.sheet.getByRole("textbox", { name: "column type" });+ }++ // A grid row by its rendered column name (row accessible name starts with it).+ columnRow(nameFragment: string | RegExp): Locator {+ return this.sheet.getByRole("row", { name: nameFragment });+ }++ async addColumn(): Promise<void> {+ const before = await this.columnNameInputs().count();+ await this.addColumnButton.click();+ await expect(this.columnNameInputs()).toHaveCount(before + 1, {+ timeout: 10_000,+ });+ }++ // Open the type suggestion dropdown for the column row at `rowIndex` and pick+ // `type`. The dropdown options portal to the overlay root (page level).+ async selectColumnType(rowIndex: number, type: string): Promise<void> {+ await this.columnTypeInputs().nth(rowIndex).click();+ const option = this.page+ .getByRole("button", { name: type, exact: true })+ .filter({ hasText: type });+ await expect(option.first()).toBeVisible({ timeout: 10_000 });+ await option.first().click();+ await expect(this.columnTypeInputs().nth(rowIndex)).toHaveValue(type, {+ timeout: 10_000,+ });+ }++ typeDropdownOption(type: string): Locator {+ return this.page+ .getByRole("button", { name: type, exact: true })+ .filter({ hasText: type });+ }++ // Not Null / Primary checkboxes for a column row. Cells are positional+ // (name, type, default, comment, not-null, primary, operations) per+ // TableColumnEditor's columnDefs; scope by cell index to avoid ambiguity.+ notNullCheckbox(nameFragment: string | RegExp): Locator {+ return this.columnRow(nameFragment)+ .getByRole("cell")+ .nth(4)+ .getByRole("checkbox")+ .first();+ }++ primaryCheckbox(nameFragment: string | RegExp): Locator {+ return this.columnRow(nameFragment)+ .getByRole("cell")+ .nth(5)+ .getByRole("checkbox")+ .first();+ }++ dropColumnButton(nameFragment: string | RegExp): Locator {+ return this.columnRow(nameFragment)+ .getByRole("cell")+ .last()+ .getByRole("button")+ .first();+ }++ // Drop/restore button for a table row in the DatabaseEditor's TableList.+ // (The trash button stops propagation, so it drops without opening the table.)+ dropTableButton(name: string | RegExp): Locator {+ return this.sheet+ .getByRole("row", { name })+ .getByRole("button")+ .last();+ }++ // Open an existing table by clicking its name cell in the DatabaseEditor's+ // TableList (row onClick → onEditTable). Requires the `public` schema tab.+ // Tab labels are truncated, so confirm via the TableEditor toolbar instead.+ async openTableFromList(name: string): Promise<void> {+ await this.selectSchema("public");+ await this.sheet.getByRole("cell", { name, exact: true }).first().click();+ await expect(this.addColumnButton).toBeVisible({ timeout: 10_000 });+ }++ // ---- Preview ----+ // Reads the Preview pane's readonly Monaco. Content extraction (not a control+ // assertion), so reading the editor's text is acceptable. Line numbers are+ // included but harmless for substring assertions.+ async previewText(): Promise<string> {+ const preview = this.sheet.locator(".monaco-editor .view-lines").last();+ await expect(preview).toBeVisible({ timeout: 10_000 });+ return (await preview.innerText()).replace(/ /g, " ");+ }++ // ---- Insert / statement ----+ async insertSql(): Promise<void> {+ await this.insertSqlButton.click();+ await expect(this.sheet).toBeHidden({ timeout: 15_000 });+ }++ async planStatementText(): Promise<string> {+ const editor = this.page.locator(".monaco-editor .view-lines").first();+ await expect(editor).toBeVisible({ timeout: 10_000 });+ return (await editor.innerText()).replace(/ /g, " ");+ }+}