diff --git a/e2e/tests/new-device-badge.spec.ts b/e2e/tests/new-device-badge.spec.ts new file mode 100644 index 0000000..27eddf5 --- /dev/null +++ b/e2e/tests/new-device-badge.spec.ts @@ -0,0 +1,28 @@ +import { test, expect } from "@playwright/test"; + +const USERNAME = process.env.LOCAL_USERNAME ?? "admin"; +const PASSWORD = process.env.LOCAL_PASSWORD ?? ""; + +test("'new' badge count matches the API's isNew count", async ({ page }) => { + test.skip(!PASSWORD, "LOCAL_PASSWORD not set"); + + await page.goto("/"); + await page.getByPlaceholder("Username").fill(USERNAME); + await page.getByPlaceholder("Password").fill(PASSWORD); + await page.getByRole("button", { name: "Sign in" }).click(); + await expect(page.locator(".device-table tbody tr").first()).toBeVisible({ timeout: 15_000 }); + + // Cross-check against the API directly rather than forcing a synthetic + // "new device" scenario -- that would permanently pollute the production + // seen_macs table on every test run. Whatever's genuinely new right now is + // enough to verify the UI reflects the API correctly. page.request (not + // the bare `request` fixture) shares the browser context's session cookie. + const res = await page.request.get("/api/devices"); + const { devices } = await res.json(); + const apiNewCount = devices.filter((d: { isNew: boolean }) => d.isNew).length; + + await expect(async () => { + const badgeCount = await page.locator(".device-badge.new").count(); + expect(badgeCount).toBe(apiNewCount); + }).toPass({ timeout: 10_000 }); +});