From a251faf8f7f9e0bde2acfbcd320d54b8869c4412 Mon Sep 17 00:00:00 2001 From: HarelM Date: Thu, 9 Jul 2026 14:27:33 +0300 Subject: [PATCH] improve abstraction --- e2e/layer-editor.spec.ts | 11 ++----- e2e/layers-list.spec.ts | 2 +- e2e/maputnik-driver.ts | 62 ++++++++++++++++++---------------------- e2e/modal-driver.ts | 14 ++++----- e2e/modals.spec.ts | 2 +- 5 files changed, 39 insertions(+), 52 deletions(-) diff --git a/e2e/layer-editor.spec.ts b/e2e/layer-editor.spec.ts index 6729a254..c510315b 100644 --- a/e2e/layer-editor.spec.ts +++ b/e2e/layer-editor.spec.ts @@ -176,9 +176,7 @@ describe("layer editor", () => { await when.collapseGroupInLayerEditor(); await when.collapseGroupInLayerEditor(1); await when.collapseGroupInLayerEditor(2); - await when.doWithin("spec-field:text-font", async () => { - await get.element(".maputnik-autocomplete input").first().click(); - }); + await when.clickWithin("spec-field:text-font", ".maputnik-autocomplete input"); await then(get.element(".maputnik-autocomplete-menu-item")).shouldBeVisible(); await then(get.element(".maputnik-autocomplete-menu-item")).shouldHaveLength(3); }); @@ -202,8 +200,7 @@ describe("layer editor", () => { layers: [{ id, type: "circle", source: "example" }], }); - const sourceText = get.elementByText('"source"'); - await sourceText.click(); + await when.clickByText('"source"'); await when.typeKeys('"'); await then(get.element(".cm-lint-marker-error")).shouldExist(); @@ -239,9 +236,7 @@ describe("layer editor", () => { const header = get.elementByTestId("layer-editor.header"); await then(header).shouldBeVisible(); - await get - .element(".maputnik-scroll-container") - .evaluate((el) => el.scrollTo(0, el.scrollHeight)); + await when.scrollToBottom(get.element(".maputnik-scroll-container")); await when.wait(200); await then(header).shouldBeVisible(); diff --git a/e2e/layers-list.spec.ts b/e2e/layers-list.spec.ts index edc30b3b..786a1b3d 100644 --- a/e2e/layers-list.spec.ts +++ b/e2e/layers-list.spec.ts @@ -342,7 +342,7 @@ describe("layers list", () => { await then(header).shouldBeVisible(); // Scroll the layer list container - await get.elementByTestId("layer-list").evaluate((el) => el.scrollTo(0, el.scrollHeight)); + await when.scrollToBottom(get.elementByTestId("layer-list")); await when.wait(200); await then(header).shouldBeVisible(); await then(get.elementByTestId("layer-list:add-layer")).shouldBeVisible(); diff --git a/e2e/maputnik-driver.ts b/e2e/maputnik-driver.ts index 08463a4e..c08460c9 100644 --- a/e2e/maputnik-driver.ts +++ b/e2e/maputnik-driver.ts @@ -203,7 +203,6 @@ async function centerOf(locator: Locator): Promise<{ x: number; y: number }> { } export class MaputnikDriver { - private scope: Locator | null = null; private readonly recordedRequests = new Map(); private readonly modalDriver = new ModalDriver(this); @@ -217,12 +216,8 @@ export class MaputnikDriver { // ---- Element access ------------------------------------------------------ - private root(): Page | Locator { - return this.scope ?? this.page; - } - private testId(testId: string): Locator { - return this.root().locator(testIdSelector(testId)); + return this.page.locator(testIdSelector(testId)); } then = (target: T) => new MaputnikAssertable(target, this.page); @@ -307,16 +302,6 @@ export class MaputnikDriver { typeKeys: (keys: string) => typeSequence(this.page, keys), - doWithin: async (selector: string, fn: () => Promise | void) => { - const previous = this.scope; - this.scope = (previous ?? this.page).locator(testIdSelector(selector)); - try { - await fn(); - } finally { - this.scope = previous; - } - }, - click: async (testId: string, index = 0) => { // Documentation buttons are wrapped in a