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:
1 parent
3eb4b5f042
commit
ca88fd9ecc
9 files changed
+99
-4
No files matched your search
@@ -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");
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { runPrologueSmoke } from "./browser_prologue.js";
|
||||
import { runPracticeResetSmoke } from "./browser_practice_reset.js";
|
||||
import { runSuspectLapsSmoke } from "./browser_suspect_laps.js";
|
||||
import { runOverlayDriverLinkSmoke } from "./browser_overlay_driver_link.js";
|
||||
import { runProfileClassSmoke } from "./browser_profile_class.js";
|
||||
import { runCorrectionsScopeSmoke } from "./browser_corrections_scope.js";
|
||||
import { runDriversPageSmoke } from "./browser_drivers_page.js";
|
||||
import { runSeriesSmoke } from "./browser_series.js";
|
||||
@@ -217,6 +218,7 @@ try {
|
||||
await evaluate('document.getElementById("publicTrainingRetry").click()');
|
||||
await waitFor(async () => await evaluate('document.getElementById("publicTrainingConnection")?.dataset.state === "current"'), "mobile retry recovered");
|
||||
console.log("PASS mobile offline status preserves profile nodes and retry recovers");
|
||||
await runProfileClassSmoke({ evaluate, savedState, waitFor, base, send });
|
||||
assert.deepEqual(errors, []);
|
||||
if (dialogs.length) console.log("NOTE auto-accepted native dialog(s):", JSON.stringify(dialogs));
|
||||
console.log("PASS offline save failure, local draft retention, retry and confirmed saved status");
|
||||
|
||||
@@ -507,3 +507,16 @@ test("public profile counts practice by default; race laps only with source race
|
||||
assert.equal(stats("all").totalLaps, 6);
|
||||
assert.equal(buildPublicTrainingProfile(state, DRIVER_ONE_TOKEN, "", 0, 0, 0, 0, "current", "bogus").lapSource, "practice");
|
||||
});
|
||||
|
||||
test("each class in a mobile profile carries the time of its latest lap, so the phone opens on the class driven last", () => {
|
||||
const now = Date.now();
|
||||
const state = buildState(now);
|
||||
let profile = buildPublicTrainingProfile(state, DRIVER_ONE_TOKEN, new Date(now).toISOString());
|
||||
const lastLapAt = (classId) => profile.classProfiles.find((item) => item.classId === classId).lastLapAt;
|
||||
assert.equal(lastLapAt("class_1"), now - 4000, "2WD: the 0.5 s non-lap is not a lap");
|
||||
assert.equal(lastLapAt("class_2"), now - 5000);
|
||||
// Out with the 4WD now: it becomes the class driven last.
|
||||
state.training.ledger.push({ driverId: "driver_1_4wd", sessionId: "free", timestamp: now - 1000, lapMs: 14200 });
|
||||
profile = buildPublicTrainingProfile(state, DRIVER_ONE_TOKEN, new Date(now).toISOString());
|
||||
assert.equal(lastLapAt("class_2"), now - 1000);
|
||||
});
|
||||
Reference in new issue
Block a user