feat(houseofrc): create a race from a House of RC event and its entries (1.80.0)
This commit is contained in:
1 parent
42df6a786f
commit
9c1f5713e6
18 files changed
+444
-21
No files matched your search
@@ -64,3 +64,61 @@ export async function runHouseOfRcSmoke({ evaluate, navigate, savedState, waitFo
|
||||
await patchState({ drivers: current.drivers.filter((driver) => !driver.id.startsWith("hor_")) });
|
||||
}
|
||||
}
|
||||
|
||||
// Race wizard → "Fetch from House of RC": pick an event, choose our class, the entered drivers
|
||||
// fill the wizard; the created event remembers the House of RC event for the results later.
|
||||
export async function runHouseOfRcEventSmoke({ evaluate, navigate, savedState, waitFor, base }) {
|
||||
try {
|
||||
await navigate("race_setup", "raceWizardStepForm");
|
||||
await evaluate(`(() => {
|
||||
const realFetch = window.fetch;
|
||||
window.fetch = async (url, options) => {
|
||||
const json = (data) => new Response(JSON.stringify(data), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
if (String(url).includes("/api/houseofrc/events")) return json({ ok: true, events: [{ id: 2251, name: "HoR Deltävling 2", start: "2026-12-05T07:00:00Z", city: "Sundsvall", country: "SE", url: "https://houseofrc.com/events/2251" }] });
|
||||
if (String(url).includes("/api/houseofrc/entries")) return json({ ok: true, event: { id: 2251, name: "HoR Deltävling 2", start: "2026-12-05T07:00:00Z", city: "Sundsvall", url: "https://houseofrc.com/events/2251" }, entries: [
|
||||
{ houseOfRcId: 901, name: "HoR Anna", number: 7, club: "Sundsvall RC", car: "XRAY X12" },
|
||||
{ houseOfRcId: 902, name: "HoR Bo", number: null, club: "", car: "" },
|
||||
{ houseOfRcId: 903, name: "HoR Skipped", number: null, club: "", car: "" },
|
||||
] });
|
||||
return realFetch(url, options);
|
||||
};
|
||||
})()`);
|
||||
await evaluate(`document.getElementById("raceWizardHouseOfRc").click()`);
|
||||
await waitFor(async () => evaluate(`Boolean(document.querySelector("[data-hor-event]"))`), "the event list");
|
||||
await evaluate(`document.querySelector('[data-hor-event="2251"]').click()`);
|
||||
await waitFor(async () => evaluate(`Boolean(document.querySelector("[data-hor-apply]"))`), "the entries");
|
||||
const statuses = await evaluate(`[...document.querySelectorAll("#houseOfRcEventOverlay tbody .pill")].map((pill) => pill.textContent.trim())`);
|
||||
assert.equal(statuses.length, 3);
|
||||
await evaluate(`(() => {
|
||||
const select = document.querySelector("[data-hor-class]");
|
||||
select.value = "test_class"; select.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
})()`);
|
||||
await evaluate(`(() => { document.querySelector('[data-hor-entry="2"]').checked = false; document.querySelector("[data-hor-apply]").click(); })()`);
|
||||
await waitFor(async () => (await savedState()).drivers.some((driver) => driver.name === "HoR Anna"), "new drivers saved");
|
||||
const drivers = (await savedState()).drivers;
|
||||
const anna = drivers.find((driver) => driver.name === "HoR Anna");
|
||||
assert.deepEqual([anna.classId, anna.club, anna.brand, anna.houseOfRcId], ["test_class", "Sundsvall RC", "XRAY X12", "901"]);
|
||||
assert.equal(drivers.some((driver) => driver.name === "HoR Skipped"), false, "an unticked entry is not created");
|
||||
const ticked = await evaluate(`[...document.querySelectorAll(".wizard-participant:checked")].map((box) => box.value)`);
|
||||
const ids = drivers.filter((driver) => ["HoR Anna", "HoR Bo"].includes(driver.name)).map((driver) => driver.id);
|
||||
assert.deepEqual([...ticked].sort(), [...ids].sort(), "the wizard is on Participants with exactly the entered drivers");
|
||||
await evaluate(`document.getElementById("raceWizardNext").click()`);
|
||||
await evaluate(`document.getElementById("raceWizardNext").click()`);
|
||||
await evaluate(`document.getElementById("raceWizardCreate").click()`);
|
||||
await waitFor(async () => (await savedState()).events.some((event) => event.name === "HoR Deltävling 2"), "the race is created");
|
||||
const event = (await savedState()).events.find((item) => item.name === "HoR Deltävling 2");
|
||||
assert.deepEqual([event.date, event.classId, event.houseOfRc?.eventId], ["2026-12-05", "test_class", 2251]);
|
||||
assert.deepEqual([...event.raceConfig.driverIds].sort(), [...ids].sort());
|
||||
console.log("PASS House of RC event import: pick an event and class, entered drivers fill the race wizard, the race keeps the House of RC event id");
|
||||
} finally {
|
||||
await evaluate(`document.getElementById("houseOfRcEventOverlay")?.remove()`).catch(() => {});
|
||||
const current = await savedState();
|
||||
const eventIds = current.events.filter((event) => event.name === "HoR Deltävling 2").map((event) => event.id);
|
||||
Object.assign(current, {
|
||||
drivers: current.drivers.filter((driver) => !String(driver.name).startsWith("HoR ")),
|
||||
events: current.events.filter((event) => !eventIds.includes(event.id)),
|
||||
sessions: current.sessions.filter((session) => !eventIds.includes(session.eventId)),
|
||||
});
|
||||
await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(current) });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user