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 <noreply@anthropic.com>
This commit is contained in:
@@ -133,7 +133,7 @@ export function DeviceTable({
|
||||
</thead>
|
||||
<tbody>
|
||||
{sorted.map((d) => (
|
||||
<tr key={d.ip}>
|
||||
<tr key={d.ip} data-ip={d.ip}>
|
||||
<td>
|
||||
<span className={`device-badge ${d.known ? "known" : "unknown"}`}>
|
||||
{d.known ? "known" : "unknown"}
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
Reference in New Issue
Block a user