Files
pleno-vue/tests/e2e/edge-gateways.routes.spec.js
T
Jeppe Bundgaard 6c4b9cb599 Add and improve e2e tests for Edge Gateway flows and configure pre-commit hooks:
- Introduced live smoke tests for Edge Gateways, verifying gateway routes and destructive-action prevention.
- Added e2e scenarios for deep-link navigation, unavailable gateway recovery, token rotation, and background page refresh.
- Refactored test helpers for streamlined functional validation in gateway scenarios.
- Updated `EdgeGatewayTerminal.vue` with test IDs for enhanced testability.
- Added and configured Husky pre-commit hooks for automated test file formatting and validation.
2026-04-16 10:52:56 +02:00

137 lines
5.0 KiB
JavaScript

import { expect, test } from "@playwright/test";
import { mockApi, primeMockSession } from "./support/network.js";
async function primeSuperuserSession(page) {
const token = "superuser-edge-gateway-routes-token";
await primeMockSession(page, { token });
}
async function openFleetRail(page, testInfo) {
if (testInfo.project.name.includes("mobile")) {
await page.getByTestId("gateway-mobile-open-rail").click();
}
}
test.describe("Edge gateway route-aware flows", () => {
test.beforeEach(async ({ page }) => {
await mockApi(page, {
authenticated: true,
permissions: ["superuser", "user"],
});
await primeSuperuserSession(page);
});
test("deep links a canonical gateway page and keeps browser history between gateway selections", async ({
page,
}, testInfo) => {
await page.goto("/superuser/gateways/701");
await expect(page).toHaveURL(/\/superuser\/gateways\/701$/);
await expect(page.getByTestId("gateway-detail-header")).toContainText("CPH Edge 01");
await openFleetRail(page, testInfo);
await page.getByTestId("gateway-fleet-item-702").click();
await expect(page).toHaveURL(/\/superuser\/gateways\/702$/);
await expect(page.getByTestId("gateway-detail-header")).toContainText("ODE Edge 01");
await page.goBack();
await expect(page).toHaveURL(/\/superuser\/gateways\/701$/);
await expect(page.getByTestId("gateway-detail-header")).toContainText("CPH Edge 01");
await page.goForward();
await expect(page).toHaveURL(/\/superuser\/gateways\/702$/);
await expect(page.getByTestId("gateway-detail-header")).toContainText("ODE Edge 01");
});
test("shows an unavailable detail state for an unknown canonical gateway id and recovers by selecting a valid gateway", async ({
page,
}, testInfo) => {
await page.goto("/superuser/gateways/999999");
await expect(page).toHaveURL(/\/superuser\/gateways\/999999$/);
await expect(page.getByTestId("gateway-unavailable-state")).toContainText("Gatewayen er ikke tilgængelig");
await openFleetRail(page, testInfo);
await page.getByTestId("gateway-fleet-item-701").click();
await expect(page).toHaveURL(/\/superuser\/gateways\/701$/);
await expect(page.getByTestId("gateway-detail-header")).toContainText("CPH Edge 01");
});
test("reveals and copies the rotated agent token after an explicit confirmation step", async ({ page }) => {
await page.goto("/superuser/gateways/701");
await page.getByTestId("gateway-rotate-credentials").click();
await expect(page.getByTestId("gateway-rotation-confirmation")).toBeVisible();
await page.getByTestId("gateway-rotation-confirm").click();
await expect(page.getByTestId("gateway-rotation-result")).toBeVisible();
await expect(page.getByTestId("gateway-rotation-token")).toHaveValue("rotated-token-701");
await page.evaluate(() => {
window.__copiedGatewayToken = "";
Object.defineProperty(navigator, "clipboard", {
configurable: true,
value: {
writeText: async (value) => {
window.__copiedGatewayToken = value;
},
},
});
});
await page.getByTestId("gateway-rotation-copy").click();
await expect.poll(() => page.evaluate(() => window.__copiedGatewayToken)).toBe("rotated-token-701");
});
test("links the department-scoped gateway manager into the canonical gateway detail page", async ({ page }) => {
await page.goto("/superuser/departments/1/gateways");
await expect(page).toHaveURL(/\/superuser\/departments\/1\/gateways$/);
await expect(page.getByTestId("gateway-open-full-page")).toBeVisible();
await page.getByTestId("gateway-open-full-page").click();
await expect(page).toHaveURL(/\/superuser\/gateways\/701$/);
await expect(page.getByTestId("gateway-detail-header")).toContainText("CPH Edge 01");
});
});
test.describe("Edge gateway background refresh", () => {
test("re-fetches page data on an interval without resetting in-progress form edits", async ({ page }) => {
await mockApi(page, {
authenticated: true,
permissions: ["superuser", "user"],
edgeGateways: {
gatewayOverrides: [
{
id: 701,
recent_updates: [{ id: 901, target_version: "1.2.2", status: "PENDING", result: {} }],
},
],
pendingUpdateByGatewayId: {
701: {
jobId: 901,
fetchCount: 0,
targetVersion: "1.2.2",
previousVersion: "1.2.0",
outcome: "COMPLETED",
},
},
},
});
await primeSuperuserSession(page);
await page.goto("/superuser/gateways/701");
const updateTimeline = page.getByTestId("gateway-update-timeline");
const targetVersionField = page.getByLabel("Target-version");
await expect(updateTimeline).toContainText("Afventer");
await targetVersionField.fill("9.9.9");
await expect(updateTimeline).toContainText("Verificerer genstart", {
timeout: 8_000,
});
await expect(targetVersionField).toHaveValue("9.9.9");
});
});