import assert from "node:assert/strict"; // Rookie class in a series: the Rookie round offers drivers from other classes (2WD and 4WD // mixed) without registering them again, and a ticked rookie stays on the round's list. export async function runSeriesRookieSmoke({ evaluate, navigate, savedState, waitFor, base }) { const seeded = await savedState(); const round = { id: "rk_round", name: "RK Cup #1 Rookie", date: "2026-03-01", classId: "rk_rookie", mode: "race", raceConfig: {} }; await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...seeded, classes: [...seeded.classes, { id: "rk_rookie", name: "RK Rookie" }, { id: "rk_2wd", name: "RK 2WD" }, { id: "rk_4wd", name: "RK 4WD" }], drivers: [...seeded.drivers, { id: "rk_ada", name: "RK Ada", classId: "rk_2wd", transponder: "8670001" }, { id: "rk_ben", name: "RK Ben", classId: "rk_4wd", transponder: "8670002" }], events: [...seeded.events, round], series: [...(seeded.series || []), { id: "rk_series", name: "RK Cup", classIds: ["rk_rookie"], eventIds: [round.id] }], }) }); const driverIds = async () => (await savedState()).events.find((event) => event.id === round.id).raceConfig.driverIds || []; await navigate("series", "seriesNew"); await evaluate(`document.querySelector('[data-series-select="rk_series"]')?.click()`); await waitFor(async () => evaluate(`Boolean(document.querySelector('tr[data-round="rk_round"]'))`), "the Rookie round is listed"); await evaluate(`document.querySelector('tr[data-round="rk_round"] [data-round-action="toggle"]').click()`); // Grouped by class: the Rookie class (empty) first, then each driver under their own class. await waitFor(async () => evaluate(`Boolean(document.querySelector('[data-round-participants] [data-picker-group="rk_rookie"].is-primary'))`), "the Rookie class is offered first (it has no drivers)"); assert.match(await evaluate(`document.querySelector("[data-round-participants]").textContent`), /RK 2WD[\s\S]*RK Ada[\s\S]*RK 4WD[\s\S]*RK Ben/, "each driver under their own class"); // "All" on one class, a single tick in the other. await evaluate(`document.querySelector('[data-round-participants] [data-picker-group="rk_2wd"] [data-picker-group-all]').click()`); await waitFor(async () => (await driverIds()).includes("rk_ada"), "All on RK 2WD ticks Ada for the Rookie round"); await evaluate(`(() => { const box = document.querySelector('[data-round-participants] [data-round-driver="rk_ben"]'); box.checked = true; box.dispatchEvent(new Event("change")); })()`); await waitFor(async () => (await driverIds()).includes("rk_ben"), "Ben ticked for the Rookie round"); const state = await savedState(); assert.deepEqual(state.drivers.filter((driver) => /^RK (Ada|Ben)$/.test(driver.name)).map((driver) => driver.id).sort(), ["rk_ada", "rk_ben"], "no driver registered again"); await waitFor(async () => evaluate(`Boolean(document.querySelector('[data-round-participants] [data-picker-group="rk_4wd"][open] [data-round-driver="rk_ben"]:checked'))`), "a class with a ticked rookie stays open"); // Select all takes only the Rookie class itself (none), never the whole club. await evaluate(`document.querySelector('[data-round-participants] [data-picker-none]').click()`); await waitFor(async () => (await driverIds()).length === 0, "Clear empties the round"); await evaluate(`document.querySelector('[data-round-participants] [data-picker-all]').click()`); await new Promise((resolve) => setTimeout(resolve, 600)); assert.equal((await driverIds()).length, 0, "Select all on an empty Rookie class ticks nobody from the other classes"); console.log("PASS a Rookie round in a series takes 2WD and 4WD drivers from their own classes without registering them again"); }