Files
homelab-monitor/e2e/tests/new-device-badge.spec.ts
T
jhodgkin dfdc37eec1
CI / web (push) Successful in 15s
CI / api (push) Successful in 22s
Add e2e coverage for the new-device badge
Cross-checks the rendered .device-badge.new count against the API's
isNew count rather than forcing a synthetic new-device scenario --
that would permanently pollute the production seen_macs table on
every test run. Full end-to-end verification (synthetic device
injected via devices-raw.json, confirmed isNew: true, confirmed 0
false positives across the other 71 real devices) was done manually
against the live deployment and cleaned up afterward; this test
guards the UI/API consistency going forward.

16/16 e2e tests green across 9 spec files.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-13 00:06:04 -06:00

29 lines
1.3 KiB
TypeScript

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