Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

test(e2e): adapt sql-editor to route-ownership refactor + fix scroll-restoration flake

zchpeter91fa9a911e4c
diff --git a/frontend/tests/e2e/scroll-restoration/dashboard-scroll-restoration.spec.ts b/frontend/tests/e2e/scroll-restoration/dashboard-scroll-restoration.spec.ts
index a1eabd7d9f..eab453377d 100644
--- a/frontend/tests/e2e/scroll-restoration/dashboard-scroll-restoration.spec.ts
+++ b/frontend/tests/e2e/scroll-restoration/dashboard-scroll-restoration.spec.ts
@@ -37,15 +37,29 @@ const readViewport = (row: Locator): Promise<SavedViewport> =>
};
});
+// Build the initial list up to `expectedCount` rows by clicking "Load more",
+// the way a user loads more of a paginated list. Each page is fetched
+// asynchronously and can lag under full-suite server load, so this is patient:
+// it waits for the row count to grow after each click and keeps clicking
+// "Load more" whenever the affordance is present, bounded by an overall
+// deadline, rather than assuming a click immediately yields the next page.
async function loadAllRows(rows: Locator, expectedCount: number): Promise<void> {
- while ((await rows.count()) < expectedCount) {
+ const loadMore = page.getByRole("button", { name: /Load more/i }).first();
+ const deadline = Date.now() + 90_000;
+ while ((await rows.count()) < expectedCount && Date.now() < deadline) {
const previousCount = await rows.count();
- await page.getByRole("button", { name: /Load more/i }).click();
- await expect
- .poll(() => rows.count())
- .toBeGreaterThan(previousCount);
+ if (await loadMore.isVisible().catch(() => false)) {
+ await loadMore.click().catch(() => {});
+ await expect
+ .poll(() => rows.count(), { timeout: 15_000 })
+ .toBeGreaterThan(previousCount)
+ .catch(() => {});
+ } else {
+ // "Load more" not shown yet — a restore may still be re-fetching a page.
+ await page.waitForTimeout(500);
+ }
}
- await expect(rows).toHaveCount(expectedCount);
+ await expect(rows).toHaveCount(expectedCount, { timeout: 20_000 });
}
async function expectBackRestored({
@@ -64,6 +78,17 @@ async function expectBackRestored({
await expect(rows.first()).toBeVisible({ timeout: 20_000 });
await loadAllRows(rows, rowCount);
+ // Mimic a real user dwelling on the loaded list before drilling into a row.
+ // The app persists its paged-data snapshot in a passive effect that runs after
+ // the rows render; a human's pause lets it finish, but Playwright otherwise
+ // navigates away instantly and the snapshot is written stale (or not at all).
+ // With the snapshot complete, the back-navigation below restores every row
+ // from cache with NO refetch — which also sidesteps the POP-mount fetch/abort
+ // race that otherwise leaves the list short or empty. Waiting for network idle
+ // is the settle signal; the small margin covers the post-render effect.
+ await page.waitForLoadState("networkidle", { timeout: 10_000 }).catch(() => {});
+ await page.waitForTimeout(1_000);
+
const target = rows.last();
await target.scrollIntoViewIfNeeded();
const before = await readViewport(target);
@@ -73,20 +98,31 @@ async function expectBackRestored({
await expect(page).toHaveURL(detailUrlPattern, { timeout: 20_000 });
await page.goBack();
await expect(page).toHaveURL(listUrl);
+ // The list is restored from the persisted snapshot (a no-refresh POP), so all
+ // rows come back together — a simple wait, no "Load more" nudge needed.
await expect(rows).toHaveCount(rowCount, { timeout: 20_000 });
await expect(target).toBeVisible({ timeout: 20_000 });
+ // The restore re-applies the saved scroll position asynchronously after the
+ // rows settle — poll generously so a slow re-application under load doesn't
+ // read a mid-restore frame.
await expect
- .poll(async () => {
- const after = await readViewport(target);
- return Math.abs(after.scrollTop - before.scrollTop);
- })
+ .poll(
+ async () => {
+ const after = await readViewport(target);
+ return Math.abs(after.scrollTop - before.scrollTop);
+ },
+ { timeout: 20_000 }
+ )
.toBeLessThanOrEqual(2);
await expect
- .poll(async () => {
- const after = await readViewport(target);
- return Math.abs(after.anchorOffset - before.anchorOffset);
- })
+ .poll(
+ async () => {
+ const after = await readViewport(target);
+ return Math.abs(after.anchorOffset - before.anchorOffset);
+ },
+ { timeout: 20_000 }
+ )
.toBeLessThanOrEqual(2);
expect(await page.evaluate(() => window.scrollY)).toBe(0);
}
diff --git a/frontend/tests/e2e/sql-editor/sql-editor-connection.spec.ts b/frontend/tests/e2e/sql-editor/sql-editor-connection.spec.ts
index 442cfa56ed..8dda26339b 100644
--- a/frontend/tests/e2e/sql-editor/sql-editor-connection.spec.ts
+++ b/frontend/tests/e2e/sql-editor/sql-editor-connection.spec.ts
@@ -48,11 +48,13 @@ test.describe("Cold-open lands on the SQL Editor home view", () => {
await sqlEditor.gotoHome();
await page.waitForTimeout(800);
- // Project picker is rendered as a Combobox with `.project-select`.
- // (AsidePanel.tsx mounts <ProjectSelect className="...project-select"/>.)
- await expect(page.locator(".project-select").first()).toBeVisible({
- timeout: 10_000,
- });
+ // Project switching now lives in the shared SQL Editor header
+ // (SQLEditorHeader → HeaderBreadcrumb → ProjectSegment). The route-ownership
+ // refactor removed the old AsidePanel `.project-select` combobox, so the
+ // stable home-view landmark is the header's "Select project" switcher.
+ await expect(
+ page.getByRole("button", { name: "Select project" }).first(),
+ ).toBeVisible({ timeout: 10_000 });
// Gutter rail buttons are stable user-facing labels (SavedQuery /
// Schema / History gutter tabs).
@@ -167,35 +169,34 @@ test.describe("Project switcher updates the editor's project context", () => {
await sqlEditor.gotoWithDb(projectId, env.instanceId, env.databaseId);
await page.waitForTimeout(800);
- // The Combobox primitive (combobox.tsx) renders the trigger as a
- // bare <div> with onClick — no implicit role="combobox". We click
- // the wrapper directly. Options inside the dropdown are <button>
- // elements containing the project label text.
- const projectSelectTrigger = page.locator(".project-select").first();
- await expect(projectSelectTrigger).toBeVisible({ timeout: 10_000 });
-
- // Pick the secondary project — different from the env default.
- await projectSelectTrigger.click();
- // Each project option's accessible name combines label + slug
- // (e.g., "Sample Project project-sample"), so `exact: true` on
- // the label alone won't match. We match the button containing the
- // label as visible text — narrower than role-only and still
- // resilient to slug renames.
+ // Project switching moved to the header breadcrumb (ProjectSegment). Open
+ // its "Select project" switcher; the popover shows Recent/All tabs, a
+ // filter, and a project table whose rows select on click.
+ const projectSwitcher = page
+ .getByRole("button", { name: "Select project" })
+ .first();
+ await expect(projectSwitcher).toBeVisible({ timeout: 10_000 });
+ await projectSwitcher.click();
+
+ // Filter by the secondary project's name so it surfaces regardless of
+ // recency, then click its row.
+ const filter = page.getByPlaceholder("Filter by name");
+ await expect(filter).toBeVisible({ timeout: 5000 });
+ await filter.fill(SECONDARY_PROJECT_TITLE);
const option = page
- .getByRole("button")
- .filter({ hasText: SECONDARY_PROJECT_TITLE })
+ .getByText(SECONDARY_PROJECT_TITLE, { exact: true })
.first();
await expect(option).toBeVisible({ timeout: 5000 });
await option.click();
- // The editor's project context switches to the picked project — the
- // project-select trigger now displays it. (The SQL-editor route is
- // database-centric: the URL's project segment only changes once a
- // database in the new project is opened, so an empty project like the
- // secondary one keeps the prior DB URL while the context switches.)
- await expect(projectSelectTrigger).toContainText(SECONDARY_PROJECT_TITLE, {
- timeout: 10_000,
- });
+ // The editor's project context switches — the header breadcrumb's project
+ // segment now displays the picked project. (The SQL-editor route is
+ // database-centric: the URL's project segment only changes once a database
+ // in the new project is opened, so an empty project like the secondary one
+ // keeps the prior DB URL while the context switches.)
+ await expect(
+ page.locator("header").getByText(SECONDARY_PROJECT_TITLE, { exact: true }),
+ ).toBeVisible({ timeout: 10_000 });
});
});
diff --git a/frontend/tests/e2e/sql-editor/sql-editor-misc.spec.ts b/frontend/tests/e2e/sql-editor/sql-editor-misc.spec.ts
index 2daef868c1..d1ef5bd35b 100644
--- a/frontend/tests/e2e/sql-editor/sql-editor-misc.spec.ts
+++ b/frontend/tests/e2e/sql-editor/sql-editor-misc.spec.ts
@@ -110,23 +110,24 @@ test.describe("Gutter tab switching (H4)", () => {
});
});
-test.describe("Gutter logo opens in a new tab (H5)", () => {
- test("logo anchor has target=_blank and rel=noopener noreferrer", async () => {
+test.describe("Header logo links to the workspace landing (H5)", () => {
+ test("logo is an in-app link to the landing page, not a new-tab external anchor", async () => {
const projectId = env.project.split("/").pop()!;
await sqlEditor.gotoWithDb(projectId, env.instanceId, env.databaseId);
- // The gutter logo is the only <img alt="Bytebase"> on the page;
- // walk up to its anchor parent.
+ // The route-ownership refactor moved the logo into the shared SQL Editor
+ // header (SQLEditorHeader → BytebaseLogo) and made it an in-app RouterLink
+ // to the workspace landing route — no longer an external new-tab anchor.
+ // It's the only <img alt="Bytebase"> on the page; walk up to its <a>.
const logoAnchor = page
.locator("a")
.filter({ has: page.locator('img[alt="Bytebase"]') })
.first();
await expect(logoAnchor).toBeVisible({ timeout: 10_000 });
- await expect(logoAnchor).toHaveAttribute("target", "_blank");
- await expect(logoAnchor).toHaveAttribute(
- "rel",
- /noopener.*noreferrer|noreferrer.*noopener/,
- );
+ // Internal SPA navigation: a relative href to the landing route, and NOT a
+ // new-tab link.
+ await expect(logoAnchor).toHaveAttribute("href", /\/landing/);
+ await expect(logoAnchor).not.toHaveAttribute("target", "_blank");
});
});