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 }); });