From b84fd373c2626f253903c51259bcb2f371d3b023 Mon Sep 17 00:00:00 2001 From: jhodgkin Date: Sun, 12 Jul 2026 23:08:06 -0600 Subject: [PATCH] Add device labeling e2e test; add data-ip for reliable row targeting First test run hit a bug in the test itself: Playwright's hasText filter does substring matching, so IP 192.168.1.1 matched 192.168.1.10, 192.168.1.100, 192.168.1.171, etc -- flaky/wrong row selection. Added a data-ip attribute to each row for exact targeting instead of relying on text content. Co-Authored-By: Claude Sonnet 5 --- apps/web/src/components/DeviceTable.tsx | 2 +- e2e/tests/device-labeling.spec.ts | 38 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 e2e/tests/device-labeling.spec.ts diff --git a/apps/web/src/components/DeviceTable.tsx b/apps/web/src/components/DeviceTable.tsx index f370f2f..94b5c0f 100644 --- a/apps/web/src/components/DeviceTable.tsx +++ b/apps/web/src/components/DeviceTable.tsx @@ -133,7 +133,7 @@ export function DeviceTable({ {sorted.map((d) => ( - + {d.known ? "known" : "unknown"} diff --git a/e2e/tests/device-labeling.spec.ts b/e2e/tests/device-labeling.spec.ts new file mode 100644 index 0000000..2d7e8bf --- /dev/null +++ b/e2e/tests/device-labeling.spec.ts @@ -0,0 +1,38 @@ +import { test, expect } from "@playwright/test"; + +const USERNAME = process.env.LOCAL_USERNAME ?? "admin"; +const PASSWORD = process.env.LOCAL_PASSWORD ?? ""; + +test("labeling an unknown device makes it known, clearing reverts it", 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 }); + + const unknownRow = page.locator(".device-table tbody tr").filter({ hasText: "unknown" }).first(); + await expect(unknownRow).toBeVisible(); + const ip = await unknownRow.getAttribute("data-ip"); + + // Exact match via data-ip, not text -- an IP like 192.168.1.1 is a + // substring of 192.168.1.100/117/171/etc, so text-based row filtering is + // not reliable here (caught this the hard way on the first run). + const row = page.locator(`tr[data-ip="${ip}"]`); + + await row.locator(".name-cell").click(); + await row.getByPlaceholder("Label this device").fill("Playwright test label"); + await row.getByRole("button", { name: "Save" }).click(); + + await expect(row.locator(".device-badge")).toHaveText("known"); + await expect(row).toContainText("Playwright test label"); + + // Clear it back out so the test doesn't leave permanent residue on a real device. + await row.locator(".name-cell").click(); + await row.getByPlaceholder("Label this device").fill(""); + await row.getByRole("button", { name: "Save" }).click(); + + await expect(row.locator(".device-badge")).toHaveText("unknown"); + await expect(row).not.toContainText("Playwright test label"); +});