feat(race): driver picker grouped by class with all/none per class, search and copy from an earlier race (1.89.33)

This commit is contained in:
larssand committed 2026-11-14 21:34:32 +01:00
1 parent eac897c774
commit cc286165df
17 files changed
+339 -102

No files matched your search

+15 -7
View File
@@ -18,14 +18,22 @@ export async function runSeriesRookieSmoke({ evaluate, navigate, savedState, wai
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()`);
await waitFor(async () => evaluate(`Boolean(document.querySelector(".series-other-drivers[open]"))`), "drivers from other classes are offered (open, the class has none)");
assert.match(await evaluate(`document.querySelector(".series-other-drivers").textContent`), /RK Ada[\s\S]*RK 2WD[\s\S]*RK Ben[\s\S]*RK 4WD/, "each with their own class");
for (const id of ["rk_ada", "rk_ben"]) {
await evaluate(`(() => { const box = document.querySelector('.series-other-drivers [data-round-driver="${id}"]'); box.checked = true; box.dispatchEvent(new Event("change")); })()`);
await waitFor(async () => (await driverIds()).includes(id), `${id} ticked for the Rookie round`);
}
// 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('.series-round-participants > .series-class-list [data-round-driver="rk_ben"]:checked'))`), "a ticked rookie moves to the round's own list");
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");
}
+42
View File
@@ -0,0 +1,42 @@
import test from "node:test";
import assert from "node:assert/strict";
import { groupParticipantChoices, participantCopySources, renderParticipantPicker } from "../src/participant_picker.js";
const classes = [{ id: "r", name: "Rookie" }, { id: "b2", name: "Rookie 2WD" }, { id: "b4", name: "Rookie 4WD" }, { id: "j4", name: "Junior 4WD" }];
const drivers = [
{ id: "1", name: "Ola", classId: "b2" }, { id: "2", name: "Ada", classId: "b2" },
{ id: "3", name: "Kim", classId: "b4" }, { id: "4", name: "Eli", classId: "j4" }, { id: "5", name: "Noa", classId: "" },
];
const escapeHtml = (v) => String(v).replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
const t = (key, params = {}) => key.replace(/\{(\w+)\}/g, (_, k) => params[k]) + Object.values(params).join(" ");
test("drivers are grouped by class: the race's own class first (even empty), then classes with someone ticked", () => {
const groups = groupParticipantChoices(drivers, classes, { primaryClassId: "r", selectedIds: ["4"], noClassLabel: "No class" });
assert.deepEqual(groups.map((g) => g.name), ["Rookie", "Junior 4WD", "Rookie 2WD", "Rookie 4WD", "No class"]);
assert.equal(groups[0].primary, true);
assert.equal(groups[0].drivers.length, 0);
assert.deepEqual(groups.find((g) => g.key === "b2").drivers.map((d) => d.name), ["Ada", "Ola"]);
assert.equal(groups.find((g) => g.key === "j4").selected, 1);
});
test("the picker renders a checkbox per driver with the caller's attributes, checked as selected", () => {
const html = renderParticipantPicker({ pickerKey: "x", drivers, classes, selectedIds: ["1"], primaryClassId: "b2", inputAttrs: () => 'class="race-participant"', t, escapeHtml });
assert.equal((html.match(/class="race-participant"/g) || []).length, 5);
assert.match(html, /class="race-participant" value="1" data-picker-driver checked/);
assert.match(html, /data-picker-group="b2" open/, "own class open");
assert.doesNotMatch(html, /data-picker-group="j4" open/, "other classes folded");
});
test("copy sources: earlier races with drivers, the series' rounds first, then newest", () => {
const events = [
{ id: "a", mode: "race", name: "Club", date: "2026-10-01" },
{ id: "b", mode: "race", name: "Cup 1", date: "2026-09-01" },
{ id: "c", mode: "race", name: "Empty", date: "2026-11-01" },
{ id: "d", mode: "track", name: "Practice", date: "2026-11-02" },
{ id: "me", mode: "race", name: "Cup 2", date: "2026-11-10" },
];
const ids = { a: ["1"], b: ["1", "2"], c: [], d: ["3"], me: ["4"] };
const sources = participantCopySources(events, { currentEventId: "me", seriesEventIds: ["b", "me"], getDriverIds: (e) => ids[e.id] });
assert.deepEqual(sources.map((s) => s.id), ["b", "a"]);
assert.equal(sources[0].label, "🏆 2026-09-01 · Cup 1 (2)");
});
+1
View File
@@ -10,6 +10,7 @@ import "./practice_rank.test.js";
import "./team_race_logic.test.js";
import "./race_overview.test.js";
import "./lap_chart.test.js";
import "./participant_picker.test.js";
import "./leader_call_logic.test.js";
import "./decoder_sim.test.js";
import "./sponsor_event.test.js";