import { expect, test, type Page } from "@playwright/test"; /** * Attendance unlock timeline: a mission with two tiers renders the reached tier * in its accent and the unreached one muted with a TO GO tag. Lowering the * confirmed count re-dims both on the next load. * * Seeding note: attendance rows are created through REST for the signed-in dev * account. The timeline counts rows responding "yes" (that is what * getMissionAttendance summarises), so repeated rows are a valid fixture and * avoid provisioning a squad of users per run. */ test.describe("Mission attendance unlocks", () => { let mapId: number | null = null; let missionId: number | null = null; let meId: number | null = null; const attendanceIds: number[] = []; 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); } test.afterAll(async ({ browser }) => { const page = await browser.newPage(); await login(page); for (const id of attendanceIds) { await page.request.delete(`/api/mission-attendances/${id}`); } if (missionId) await page.request.delete(`/api/missions/${missionId}`); if (mapId) await page.request.delete(`/api/maps/${mapId}`); await page.close(); }); test("lights reached tiers and dims the rest, then re-dims after attendance drops", async ({ page, }) => { await page.setViewportSize({ width: 1440, height: 1000 }); await login(page); // Tours would overlay the page; opt this browser out before any page runs. await page.addInitScript(() => window.localStorage.setItem("ptf:tours:opted-out", "1")); const mapRes = await page.request.post("/api/maps", { data: { name: "E2E Attendance Unlocks Map", worldSizeWidth: 8192, worldSizeHeight: 8192, basemapMode: "image", isActive: true, }, }); expect(mapRes.ok(), await mapRes.text()).toBe(true); mapId = (await mapRes.json()).doc.id; const meRes = await page.request.get("/api/users/me"); meId = (await meRes.json()).user.id as number; const missionRes = await page.request.post("/api/missions", { data: { name: "E2E Attendance Unlocks", codeName: "E2E-UNLOCK", summary: "Attendance unlock timeline e2e mission", operationType: "main", classification: { map: mapId, missionType: "PvE", startDateTime: new Date(Date.now() + 3 * 86_400_000).toISOString(), estimatedDuration: 90, }, ownershipAndStatus: { authors: [meId], status: "Scheduled", visibility: "unit" }, missionRoles: { maxPlayers: 12, providedRoles: [] }, gameDetails: { serverDetails: { serverIp: "127.0.0.1", serverPort: 2302 } }, briefing: [], attendanceUnlocks: [ { threshold: 6, title: "Armor Support", description: "Gain access to an M1A1 for the operation.", accentColor: "#f59e0b", }, { threshold: 8, title: "Air Support", description: "Call in a rotary gunship.", accentColor: "#22d3ee", }, ], }, }); expect(missionRes.ok(), await missionRes.text()).toBe(true); missionId = (await missionRes.json()).doc.id; const addYes = async (count: number) => { for (let index = 0; index < count; index += 1) { const res = await page.request.post("/api/mission-attendances", { data: { mission: missionId, user: meId, response: "yes" }, }); expect(res.ok(), await res.text()).toBe(true); attendanceIds.push((await res.json()).doc.id); } }; await addYes(6); await page.goto(`/intelligence/missions/${missionId}`); const card = page.locator('[data-testid="attendance-unlocks"]:visible').first(); await expect(card).toBeVisible(); const unlocked = card.getByTestId("attendance-unlock-tier-6"); const locked = card.getByTestId("attendance-unlock-tier-8"); await expect(unlocked).toHaveAttribute("data-unlocked", "true"); await expect(unlocked).toContainText("Armor Support"); await expect(unlocked).toContainText("Unlocked"); // The accent is applied inline, so the computed colour is exact. await expect(unlocked.locator("p").first()).toHaveCSS("color", "rgb(245, 158, 11)"); await expect(locked).toHaveAttribute("data-unlocked", "false"); await expect(locked).toContainText("Air Support"); await expect(locked).toContainText("2 to go"); await expect(locked.locator("p").first()).not.toHaveCSS("color", "rgb(245, 158, 11)"); // Drop below the first threshold: both tiers dim. const removed = attendanceIds.pop(); expect(removed).toBeTruthy(); const deleteRes = await page.request.delete(`/api/mission-attendances/${removed}`); expect(deleteRes.ok(), await deleteRes.text()).toBe(true); await page.reload(); const reloaded = page.locator('[data-testid="attendance-unlocks"]:visible').first(); await expect(reloaded).toBeVisible(); await expect(reloaded.getByTestId("attendance-unlock-tier-6")).toHaveAttribute( "data-unlocked", "false", ); await expect(reloaded.getByTestId("attendance-unlock-tier-6")).toContainText("1 to go"); await expect(reloaded.getByTestId("attendance-unlock-tier-8")).toContainText("3 to go"); await expect(reloaded.getByTestId("attendance-unlock-tier-6")).not.toContainText("Unlocked"); }); });