fix(settings): make data imports real buttons and confirm the full import

The JSON imports were bare file inputs next to the export buttons and
didn't read as imports. They are now buttons like the CSV imports; the
full import asks before it replaces all race data.
This commit is contained in:
larssand committed 2026-10-23 08:05:57 +02:00
1 parent f4dc3bb5bd
commit f51aa0ba37
4 files changed
+50 -5

No files matched your search

+28
View File
@@ -66,6 +66,34 @@ export async function runSettingsTabsSmoke({ evaluate, navigate, waitFor, savedS
await evaluate(`(() => { document.querySelector('[name="raceAudioPbWarmup"]').value = "10"; document.querySelector('[name="raceAudioPbCooldown"]').value = "60"; document.querySelector('[name="raceAudioPbMinGain"]').value = "0.1"; document.getElementById("settingsForm").requestSubmit(); })()`);
console.log("PASS the practice personal best call rules default to 10 laps / 60 s / 0.1 s and are saved");
// Import is a real button next to each export (a bare "Choose file" didn't read as an import).
await evaluate(`document.querySelector('[data-settings-tab="system"]').click()`);
await waitFor(async () => evaluate(`Boolean(document.getElementById("selectImportData"))`), "System & backup shown");
assert.equal(await evaluate(`document.getElementById("importData").hidden && document.getElementById("importDirectoryData").hidden`), true, "the file inputs are hidden");
assert.equal(await evaluate(`document.getElementById("selectImportData").textContent.trim()`), "Import all race data");
assert.equal(await evaluate(`document.getElementById("selectImportDirectoryData").textContent.trim()`), "Import drivers/classes/cars");
const pickFile = (inputId, name, payload) => evaluate(`(() => {
const input = document.getElementById(${JSON.stringify(inputId)});
const transfer = new DataTransfer();
transfer.items.add(new File([${JSON.stringify(JSON.stringify(payload))}], ${JSON.stringify(name)}, { type: "application/json" }));
input.files = transfer.files;
input.dispatchEvent(new Event("change", { bubbles: true }));
})()`);
assert.equal(await evaluate(`(() => { let opened = false; const input = document.getElementById("importDirectoryData"); input.click = () => { opened = true; }; document.getElementById("selectImportDirectoryData").click(); delete input.click; return opened; })()`), true, "the button opens the file picker");
await pickFile("importDirectoryData", "directory.json", { classes: [{ id: "imp_class", name: "IMP Class" }], drivers: [{ id: "imp_driver", name: "IMP Driver", classId: "imp_class" }], cars: [] });
await waitFor(async () => (await savedState()).drivers.some((driver) => driver.id === "imp_driver"), "drivers/classes/cars imported");
assert.ok((await savedState()).sessions.length > 0, "the directory import merges - races and sessions stay");
// The full import replaces everything, so it asks first; declining changes nothing.
const sessionsBefore = (await savedState()).sessions.length;
await evaluate(`window.__confirms = []; window.__realConfirm = window.confirm; window.confirm = (message) => { window.__confirms.push(message); return false; }`);
await pickFile("importData", "full_export.json", { classes: [], drivers: [], cars: [], events: [], sessions: [] });
assert.match((await evaluate(`window.__confirms`))[0] || "", /full_export\.json[\s\S]*replaced/, "the confirm names the file and says it replaces");
assert.equal(await evaluate(`document.getElementById("importData").value`), "", "the picker is cleared so the same file can be picked again");
await new Promise((resolve) => setTimeout(resolve, 600));
assert.equal((await savedState()).sessions.length, sessionsBefore, "declining keeps everything");
await evaluate(`window.confirm = window.__realConfirm`);
console.log("PASS import is a button next to each export, and the full import asks before it replaces anything");
// The sidebar "update available" link opens Settings on System & backup at Updates, even
// when another tab was the last one used.
await evaluate(`document.querySelector('[data-settings-tab="connection"]').click()`);