mirror of
https://github.com/ipnet-mesh/meshcore-hub.git
synced 2026-08-06 17:02:59 +02:00
94dd4c9b42
Replaces the httpx-based smoke tests in tests/e2e/ with a browser E2E suite
under e2e/, running against a self-contained throwaway stack that never
touches the local development database.
Stack & data isolation (e2e/docker-compose.test.yml):
- Own ephemeral Postgres 17 (schema via the `migrate` service / Alembic),
distinct project name + named volumes, no host DB port, no \${VAR}
interpolation. `make e2e-down` destroys everything.
- OIDC enabled with a known session secret; WEB_AUTO_REFRESH_SECONDS=2 so
polling is assertable; CONTENT_HOME mounts a test markdown page.
- Deterministic seeder (e2e/seed_data.py) run via global setup inside the
collector container: nodes/observers with `area` tags, adverts, messages
on the public (17) + a custom channel, raw packets + path hops keyed to
node prefixes, a route + health/history, profiles + adoptions, and
event_observers rows so the observer filter/badges resolve.
Auth & tests:
- Forged signed `meshcore-session` cookies (e2e/mint_session.py,
itsdangerous) for admin/member identities -> storageState; no real IdP
needed. 31 specs across 12 files cover global nav/theme, profile
menu+edit, home hero, dashboard widgets, list filters/auto-refresh/row
actions, observer toggles, the path-node overlay, map filters +
show-labels, members, markdown pages, and routes add/edit/delete
(persistence, validation, confirm dialog). workers:1 / fullyParallel:false
against the single shared backend; targeted data-testids added to React
components for stable selectors.
Fixes surfaced while running the suite on fresh Postgres:
- Migration 5e3b712ccf10 aborted on Postgres: its route-health backfill
queries the live Route model (which now has max_path_length) before that
column exists. The swallowed error left the transaction aborted, killing
the subsequent alembic_version stamp. Wrapped the backfill in a SAVEPOINT
so a failure rolls back cleanly without blocking the migration.
- Restored the full ABUSE_* env set required by the MQTT broker, and set
the web service's API_KEY to the admin key (admin writes go through the
proxy as a Bearer token).
31/31 passing; tsc (frontend+e2e), pytest (1460), and pre-commit green.
92 lines
3.6 KiB
TypeScript
92 lines
3.6 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import { countApiCalls, expectListLoaded, openFilters } from "../utils/helpers";
|
|
|
|
const ALPHA_KEY = "a1fa" + "0".repeat(60);
|
|
|
|
test.use({ permissions: ["clipboard-read", "clipboard-write"] });
|
|
|
|
test.describe("advertisements", () => {
|
|
test("filter options work", async ({ page }) => {
|
|
await page.goto("/advertisements");
|
|
await expectListLoaded(page);
|
|
const table = page.locator("table");
|
|
|
|
await openFilters(page);
|
|
await page.locator('select[name="route_type"]').selectOption("all");
|
|
await page.getByRole("button", { name: "Filter" }).click();
|
|
await expect(page).toHaveURL(/route_type=all/);
|
|
await expect(table.getByText("Charlie Node").first()).toBeVisible();
|
|
|
|
await openFilters(page);
|
|
await page.locator('input[name="search"]').fill("Bravo");
|
|
await page.getByRole("button", { name: "Filter" }).click();
|
|
await expect(page).toHaveURL(/search=Bravo/);
|
|
// Two Bravo adverts (one per area); toHaveCount auto-waits out the refetch.
|
|
await expect(page.getByTestId("list-row")).toHaveCount(2);
|
|
await expect(table.getByText("Alpha Node")).toHaveCount(0);
|
|
});
|
|
|
|
test("auto-refresh works and can be paused", async ({ page }) => {
|
|
await page.goto("/advertisements");
|
|
await expectListLoaded(page);
|
|
|
|
const toggle = page.getByTestId("auto-refresh-toggle");
|
|
await expect(toggle).toBeChecked();
|
|
|
|
const active = await countApiCalls(page, "/api/v1/advertisements?", 5000);
|
|
expect(active).toBeGreaterThanOrEqual(2);
|
|
|
|
await toggle.click();
|
|
await expect(toggle).not.toBeChecked();
|
|
const paused = await countApiCalls(page, "/api/v1/advertisements?", 4500);
|
|
expect(paused).toBe(0);
|
|
});
|
|
|
|
test("table row actions work", async ({ page }) => {
|
|
await page.goto("/advertisements");
|
|
await expectListLoaded(page);
|
|
const table = page.locator("table");
|
|
|
|
await table.getByRole("link", { name: "Alpha Node" }).first().click();
|
|
await expect(page).toHaveURL(new RegExp(`/nodes/${ALPHA_KEY}`));
|
|
await page.goBack();
|
|
await expectListLoaded(page);
|
|
|
|
// Click a plain-text cell (Time): node links and copyable keys
|
|
// stopPropagation / have their own handlers.
|
|
await page.getByTestId("list-row").first().locator("td").nth(3).click();
|
|
await expect(page).toHaveURL(/\/packets\/hash\//);
|
|
|
|
await page.goto("/advertisements");
|
|
await expectListLoaded(page);
|
|
const copyable = table.locator('code[title="Click to copy"]').first();
|
|
await copyable.click();
|
|
await expect(page.getByText("Copied!").first()).toBeVisible();
|
|
});
|
|
|
|
test("observer toggles filter the list", async ({ page }) => {
|
|
await page.goto("/advertisements");
|
|
await expectListLoaded(page);
|
|
|
|
const north = page.locator('[data-testid="observer-area"][data-area="North"]');
|
|
const south = page.locator('[data-testid="observer-area"][data-area="South"]');
|
|
await expect(north.first()).toBeVisible();
|
|
await expect(south.first()).toBeVisible();
|
|
await expect(page.getByTestId("list-row")).toHaveCount(5);
|
|
|
|
await north.first().click();
|
|
await expect(north.first()).toHaveClass(/badge-ghost/);
|
|
await expect(page.getByTestId("list-row")).toHaveCount(3);
|
|
|
|
await north.first().click();
|
|
await expect(north.first()).toHaveClass(/badge-primary/);
|
|
await expect(page.getByTestId("list-row")).toHaveCount(5);
|
|
|
|
await south.first().click();
|
|
await expect(page.getByTestId("list-row")).toHaveCount(2);
|
|
await north.first().click();
|
|
await expect(north.first()).toHaveClass(/badge-primary/);
|
|
await expect(page.getByTestId("list-row")).toHaveCount(2);
|
|
});
|
|
});
|