36 lines
1.6 KiB
JavaScript
36 lines
1.6 KiB
JavaScript
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, 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);
|
|
});
|