diff --git a/e2e/maputnik-driver.ts b/e2e/maputnik-driver.ts index f54177bb..08463a4e 100644 --- a/e2e/maputnik-driver.ts +++ b/e2e/maputnik-driver.ts @@ -493,6 +493,31 @@ export class MaputnikDriver { waitForExampleFileResponse: () => this.when.waitForResponse("example-style.json"), clearLocalStorage: () => this.page.evaluate(() => window.localStorage.clear()), + + /** fill localStorage until we get a QuotaExceededError */ + fillLocalStorage: async () => { + await this.page.evaluate(() => { + let chunkSize = 1000; + const chunk = new Array(chunkSize).join("x"); + let index = 0; + + // Keep adding until we hit the quota + for (;;) { + try { + const key = `maputnik:fill-${index++}`; + window.localStorage.setItem(key, chunk); + } catch (e: any) { + // Verify it's a quota error + if (e.name === "QuotaExceededError") { + if (chunkSize <= 1) return; + chunkSize /= 2; + continue; + } + throw e; // Unexpected error + } + } + }); + } }; // ---- get ----------------------------------------------------------------- diff --git a/e2e/modals.spec.ts b/e2e/modals.spec.ts index 8ee3ba4a..655b1982 100644 --- a/e2e/modals.spec.ts +++ b/e2e/modals.spec.ts @@ -391,29 +391,7 @@ describe("modals", () => { test("handles quota exceeded error when opening style from URL", async ({ page }) => { // Clear localStorage to start fresh await when.clearLocalStorage(); - - // fill localStorage until we get a QuotaExceededError - await page.evaluate(() => { - let chunkSize = 1000; - const chunk = new Array(chunkSize).join("x"); - let index = 0; - - // Keep adding until we hit the quota - for (;;) { - try { - const key = `maputnik:fill-${index++}`; - window.localStorage.setItem(key, chunk); - } catch (e: any) { - // Verify it's a quota error - if (e.name === "QuotaExceededError") { - if (chunkSize <= 1) return; - chunkSize /= 2; - continue; - } - throw e; // Unexpected error - } - } - }); + await when.fillLocalStorage(); // Open the style via URL input await when.click("nav:open");