fix tränings statse sidan
This commit is contained in:
@@ -8,3 +8,5 @@ import "./race_audio.test.js";
|
||||
import "./decoder_runtime.test.js";
|
||||
import "./csv_import.test.js";
|
||||
import "./server_persistence.integration.test.js";
|
||||
|
||||
import "./training_views.test.js";
|
||||
|
||||
35
tests/training_views.test.js
Normal file
35
tests/training_views.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user