import test from "node:test"; import assert from "node:assert/strict"; import { getDriverProfileGroups } from "../src/driver_profile_logic.js"; import { buildDriverTrainingStats } from "../src/training_logic.js"; import { buildTrainingOverviewRows, buildTrainingProgressFeed, resolveTrainingProfile } from "../src/training_views.js"; test("training opens without implicitly selecting the first driver", () => { const profiles = [{ id: "profile_1", driverIds: ["driver_1"] }]; assert.equal(resolveTrainingProfile(profiles, ""), null); assert.equal(resolveTrainingProfile(profiles, "missing"), null); assert.equal(resolveTrainingProfile(profiles, "driver_1")?.id, "profile_1"); }); test("training overview keeps each driver class on a separate statistics row", () => { const state = { classes: [{ id: "2wd", name: "2WD" }, { id: "4wd", name: "4WD" }], drivers: [ { id: "driver_2wd", profileId: "profile_1", name: "Alex", classId: "2wd" }, { id: "driver_4wd", profileId: "profile_1", name: "Alex", classId: "4wd" }, ], training: { ledger: [ { driverId: "driver_2wd", sessionId: "s1", timestamp: 1_000, lapMs: 17_000 }, { driverId: "driver_2wd", sessionId: "s1", timestamp: 18_000, lapMs: 16_500 }, { driverId: "driver_4wd", sessionId: "s2", timestamp: 2_000, lapMs: 15_000 }, ], }, }; const profiles = getDriverProfileGroups(state); const rows = buildTrainingOverviewRows(state, profiles, buildDriverTrainingStats); assert.equal(rows.length, 2); assert.equal(rows.find((row) => row.classId === "2wd").stats.totalLaps, 2); assert.equal(rows.find((row) => row.classId === "4wd").stats.totalLaps, 1); }); test("training progress feed highlights personal development instead of ranking drivers", () => { const rows = [ { profile: { id: "p1" }, driver: { name: "Alex" }, classId: "2wd", className: "2WD", stats: { totalLaps: 80, lastLapAt: 200, personalBestGainMs: 250 } }, { profile: { id: "p2" }, driver: { name: "Kim" }, classId: "4wd", className: "4WD", stats: { totalLaps: 120, lastLapAt: 100, trendSampleReady: true, averageTrendMs: 400 } }, ]; const feed = buildTrainingProgressFeed(rows); assert.deepEqual(feed.map((entry) => entry.profile.id), ["p1", "p2"]); assert.equal(feed[0].kind, "personal_best"); assert.equal(feed[1].kind, "average_gain"); });