feat(training): fold-out practice stints with every lap time on Training and the driver's page (1.86.0)
This commit is contained in:
1 parent
3870510d8c
commit
73e1c0ccf3
16 files changed
+224
-5
No files matched your search
@@ -42,10 +42,18 @@ export async function runTrainingSourceSmoke({ evaluate, navigate, savedState, w
|
||||
assert.equal(await evaluate(`document.getElementById("training-source").value`), "practice", "practice is the default");
|
||||
assert.equal(await evaluate(`Boolean(document.querySelector('[data-sort-id="training-stints-featured"]'))`), true, "stints for practice");
|
||||
assert.equal(await evaluate(`document.querySelectorAll(".training-race-origin").length`), 0, "no race laps mixed into practice");
|
||||
// The stint card folds out to every lap, with the best lap starred.
|
||||
assert.equal(await evaluate(`document.querySelectorAll(".stint-laps-card").length`), 1, "one practice stint card");
|
||||
await evaluate(`document.querySelector(".stint-laps-card > summary").click()`);
|
||||
assert.equal(await evaluate(`document.querySelector(".stint-laps-card").open`), true, "the card opens");
|
||||
assert.deepEqual(await evaluate(`[...document.querySelectorAll(".stint-laps-card .stint-lap-time")].map((cell) => cell.textContent.trim())`), ["0:20.000", "0:20.000", "0:19.500", "0:19.500"]);
|
||||
assert.equal(await evaluate(`document.querySelectorAll(".stint-laps-card .stint-lap.is-best").length`), 2, "both 19.500 laps are best");
|
||||
console.log("PASS training stats: a practice stint folds out to every lap time");
|
||||
|
||||
await evaluate(`(() => { const select = document.getElementById("training-source"); select.value = "race"; select.dispatchEvent(new Event("change")); })()`);
|
||||
await waitFor(async () => Boolean(await evaluate(`document.querySelector('[data-sort-id="training-race-sessions"]')`)), "race sessions table");
|
||||
assert.equal(await evaluate(`Boolean(document.querySelector('[data-sort-id="training-stints-featured"]'))`), false, "no stints for races");
|
||||
assert.equal(await evaluate(`document.querySelectorAll(".stint-laps-card").length`), 0, "no stint cards for races");
|
||||
const row = await evaluate(`[...document.querySelectorAll('[data-sort-id="training-race-sessions"] tbody tr')].map((tr) => [...tr.children].map((td) => td.textContent.trim()))[0]`);
|
||||
assert.equal(row[1], "🏁 TS Winter #3 TS 2WD · Kval 2 · TS Winter Cup", "race, session and series");
|
||||
assert.equal(row[2], "3");
|
||||
|
||||
@@ -520,3 +520,12 @@ test("each class in a mobile profile carries the time of its latest lap, so the
|
||||
profile = buildPublicTrainingProfile(state, DRIVER_ONE_TOKEN, new Date(now).toISOString());
|
||||
assert.equal(lastLapAt("class_2"), now - 1000);
|
||||
});
|
||||
|
||||
test("public profile stint summaries carry lap times only, for the fold-out stint cards", () => {
|
||||
const profile = buildPublicTrainingProfile(buildState(), DRIVER_ONE_TOKEN, "");
|
||||
const stints = profile.classProfiles[0].stats.stintSummaries;
|
||||
assert.ok(stints.length > 0);
|
||||
const laps = stints.flatMap((stint) => stint.laps);
|
||||
assert.equal(laps.length, stints.reduce((sum, stint) => sum + stint.lapCount, 0));
|
||||
laps.forEach((lap) => assert.deepEqual(Object.keys(lap).sort(), ["excluded", "lapMs"]));
|
||||
});
|
||||
@@ -3,7 +3,8 @@ import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import vm from "node:vm";
|
||||
|
||||
const source = fs.readFileSync(new URL("../src/public_training.js", import.meta.url), "utf8");
|
||||
// The page is an ES module; drop its imports to run it as a plain script (rendering is stubbed below).
|
||||
const source = fs.readFileSync(new URL("../src/public_training.js", import.meta.url), "utf8").replace(/^import .*$/gm, "");
|
||||
|
||||
function profileHarness() {
|
||||
const ui = { editing: false, saving: false, requests: 0, renders: 0, html: "existing profile" };
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import "./auth.test.js";
|
||||
import "./backend_url.test.js";
|
||||
import "./houseofrc_logic.test.js";
|
||||
import "./stint_laps_view.test.js";
|
||||
import "./judging_penalties.test.js";
|
||||
import "./practice_rank.test.js";
|
||||
import "./team_race_logic.test.js";
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { buildStintLapRows, renderStintLapCards } from "../src/stint_laps_view.js";
|
||||
import { buildTrainingStintAnalysis } from "../src/training_logic.js";
|
||||
|
||||
const escapeHtml = (value) => String(value).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
||||
const labels = { stint: "Stint", laps: "Varv", best: "Bästa", average: "Snitt", duration: "Tid", lap: "Varvtider", excluded: "Startvarv", empty: "Inga" };
|
||||
const fmt = (ms) => (ms / 1000).toFixed(3);
|
||||
|
||||
test("buildStintLapRows marks best, slow and the out lap, with deltas against the best lap", () => {
|
||||
const rows = buildStintLapRows([{ lapMs: 150000, excluded: true }, { lapMs: 13500 }, { lapMs: 13201 }, { lapMs: 13400 }, { lapMs: 16000 }]);
|
||||
assert.deepEqual(rows.map((row) => row.number), [1, 2, 3, 4, 5]);
|
||||
assert.equal(rows[0].excluded, true);
|
||||
assert.equal(rows[0].deltaMs, null, "the out lap is not compared");
|
||||
assert.equal(rows[2].best, true);
|
||||
assert.equal(rows[1].deltaMs, 299);
|
||||
assert.equal(rows[4].slow, true, "over 15% above the median");
|
||||
assert.equal(rows[2].barPct, 100);
|
||||
});
|
||||
|
||||
test("renderStintLapCards lists every lap and keeps open cards open", () => {
|
||||
const stints = [{ id: "s1", number: 2, startedAt: 1, lapCount: 2, bestLapMs: 13201, averageLapMs: 13300, durationMs: 26601, laps: [{ lapMs: 13400 }, { lapMs: 13201 }] }];
|
||||
const html = renderStintLapCards(stints, { formatLap: fmt, formatDuration: fmt, escapeHtml, labels, openIds: new Set(["s1"]) });
|
||||
assert.equal((html.match(/class="stint-lap[ "]/g) || []).length, 2);
|
||||
assert.match(html, /data-stint-id="s1" open/);
|
||||
assert.match(html, /\+0\.199/);
|
||||
assert.match(html, /★/);
|
||||
assert.match(renderStintLapCards([], { escapeHtml, labels }), /Inga/);
|
||||
});
|
||||
|
||||
test("buildTrainingStintAnalysis rows carry their laps for the fold-out list", () => {
|
||||
const ledger = [10_000, 23_000, 36_500].map((timestamp, index) => ({ driverId: "d1", sourceId: "tp", sessionId: "p1", timestamp, lapMs: [10_000, 13_000, 13_500][index] }));
|
||||
const { rows } = buildTrainingStintAnalysis({ training: { ledger } }, "d1");
|
||||
assert.deepEqual(rows[0].laps.map((lap) => lap.lapMs), [10_000, 13_000, 13_500]);
|
||||
assert.equal(rows[0].averageLapMs, 12_167);
|
||||
});
|
||||
Reference in new issue
Block a user