126 lines
4.5 KiB
TypeScript
126 lines
4.5 KiB
TypeScript
import { expect, test, type Page } from "@playwright/test";
|
|
|
|
/**
|
|
* Strategic objectives: a superuser authors a map objective through the REST
|
|
* gate and both surfaces render it (world map and the mission planning map of
|
|
* a mission on the same terrain). Seeds its own map + mission through
|
|
* cookie-authed REST (the e2e dev user carries a superuser role).
|
|
*/
|
|
test.describe("Strategic objectives", () => {
|
|
let mapId: number | null = null;
|
|
let missionId: number | null = null;
|
|
|
|
async function login(page: Page) {
|
|
const res = await page.request.post("/api/users/login", {
|
|
data: { username: "dev", password: "Test123" },
|
|
});
|
|
expect(res.ok(), `login failed: ${res.status()}`).toBe(true);
|
|
}
|
|
|
|
async function createObjective(
|
|
page: Page,
|
|
data: Record<string, unknown>,
|
|
): Promise<{ id: number }> {
|
|
const res = await page.request.post("/api/map-objectives", {
|
|
data: { map: mapId, markerType: "mil_objective", status: "active", ...data },
|
|
});
|
|
expect(res.ok(), await res.text()).toBe(true);
|
|
return (await res.json()).doc as { id: number };
|
|
}
|
|
|
|
test.afterAll(async ({ browser }) => {
|
|
const p = await browser.newPage().catch(() => null);
|
|
if (!p) return;
|
|
await login(p);
|
|
if (missionId) await p.request.delete(`/api/missions/${missionId}`);
|
|
// Objectives are removed by the maps beforeDelete hook.
|
|
if (mapId) await p.request.delete(`/api/maps/${mapId}`);
|
|
await p.close();
|
|
});
|
|
|
|
test("renders on the world map and the mission planning map", async ({ page }) => {
|
|
await login(page);
|
|
await page.addInitScript(() => window.localStorage.setItem("ptf:tours:opted-out", "1"));
|
|
|
|
page.on("console", (msg) => {
|
|
if (msg.type() === "error") console.log("[CONSOLE ERROR]", msg.text());
|
|
});
|
|
page.on("pageerror", (err) => console.log("[PAGE ERROR]", err.message));
|
|
page.on("requestfailed", (req) =>
|
|
console.log("[REQUEST FAILED]", req.url(), req.failure()?.errorText ?? ""),
|
|
);
|
|
|
|
const mapRes = await page.request.post("/api/maps", {
|
|
data: {
|
|
name: "E2E Objective Map",
|
|
worldSizeWidth: 8192,
|
|
worldSizeHeight: 8192,
|
|
basemapMode: "image",
|
|
isActive: true,
|
|
worldMap: true,
|
|
},
|
|
});
|
|
expect(mapRes.ok(), await mapRes.text()).toBe(true);
|
|
mapId = (await mapRes.json()).doc.id;
|
|
|
|
const meRes = await page.request.get("/api/users/me");
|
|
const meId = (await meRes.json()).user.id as number;
|
|
const missionRes = await page.request.post("/api/missions", {
|
|
data: {
|
|
name: "E2E Objective Op",
|
|
codeName: "E2E-OBJ",
|
|
summary: "Objective layer e2e mission",
|
|
operationType: "main",
|
|
classification: {
|
|
map: mapId,
|
|
missionType: "PvE",
|
|
startDateTime: new Date(Date.now() + 3 * 86_400_000).toISOString(),
|
|
estimatedDuration: 60,
|
|
planningMapEnabled: true,
|
|
},
|
|
ownershipAndStatus: { authors: [meId], status: "Scheduled", visibility: "unit" },
|
|
briefing: [],
|
|
gameDetails: { serverDetails: { serverIp: "127.0.0.1", serverPort: 2302 } },
|
|
missionRoles: { maxPlayers: 32, providedRoles: [] },
|
|
},
|
|
});
|
|
expect(missionRes.ok(), await missionRes.text()).toBe(true);
|
|
missionId = (await missionRes.json()).doc.id;
|
|
|
|
// REST create also exercises the superuser write gate.
|
|
await createObjective(page, {
|
|
name: "OBJ ALPHA",
|
|
description: "Take the ridge",
|
|
status: "active",
|
|
position: [4096, 4096],
|
|
});
|
|
await createObjective(page, {
|
|
name: "OBJ BRAVO",
|
|
status: "secured",
|
|
redacted: true,
|
|
position: [3000, 3500],
|
|
});
|
|
|
|
await page.goto(`/map/${mapId}`);
|
|
await expect(page.locator(".objective-marker-name", { hasText: "OBJ ALPHA" })).toBeVisible({
|
|
timeout: 60_000,
|
|
});
|
|
// Superusers see redacted objectives, flagged.
|
|
await expect(
|
|
page.locator(".objective-marker-name", { hasText: "OBJ BRAVO // REDACTED" }),
|
|
).toBeVisible();
|
|
|
|
await page.goto(`/intelligence/missions/${missionId}`);
|
|
const section = page.locator("section[aria-label='Mission planning map']");
|
|
await expect(section).toBeVisible({ timeout: 60_000 });
|
|
await expect(section.locator(".objective-marker-name", { hasText: "OBJ ALPHA" })).toBeVisible({
|
|
timeout: 60_000,
|
|
});
|
|
await expect(
|
|
section.locator(".objective-marker-name", { hasText: "OBJ BRAVO // REDACTED" }),
|
|
).toBeVisible();
|
|
|
|
// The export path is covered by the unit tests; no clipboard in headless.
|
|
await section.screenshot({ path: "test-results/mission-planning-objectives.png" });
|
|
});
|
|
});
|