import test from "node:test"; import assert from "node:assert/strict"; import { getRaceFormatPresets, applyRaceWizardPresetDefaults, HEAT_ORDERS } from "../src/event_race_logic.js"; const presets = getRaceFormatPresets({ state: { settings: {} }, t: (key) => key, uid: () => "x", normalizeStoredRacePreset: (p) => p }); const get = (id) => presets.find((preset) => preset.id === id); test("the federation-style presets are offered with a description", () => { for (const id of ["efra_offroad", "efra_touring", "efra_nitro", "ifmar", "roar", "club_quick", "rookie_junior", "points_only"]) { assert.ok(get(id), id); assert.equal(get(id).hint, `events.preset_${id}_hint`); } }); test("every built-in preset has values the race settings accept", () => { for (const preset of presets.filter((item) => item.id !== "custom")) { const v = preset.values; assert.ok(["points", "best"].includes(v.qualifyingScoring), preset.id); assert.ok(["rank_low", "field_desc", "ifmar"].includes(v.qualifyingPointsTable), preset.id); assert.ok(["rounds", "best_lap", "best_round"].includes(v.qualifyingTieBreak), preset.id); assert.ok(["best_sum", "average", "consecutive"].includes(v.qualSeedMethod), preset.id); assert.ok(!v.heatOrder || HEAT_ORDERS.includes(v.heatOrder), preset.id); assert.ok(v.countedQualRounds <= v.qualifyingRounds, `${preset.id} counted rounds`); assert.ok(v.countedFinalLegs <= v.finalLegs, `${preset.id} counted legs`); assert.ok(v.bumpCount < v.carsPerFinal, `${preset.id} bump-up`); assert.ok(v.minLapMs < v.maxLapMs, `${preset.id} lap limits`); } }); test("a preset sets the wizard's practice rounds; others keep the draft's", () => { const getRaceWizardPreset = (id) => get(id); assert.equal(applyRaceWizardPresetDefaults({ practiceSessions: 1 }, "efra_offroad", { getRaceWizardPreset }).practiceSessions, 2); const draft = applyRaceWizardPresetDefaults({ practiceSessions: 3 }, "club_qualifying", { getRaceWizardPreset }); assert.equal(draft.practiceSessions, 3); assert.equal(draft.createPractice, true); assert.equal(applyRaceWizardPresetDefaults({}, "efra_nitro", { getRaceWizardPreset }).qualifyingRounds, 5); assert.equal(applyRaceWizardPresetDefaults({}, "endurance", { getRaceWizardPreset }).createPractice, false); });