diff --git a/e2e/dashboard-widgets.spec.js b/e2e/dashboard-widgets.spec.js index 02dd19ec8..e6a3261dd 100644 --- a/e2e/dashboard-widgets.spec.js +++ b/e2e/dashboard-widgets.spec.js @@ -126,7 +126,9 @@ test.beforeEach(async ({ page }) => { }); }); - await page.route("**/api/goals**", async (route) => { + // Use regex to exactly match /api/goals or /api/goals?params + // Prevents shadowing /api/goals/sync + await page.route(/\/api\/goals(\?|$)/, async (route) => { if (route.request().method() === "POST") { await route.fulfill({ contentType: "application/json", @@ -225,6 +227,7 @@ test.beforeEach(async ({ page }) => { }); }); }); + test("dashboard widgets render with mocked metrics", async ({ page }) => { await page.goto("/dashboard", { waitUntil: "load" }); await expect( @@ -248,7 +251,7 @@ test("dashboard widgets render with mocked metrics", async ({ page }) => { test("contribution graph range buttons request a new range", async ({ page, }) => { - const contributionRequests = []; + const contributionRequests: string[] = []; page.on("request", (request) => { if (request.url().includes("/api/metrics/contributions")) { contributionRequests.push(request.url()); @@ -259,7 +262,8 @@ test("contribution graph range buttons request a new range", async ({ await expect( page.getByRole("heading", { name: "Dashboard", exact: true }) ).toBeVisible({ timeout: 30000 }); - await page.getByRole("button", { name: "Show 90-day range" }).first().click(); + + // Click only the correctly scoped locator await page .locator("#contribution-activity") .getByRole("button", { name: "Show 90-day range" }) @@ -273,7 +277,7 @@ test("contribution graph range buttons request a new range", async ({ }); test("goal form posts a new goal", async ({ page }) => { - const goalPosts = []; + const goalPosts: unknown[] = []; page.on("request", (request) => { if (request.url().endsWith("/api/goals") && request.method() === "POST") { goalPosts.push(request.postDataJSON()); @@ -289,7 +293,8 @@ test("goal form posts a new goal", async ({ page }) => { await page.getByLabel("Unit", { exact: true }).selectOption("prs"); await page.getByRole("button", { name: "Create goal" }).click(); - await expect.poll(() => goalPosts, { timeout: 15000 }).toHaveLength(1); + // Evaluate the length primitive to avoid array reference polling issues + await expect.poll(() => goalPosts.length, { timeout: 15000 }).toBe(1); expect(goalPosts[0]).toMatchObject({ title: "Ship one PR", target: 1, @@ -297,7 +302,7 @@ test("goal form posts a new goal", async ({ page }) => { }); }); -function mockMetricResponse(url) { +function mockMetricResponse(url: string) { if (url.includes("/api/metrics/prs")) { return { open: 2,