209 lines
17 KiB
JavaScript
209 lines
17 KiB
JavaScript
import assert from "node:assert/strict";
|
|
|
|
export async function runRaceSetupSmoke({ evaluate, navigate, fill, savedState, waitFor, pause }) {
|
|
const click = id => evaluate(`document.getElementById(${JSON.stringify(id)}).click()`);
|
|
const submit = id => evaluate(`document.getElementById(${JSON.stringify(id)}).requestSubmit()`);
|
|
const findEvent = async name => (await savedState()).events.find(event => event.name === name);
|
|
async function editEvent(event, view, readyForm) {
|
|
await click("event-edit-" + event.id);
|
|
await fill("eventEditForm", { name: event.name + " Updated" });
|
|
await submit("eventEditForm");
|
|
await waitFor(async () => Boolean(await findEvent(event.name + " Updated")), "event name saved");
|
|
await navigate(view, readyForm);
|
|
await click("event-edit-" + event.id);
|
|
assert.equal(await evaluate('document.getElementById("eventEditForm").elements.namedItem("name").value'), event.name + " Updated");
|
|
await click("eventEditCancel");
|
|
await click("event-manage-" + event.id);
|
|
}
|
|
|
|
await navigate("events", "eventForm");
|
|
await fill("eventForm", { name: "Browser Sponsor", date: "2026-09-08", classId: "test_class" });
|
|
await submit("eventForm");
|
|
await waitFor(async () => Boolean(await findEvent("Browser Sponsor")), "create sponsor event");
|
|
const sponsor = await findEvent("Browser Sponsor");
|
|
await editEvent(sponsor, "events", "eventForm");
|
|
await fill("sessionForm", { name: "Sponsor Heat", type: "heat", durationMin: "5", startMode: "mass" });
|
|
await submit("sessionForm");
|
|
await waitFor(async () => (await savedState()).sessions.some(session => session.name === "Sponsor Heat" && session.eventId === sponsor.id), "sponsor session");
|
|
console.log("PASS sponsor-event create/edit/reload and session creation");
|
|
|
|
// Quick setup: two rental cars, three guests -> 2 groups, practice + 2 qualifying rounds,
|
|
// drivers swap cars; guests stay out of the club driver list.
|
|
for (const [name, tp] of [["Hyrbil 1", "990001"], ["Hyrbil 2", "990002"]]) {
|
|
await waitFor(async () => Boolean(await evaluate('Boolean(document.getElementById("sponsorAddCar"))')), "sponsor setup panel");
|
|
await fill("sponsorSetupForm", { newCarName: name, newCarTp: tp });
|
|
await click("sponsorAddCar");
|
|
await waitFor(async () => (await savedState()).cars.some((car) => car.transponder === tp), "rental car " + name);
|
|
}
|
|
await waitFor(async () => Boolean(await evaluate('document.querySelectorAll("#sponsorSetupForm input[name=car]:checked").length === 2')), "both cars ticked");
|
|
await evaluate('document.querySelector("#sponsorSetupForm textarea[name=guests]").value = \"Gäst Anna\\nGäst Bosse\\nGäst Cissi\"');
|
|
await submit("sponsorSetupForm");
|
|
await waitFor(async () => (await savedState()).sessions.filter((session) => session.eventId === sponsor.id && session.carAssignments).length === 6, "sponsor heats");
|
|
{
|
|
const saved = await savedState();
|
|
const guests = saved.drivers.filter((driver) => driver.guestEventId === sponsor.id);
|
|
assert.equal(guests.length, 3);
|
|
const heats = saved.sessions.filter((session) => session.eventId === sponsor.id && session.carAssignments);
|
|
assert.deepEqual(heats.map((session) => session.name).slice(2), ["Q1 H1", "Q1 H2", "Q2 H1", "Q2 H2"]);
|
|
assert.ok(heats[0].name.endsWith(" G1") && heats[1].name.endsWith(" G2") && heats[0].type === "practice", "one practice per group");
|
|
const q1 = heats.find((session) => session.name === "Q1 H1");
|
|
const q2 = heats.find((session) => session.name === "Q2 H1");
|
|
assert.notEqual(q1.carAssignments[q1.driverIds[0]], q2.carAssignments[q2.driverIds[0]], "drivers swap cars between rounds");
|
|
await navigate("drivers", "driverForm");
|
|
assert.equal(await evaluate('document.getElementById("view").textContent.includes("Gäst Anna")'), false, "guests not in the driver list");
|
|
await navigate("events", "eventForm");
|
|
await click("event-manage-" + sponsor.id);
|
|
}
|
|
console.log("PASS sponsor quick setup: guests, rental cars, rotating heats");
|
|
|
|
await navigate("race_setup", "raceWizardStepForm");
|
|
await fill("raceWizardStepForm", { name: "Browser Endurance", date: "2026-09-08", classId: "test_class", presetId: "endurance" });
|
|
await click("raceWizardNext");
|
|
await click("wizardSelectAllParticipants");
|
|
await click("raceWizardNext");
|
|
await evaluate('document.querySelector("#raceWizardPlanForm [name=createTeamRace]").checked = true');
|
|
await fill("raceWizardPlanForm", { teamRaceDurationMin: "45" });
|
|
await click("raceWizardNext");
|
|
await click("raceWizardCreate");
|
|
await waitFor(async () => Boolean(await findEvent("Browser Endurance")), "wizard race creation");
|
|
const race = await findEvent("Browser Endurance");
|
|
// A wizard race with practice + qualifying: the qualifying is real heats (Q<round> H<heat>,
|
|
// generated), so "Create qualifying from practice" later replaces them instead of adding more.
|
|
await navigate("race_setup", "raceWizardStepForm");
|
|
await fill("raceWizardStepForm", { name: "Browser Club Race", date: "2026-09-08", classId: "test_class", presetId: "club_qualifying" });
|
|
await click("raceWizardNext");
|
|
await click("wizardSelectAllParticipants");
|
|
await click("raceWizardNext");
|
|
await evaluate('(() => { const form = document.getElementById("raceWizardPlanForm"); form.elements.createPractice.checked = true; form.elements.createQualifying.checked = true; form.elements.createPractice.dispatchEvent(new Event("change", { bubbles: true })); form.elements.createQualifying.dispatchEvent(new Event("change", { bubbles: true })); })()');
|
|
await fill("raceWizardPlanForm", { practiceSessions: "1", qualifyingRounds: "2" });
|
|
await click("raceWizardNext");
|
|
await click("raceWizardCreate");
|
|
await waitFor(async () => Boolean(await findEvent("Browser Club Race")), "wizard club race creation");
|
|
{
|
|
const club = await findEvent("Browser Club Race");
|
|
const clubSessions = (await savedState()).sessions.filter((session) => session.eventId === club.id);
|
|
const quals = clubSessions.filter((session) => session.type === "qualification");
|
|
const practices = clubSessions.filter((session) => session.type === "practice");
|
|
assert.ok(practices.length >= 1 && practices.every((session) => session.driverIds.length <= club.raceConfig.carsPerHeat), `practice split by cars per heat: ${practices.map((session) => session.name + ":" + session.driverIds.length)}`);
|
|
assert.ok(quals.length >= 2 && quals.every((session) => /^Q[12] H\d+$/.test(session.name) && session.generated), `qualifying heats per round: ${quals.map((session) => session.name)}`);
|
|
assert.equal(club.raceConfig.qualifyingRounds, 2);
|
|
console.log("PASS wizard builds qualifying as Q<round> H<heat> heats");
|
|
// A driver left out can be ticked again, and the heats not run yet follow the list.
|
|
await click("event-manage-" + club.id);
|
|
await waitFor(async () => (await evaluate('document.querySelectorAll(".race-participant").length')) > 0, "participant list");
|
|
const first = await evaluate('document.querySelector(".race-participant:checked").value');
|
|
await evaluate(`document.querySelector('.race-participant[value="${first}"]').click()`);
|
|
await waitFor(async () => !(await savedState()).sessions.some((session) => session.eventId === club.id && session.type === "qualification" && session.driverIds.includes(first)), "unticked driver leaves the heats");
|
|
await waitFor(async () => Boolean(await evaluate(`Boolean(document.querySelector('.race-participant[value="${first}"]:not(:checked)'))`)), "unticked driver still listed");
|
|
await evaluate(`document.querySelector('.race-participant[value="${first}"]').click()`);
|
|
await waitFor(async () => (await savedState()).sessions.some((session) => session.eventId === club.id && session.type === "qualification" && session.driverIds.includes(first)), "ticked again: back in a heat");
|
|
console.log("PASS race participants can be changed after creation and the heats follow");
|
|
// Format: changing cars per heat / rounds rebuilds the qualifying heats that have not run.
|
|
const qualCount = async () => (await savedState()).sessions.filter((session) => session.eventId === club.id && session.type === "qualification").length;
|
|
const before = await qualCount();
|
|
await fill("raceFormatForm", { qualifyingRounds: "3", carsPerHeat: "2" });
|
|
await submit("raceFormatForm");
|
|
await waitFor(async () => (await savedState()).sessions.some((session) => session.eventId === club.id && session.name === "Q3 H1"), "a third round after the format change");
|
|
const heats = (await savedState()).sessions.filter((session) => session.eventId === club.id && session.type === "qualification");
|
|
assert.ok(heats.length > before && heats.every((session) => session.driverIds.length <= 2), `heats rebuilt with max 2 cars: ${heats.map((session) => session.name + ":" + session.driverIds.length)}`);
|
|
const practiceHeats = (await savedState()).sessions.filter((session) => session.eventId === club.id && session.type === "practice");
|
|
assert.ok(practiceHeats.every((session) => session.driverIds.length <= 2), `practice heats rebuilt with max 2 cars: ${practiceHeats.map((session) => session.name + ":" + session.driverIds.length)}`);
|
|
console.log("PASS format change rebuilds the practice and qualifying heats (cars per heat, rounds)");
|
|
// "Qualifying starts at": saved per class on the day plan, and cleared again.
|
|
await waitFor(async () => Boolean(await evaluate('Boolean(document.getElementById("qualStartForm"))')), "qualifying start form");
|
|
await fill("qualStartForm", { qualStart: "13:30" });
|
|
await submit("qualStartForm");
|
|
const expectedAt = new Date("2026-09-08T13:30:00").getTime();
|
|
await waitFor(async () => ((await savedState()).raceDays || []).some((day) => day.date === "2026-09-08" && day.qualStartAt?.[club.id] === expectedAt), "qualifying start saved");
|
|
await waitFor(async () => Boolean(await evaluate('Boolean(document.getElementById("qualStartClear"))')), "clear button");
|
|
await click("qualStartClear");
|
|
await waitFor(async () => !((await savedState()).raceDays || []).some((day) => day.date === "2026-09-08" && day.qualStartAt?.[club.id]), "qualifying start cleared");
|
|
console.log("PASS qualifying start time is saved per class and cleared");
|
|
}
|
|
await navigate("race_setup", "raceWizardStepForm");
|
|
await editEvent(race, "race_setup", "raceWizardStepForm");
|
|
const current = await savedState();
|
|
const driver = current.drivers.find(item => item.name === "Browser Driver Updated");
|
|
const car = current.cars.find(item => item.name === "Browser Car Updated");
|
|
const raceState = () => findEvent("Browser Endurance Updated");
|
|
const setValue = (selector, value) => evaluate(`(() => { const node = document.querySelector(${JSON.stringify(selector)}); node.value = ${JSON.stringify(value)}; node.dispatchEvent(new Event("change", { bubbles: true })); })()`);
|
|
await waitFor(async () => await evaluate(`Boolean(document.getElementById("teamSetupAdd"))`), "team race setup");
|
|
await click("teamSetupAdd");
|
|
await waitFor(async () => ((await raceState()).raceConfig.teams || []).length === 1, "team create");
|
|
const team = (await raceState()).raceConfig.teams[0];
|
|
await setValue(`[data-team-name="${team.id}"]`, "Browser Team Updated");
|
|
await waitFor(async () => (await raceState()).raceConfig.teams.some(item => item.name === "Browser Team Updated"), "team rename");
|
|
await setValue(`[data-team-add="${team.id}"]`, driver.id);
|
|
await waitFor(async () => (await raceState()).raceConfig.teams[0].driverIds.includes(driver.id), "team driver");
|
|
await setValue(`[data-team-car="${team.id}"]`, car.id);
|
|
await waitFor(async () => (await raceState()).raceConfig.teams.some(item => item.name === "Browser Team Updated" && item.carIds.includes(car.id) && item.driverIds.includes(driver.id)), "team membership update");
|
|
await navigate("race_setup", "raceWizardStepForm");
|
|
await click("event-manage-" + race.id);
|
|
await waitFor(async () => (await evaluate(`document.querySelector('[data-team-name="${team.id}"]')?.value || ""`)) === "Browser Team Updated", "team kept after reopening");
|
|
assert.equal(await evaluate(`document.querySelector('[data-team-car="${team.id}"]').value`), car.id);
|
|
|
|
await fill("sessionForm", { name: "Editable Practice", type: "open_practice", durationMin: "5" });
|
|
await submit("sessionForm");
|
|
await waitFor(async () => (await savedState()).sessions.some(session => session.name === "Editable Practice"), "practice create");
|
|
const session = (await savedState()).sessions.find(item => item.name === "Editable Practice");
|
|
await click("session-edit-" + session.id);
|
|
await fill("sessionEditForm", { name: "Edited Team Session", type: "team_race", durationMin: "45", followUpSec: "30" });
|
|
await submit("sessionEditForm");
|
|
await waitFor(async () => (await savedState()).sessions.some(item => item.id === session.id && item.type === "team_race" && item.durationMin === 45 && item.followUpSec === 30), "session edit type and duration");
|
|
await fill("raceFormatForm", { minLapSec: "30", maxLapSec: "120" });
|
|
await submit("raceFormatForm");
|
|
await waitFor(async () => (await raceState()).raceConfig.minLapMs === 30000 && (await raceState()).raceConfig.maxLapMs === 120000, "lap limits saved");
|
|
await navigate("race_setup", "raceWizardStepForm");
|
|
await click("event-manage-" + race.id);
|
|
await click("session-edit-" + session.id);
|
|
assert.equal(await evaluate('document.getElementById("sessionEditForm").elements.namedItem("type").value'), "team_race");
|
|
await click("sessionEditCancel");
|
|
assert.equal(await evaluate('document.getElementById("raceFormatForm").elements.namedItem("minLapSec").value'), "30.0");
|
|
await evaluate(`document.querySelector('[data-team-delete="${team.id}"]').click()`);
|
|
await waitFor(async () => !(await raceState()).raceConfig.teams.some(item => item.id === team.id), "team deletion");
|
|
console.log("PASS race wizard/edit/reload, team create/member-edit/delete, session type/duration and lap limits");
|
|
|
|
// Running order: the sessions are listed in it, and ▲ moves one earlier.
|
|
for (const name of ["Q1 H2", "Q1 H1"]) {
|
|
await fill("sessionForm", { name, type: "qualification", durationMin: "5" });
|
|
await submit("sessionForm");
|
|
await waitFor(async () => (await savedState()).sessions.some((item) => item.name === name && item.eventId === race.id), name + " created");
|
|
}
|
|
const listed = async () => evaluate(`[...document.querySelectorAll("[data-session-move][data-step='1']")].map((button) => button.dataset.sessionMove)`);
|
|
const sessionNames = async () => {
|
|
const ids = await listed();
|
|
const all = (await savedState()).sessions;
|
|
return ids.map((id) => all.find((item) => item.id === id)?.name).filter((name) => /^Q1/.test(name));
|
|
};
|
|
await waitFor(async () => (await sessionNames()).join() === "Q1 H1,Q1 H2", "listed in running order although Q1 H1 was made last");
|
|
const q12 = (await savedState()).sessions.find((item) => item.name === "Q1 H2" && item.eventId === race.id);
|
|
await evaluate(`document.querySelector('[data-session-move="${q12.id}"][data-step="-1"]').click()`);
|
|
await waitFor(async () => (await sessionNames()).join() === "Q1 H2,Q1 H1", "Q1 H2 moved up");
|
|
const q11 = (await savedState()).sessions.find((item) => item.name === "Q1 H1" && item.eventId === race.id);
|
|
await waitFor(async () => {
|
|
const order = (await raceState()).sessionOrder || [];
|
|
return order.includes(q12.id) && order.indexOf(q12.id) < order.indexOf(q11.id);
|
|
}, "the order is saved on the race");
|
|
console.log("PASS Race Setup lists sessions in running order and ▲▼ change it");
|
|
|
|
// The race list: races from past dates are folded away under Done; search finds them.
|
|
await navigate("race_setup", "raceWizardStepForm");
|
|
const raceId = (await raceState()).id;
|
|
assert.equal(await evaluate(`document.querySelector('[data-event-row="${raceId}"]').closest("details")?.id || ""`), "eventListDone", "a race from a past date is under Done");
|
|
assert.equal(await evaluate(`document.getElementById("eventListDone").open`), false, "Done is folded by default");
|
|
if (await evaluate(`Boolean(document.getElementById("eventListSearch"))`)) {
|
|
await evaluate(`(() => { const box = document.getElementById("eventListSearch"); box.value = "endurance"; box.dispatchEvent(new Event("input")); })()`);
|
|
assert.equal(await evaluate(`document.getElementById("eventListDone").open`), true, "search opens Done");
|
|
assert.equal(await evaluate(`document.querySelector('[data-event-row="${raceId}"]').hidden`), false);
|
|
assert.ok(await evaluate(`[...document.querySelectorAll("[data-event-row]")].some((row) => row.hidden)`), "other races are filtered out");
|
|
}
|
|
console.log("PASS Race Setup groups races into today, upcoming and a folded Done list, with search");
|
|
|
|
// Manage: sessions grouped per step; print/export/delete live in the ⋯ menu.
|
|
await click("event-manage-" + raceId);
|
|
await waitFor(async () => Boolean(await evaluate(`document.querySelector('details[data-session-group="qual_1"]')`)), "qualifying round 1 is its own group");
|
|
assert.equal(await evaluate(`document.querySelector('details[data-session-group="qual_1"]').open`), true, "a step not yet run is open");
|
|
assert.equal(await evaluate(`Boolean(document.getElementById("session-delete-${q11.id}").closest("details.row-menu"))`), true, "delete is in the ⋯ menu");
|
|
console.log("PASS Manage groups sessions per step with the rarer actions in a ⋯ menu");
|
|
}
|