Skip to content

Commit 932ab93

Browse files
committed
use playwright / vitest locators as much as possible
1 parent 720f90f commit 932ab93

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

app/integration/devices.test.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ test("devices route renders the device list page", async ({ page }) => {
2929
await expect(table).toBeVisible();
3030

3131
// Verify our test device is in the table
32-
const deviceLink = await page.locator("table td a", {
33-
hasText: TEST_DEVICE_NAME,
34-
});
32+
const deviceLink = await page.getByRole("link", { name: TEST_DEVICE_NAME });
3533
await expect(deviceLink).toBeVisible();
3634
// Verify the device status is online
37-
const statusBadge = await page.locator('table .badge:has-text("online")');
35+
const statusBadge = await page.getByText("online", { exact: true });
3836
await expect(statusBadge).toBeVisible();
3937
});
4038

@@ -58,9 +56,7 @@ test("adding a new device works correctly", async ({ page }) => {
5856
await page.getByRole("link", { name: "devices" }).click();
5957

6058
// Verify our test device is in the table
61-
const newDeviceUrl = await page.locator("table a", {
62-
hasText: NEW_DEVICE_URL,
63-
});
59+
const newDeviceUrl = await page.getByRole("link", { name: NEW_DEVICE_URL });
6460
await expect(newDeviceUrl).toBeVisible();
6561
});
6662

@@ -69,7 +65,7 @@ test("device detail page and tab navigation", async ({ page }) => {
6965
await page.goto("/devices/list", { waitUntil: "load" });
7066

7167
// Click on our pre-seeded mock device
72-
await page.locator("table td a", { hasText: TEST_DEVICE_NAME }).click();
68+
await page.getByRole("link", { name: TEST_DEVICE_NAME }).click();
7369

7470
// Wait for navigation to complete - should be redirected to the state tab
7571
await page.waitForURL(/\/devices\/.*\/.*\/state/);
@@ -78,12 +74,7 @@ test("device detail page and tab navigation", async ({ page }) => {
7874
expect(page.url()).toMatch(/\/devices\/.*\/.*\/state/);
7975

8076
// Verify device name is displayed in the breadcrumb
81-
const breadcrumbDeviceName = await page.locator(
82-
".breadcrumbs > ul > li:nth-child(2) > a",
83-
{
84-
hasText: TEST_DEVICE_NAME,
85-
},
86-
);
77+
const breadcrumbDeviceName = await page.getByRole("link", { name: TEST_DEVICE_NAME });
8778
await expect(breadcrumbDeviceName).toBeVisible();
8879

8980
// Check for API and network links
@@ -93,11 +84,11 @@ test("device detail page and tab navigation", async ({ page }) => {
9384
await expect(networkLink).toBeVisible();
9485

9586
// Check for status badge
96-
const onlineBadge = await page.locator('.badge:has-text("online")');
87+
const onlineBadge = await page.getByText("online", { exact: true });
9788
await expect(onlineBadge).toBeVisible();
9889

9990
// Check for navigation tabs
100-
const stateTabs = page.locator(".tabs");
91+
const stateTabs = page.getByRole("tablist");
10192
await expect(stateTabs).toBeVisible();
10293

10394
// Verify all tabs are present

app/integration/setup.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ test("verify: mock database is working", async ({ page }) => {
1313
await page.goto("/devices/list", { waitUntil: "load" });
1414

1515
// Verify our test device is in the table
16-
const deviceLink = await page.locator("table td a", {
17-
hasText: TEST_DEVICE_NAME,
18-
});
16+
const deviceLink = await page.getByRole("link", { name: TEST_DEVICE_NAME });
1917
await expect(deviceLink).toBeVisible();
2018
});

0 commit comments

Comments
 (0)