fix(profile): open the mobile profile on the class driven last (1.42.3)

Passes and exercises only count the selected class, and the profile
opened on the first registered one, so laps with another car never
showed. It now opens on the class with the latest lap and offers a
switch when today's latest laps are in another class.
This commit is contained in:
larssand committed 2026-10-25 18:01:40 +01:00
1 parent 3eb4b5f042
commit ca88fd9ecc
9 files changed
+99 -4

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import assert from "node:assert/strict";
// A driver with several classes (one car each) went out with the 4WD, started a pass on the
// phone and saw no laps: the profile opened on the first registered class, and passes and
// exercises only count the selected class. It now opens on the class driven last, and points
// out a switch when the latest laps today are in another class.
export async function runProfileClassSmoke({ evaluate, savedState, waitFor, base, send }) {
const seeded = await savedState();
const token = "browser-profile-class-token-123456789012";
const now = Date.now();
const lap = (driverId, minutesAgo, lapMs) => ({ id: `pc_${driverId}_${minutesAgo}`, sourceKey: `pc_${driverId}_${minutesAgo}`, driverId, sessionId: "pc_session", timestamp: now - minutesAgo * 60000, lapMs });
const state = {
...seeded,
classes: [...seeded.classes, { id: "pc_2wd", name: "PC 2WD" }, { id: "pc_4wd", name: "PC 4WD" }, { id: "pc_truck", name: "PC Truck" }],
drivers: [...seeded.drivers,
{ id: "pc_driver_2wd", profileId: "pc_profile", name: "PC Driver", classId: "pc_2wd" },
{ id: "pc_driver_4wd", profileId: "pc_profile", name: "PC Driver", classId: "pc_4wd" },
{ id: "pc_driver_truck", profileId: "pc_profile", name: "PC Driver", classId: "pc_truck" }],
training: {
...(seeded.training || {}),
shares: [...(seeded.training?.shares || []), { driverId: "pc_driver_2wd", token, enabled: true }],
ledger: [...(seeded.training?.ledger || []), lap("pc_driver_2wd", 300, 20000), lap("pc_driver_2wd", 299, 19800), lap("pc_driver_4wd", 3, 17000), lap("pc_driver_4wd", 2, 16800)],
},
};
const response = await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(state) });
assert.equal(response.ok, true);
const selectedClass = () => evaluate(`document.getElementById("profileClass")?.value`);
await send("Page.navigate", { url: `${base}/public-training/${token}?lang=en` });
await waitFor(async () => (await selectedClass()) === "pc_4wd", "the profile opens on the 4WD, the class driven last");
assert.equal(await evaluate(`Boolean(document.querySelector("[data-switch-class]"))`), false, "no switch hint when the right class is shown");
console.log("PASS the mobile profile opens on the class driven last, not the first registered one");
await send("Page.navigate", { url: `${base}/public-training/${token}?lang=en&class=pc_2wd` });
await waitFor(async () => Boolean(await evaluate(`document.querySelector("[data-switch-class]")`)), "switch hint shown on another class");
assert.match(await evaluate(`document.querySelector(".profile-class-switch").innerText`), /PC 4WD/);
await evaluate(`document.querySelector("[data-switch-class]").click()`);
await waitFor(async () => (await selectedClass()) === "pc_4wd", "the button switches to the 4WD");
assert.match(await evaluate(`location.search`), /class=pc_4wd/);
assert.equal(await evaluate(`Boolean(document.querySelector("[data-switch-class]"))`), false);
console.log("PASS on another class, the profile says the latest laps are in the 4WD and switches in one tap");
}