Add device labeling e2e test; add data-ip for reliable row targeting
CI / web (push) Successful in 17s
CI / api (push) Successful in 23s

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 <noreply@anthropic.com>
This commit is contained in:
2026-07-12 23:08:06 -06:00
parent 7a685b9bd8
commit b84fd373c2
2 changed files with 39 additions and 1 deletions
+38
View File
@@ -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");
});