Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions e2e/dashboard-widgets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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());
Expand All @@ -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" })
Expand All @@ -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());
Expand All @@ -289,15 +293,16 @@ 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,
unit: "prs",
});
});

function mockMetricResponse(url) {
function mockMetricResponse(url: string) {
if (url.includes("/api/metrics/prs")) {
return {
open: 2,
Expand Down
Loading