Committing a new run selection no longer force-flips every data set chip to refit. The previous selection is diffed against the new one: runs that left the selection lose their edit marker, newly added runs refit, and a high-end append conservatively flips the previous pair boundary, so extending e.g. 2759-2760 to 2759-2761 touches at most the last two runs.
756 lines
28 KiB
JavaScript
756 lines
28 KiB
JavaScript
// Copyright (C) 2026 Zaher Salman
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
const assert = require("assert");
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const vm = require("vm");
|
|
|
|
const repoRoot = path.resolve(__dirname, "..");
|
|
|
|
function makeChipElement(run, action, text) {
|
|
return {
|
|
dataset: { run: String(run), action: action },
|
|
textContent: text,
|
|
className: "series-action-chip",
|
|
type: "button"
|
|
};
|
|
}
|
|
|
|
function loadLibraryWithDOM(overrides) {
|
|
const sandbox = {
|
|
console: { log: function() {}, error: console.error, warn: console.warn },
|
|
document: {
|
|
getElementById: function() { return null; },
|
|
getElementsByTagName: function() { return []; },
|
|
querySelectorAll: function() { return []; }
|
|
},
|
|
window: {}
|
|
};
|
|
sandbox.global = sandbox;
|
|
vm.runInNewContext(
|
|
fs.readFileSync(path.join(repoRoot, "muSRFitlib.js"), "utf8"),
|
|
sandbox,
|
|
{ filename: "muSRFitlib.js" }
|
|
);
|
|
sandbox.amIWeb = function() { return false; };
|
|
sandbox.prepCFG = function() {};
|
|
if (overrides) {
|
|
for (const key of Object.keys(overrides)) {
|
|
sandbox[key] = overrides[key];
|
|
}
|
|
}
|
|
return sandbox;
|
|
}
|
|
|
|
function testCollectSeriesActionOverrides() {
|
|
const chips = [
|
|
makeChipElement(2531, "reuse", "2531 · reuse"),
|
|
makeChipElement(2534, "refit", "2534 · refit"),
|
|
makeChipElement(2536, "skip", "2536 · skip")
|
|
];
|
|
const container = { querySelectorAll: function() { return chips; } };
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
getElementById: function(id) {
|
|
if (id === "seriesActionChips") return container;
|
|
return null;
|
|
}
|
|
}
|
|
});
|
|
|
|
const overrides = lib.collectSeriesActionOverrides();
|
|
// Objects returned from a vm-isolated context use a different Object.prototype,
|
|
// so compare by content rather than deepStrictEqual (which checks prototypes).
|
|
assert.strictEqual(JSON.stringify(overrides),
|
|
JSON.stringify({ 2531: "reuse", 2534: "refit", 2536: "skip" }),
|
|
"all visible chip choices must be passed to the series planner");
|
|
}
|
|
|
|
function testCollectSeriesActionOverridesEmptyContainer() {
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
getElementById: function() { return null; },
|
|
querySelectorAll: function() { return []; }
|
|
}
|
|
});
|
|
assert.strictEqual(JSON.stringify(lib.collectSeriesActionOverrides()), "{}");
|
|
}
|
|
|
|
function testUpdateSeriesActionVisibilityEligible() {
|
|
let hiddenValue = true;
|
|
const container = { innerHTML: "", appendChild: function() {} };
|
|
const createElement = function(tag) {
|
|
return {
|
|
dataset: {},
|
|
className: "",
|
|
textContent: "",
|
|
type: "",
|
|
title: "",
|
|
onclick: null,
|
|
appendChild: function() {}
|
|
};
|
|
};
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
createElement: createElement,
|
|
getElementById: function(id) {
|
|
if (id === "seriesActionsRow") {
|
|
return { set hidden(v) { hiddenValue = Boolean(v); } };
|
|
}
|
|
if (id === "seriesActionChips") return container;
|
|
if (id === "runNumbers") return { value: "2531, 2534, 2536" };
|
|
if (id === "Params") return { querySelectorAll: function() { return []; } };
|
|
return null;
|
|
}
|
|
}
|
|
});
|
|
lib.collectSharedParameterControls = function() { return {}; };
|
|
lib.All.runNumbers = "2531, 2534, 2536";
|
|
|
|
lib.updateSeriesActionVisibility();
|
|
assert.strictEqual(hiddenValue, false,
|
|
"series actions row must be visible for ≥2 data sets with no shared parameters");
|
|
}
|
|
|
|
function testUpdateSeriesActionVisibilityHiddenForSingleRun() {
|
|
let hiddenValue = false;
|
|
const container = { innerHTML: "", appendChild: function() {} };
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
createElement: function() { return { dataset: {}, appendChild: function() {} }; },
|
|
getElementById: function(id) {
|
|
if (id === "seriesActionsRow") {
|
|
return { set hidden(v) { hiddenValue = Boolean(v); } };
|
|
}
|
|
if (id === "seriesActionChips") return container;
|
|
if (id === "runNumbers") return { value: "2531" };
|
|
return null;
|
|
}
|
|
}
|
|
});
|
|
lib.collectSharedParameterControls = function() { return {}; };
|
|
lib.All.runNumbers = "2531";
|
|
|
|
lib.updateSeriesActionVisibility();
|
|
assert.strictEqual(hiddenValue, true,
|
|
"series actions row must be hidden for a single data set");
|
|
}
|
|
|
|
function testUpdateSeriesActionVisibilityHiddenForShared() {
|
|
let hiddenValue = false;
|
|
const container = { innerHTML: "", appendChild: function() {} };
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
createElement: function() { return { dataset: {}, appendChild: function() {} }; },
|
|
getElementById: function(id) {
|
|
if (id === "seriesActionsRow") {
|
|
return { set hidden(v) { hiddenValue = Boolean(v); } };
|
|
}
|
|
if (id === "seriesActionChips") return container;
|
|
if (id === "runNumbers") return { value: "2531, 2534" };
|
|
return null;
|
|
}
|
|
}
|
|
});
|
|
lib.collectSharedParameterControls = function() { return { shLam: true }; };
|
|
lib.All.runNumbers = "2531, 2534";
|
|
|
|
lib.updateSeriesActionVisibility();
|
|
assert.strictEqual(hiddenValue, true,
|
|
"series actions row must be hidden when any parameter is shared (global route)");
|
|
}
|
|
|
|
function testRenderSeriesActionChipsCycles() {
|
|
// Verify the chip click handler cycles reuse → refit → skip → reuse.
|
|
let appended = [];
|
|
const container = {
|
|
innerHTML: "",
|
|
appendChild: function(el) { appended.push(el); }
|
|
};
|
|
const createElement = function(tag) {
|
|
return {
|
|
dataset: {},
|
|
className: "",
|
|
textContent: "",
|
|
type: "",
|
|
title: "",
|
|
onclick: null,
|
|
set textContent(v) { this._text = v; },
|
|
appendChild: function() {}
|
|
};
|
|
};
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
createElement: createElement,
|
|
getElementById: function(id) {
|
|
if (id === "seriesActionChips") return container;
|
|
return null;
|
|
}
|
|
}
|
|
});
|
|
lib.collectSharedParameterControls = function() { return {}; };
|
|
|
|
lib.renderSeriesActionChips([{ main: 2534, add: [] }]);
|
|
assert.strictEqual(appended.length, 1);
|
|
const chip = appended[0];
|
|
assert.strictEqual(chip.dataset.run, "2534");
|
|
assert.strictEqual(chip.dataset.action, "reuse");
|
|
chip.onclick.call(chip);
|
|
assert.strictEqual(chip.dataset.action, "refit");
|
|
chip.onclick.call(chip);
|
|
assert.strictEqual(chip.dataset.action, "skip");
|
|
chip.onclick.call(chip);
|
|
assert.strictEqual(chip.dataset.action, "reuse");
|
|
}
|
|
|
|
function testRenderSeriesActionBulk() {
|
|
// The "All" selector must set every chip to one action at once.
|
|
let appended = [];
|
|
const container = {
|
|
innerHTML: "",
|
|
appendChild: function(el) { appended.push(el); },
|
|
querySelectorAll: function() { return appended; }
|
|
};
|
|
const createElement = function(tag) {
|
|
return {
|
|
dataset: {},
|
|
className: "",
|
|
textContent: "",
|
|
type: "",
|
|
title: "",
|
|
onclick: null,
|
|
set textContent(v) { this._text = v; },
|
|
appendChild: function() {}
|
|
};
|
|
};
|
|
const bulk = { value: "", onchange: null };
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
createElement: createElement,
|
|
getElementById: function(id) {
|
|
if (id === "seriesActionChips") return container;
|
|
if (id === "seriesActionAll") return bulk;
|
|
return null;
|
|
}
|
|
}
|
|
});
|
|
lib.collectSharedParameterControls = function() { return {}; };
|
|
|
|
lib.renderSeriesActionChips([
|
|
{ main: 2531, add: [] },
|
|
{ main: 2534, add: [] },
|
|
{ main: 2536, add: [] }
|
|
]);
|
|
assert.strictEqual(appended.length, 3);
|
|
assert.ok(typeof bulk.onchange === "function",
|
|
"the All selector must get an onchange handler during render");
|
|
|
|
bulk.value = "refit";
|
|
bulk.onchange.call(bulk);
|
|
for (const chip of appended) {
|
|
assert.strictEqual(chip.dataset.action, "refit",
|
|
"All=refit must set every chip to refit");
|
|
}
|
|
|
|
bulk.value = "skip";
|
|
bulk.onchange.call(bulk);
|
|
for (const chip of appended) {
|
|
assert.strictEqual(chip.dataset.action, "skip");
|
|
}
|
|
|
|
bulk.value = "reuse";
|
|
bulk.onchange.call(bulk);
|
|
for (const chip of appended) {
|
|
assert.strictEqual(chip.dataset.action, "reuse");
|
|
}
|
|
}
|
|
|
|
function testRenderSeriesActionChipsPreservesUnchangedDataSets() {
|
|
// Refreshes caused by parameter sharing or other GUI updates must not erase
|
|
// explicit actions. The full main+ADDRUN identity determines whether a data
|
|
// set is unchanged and may safely retain its previous choice.
|
|
let children = [];
|
|
const container = {
|
|
get innerHTML() {
|
|
return "";
|
|
},
|
|
set innerHTML(value) {
|
|
if (value === "") children = [];
|
|
},
|
|
appendChild: function(element) {
|
|
children.push(element);
|
|
},
|
|
querySelectorAll: function() {
|
|
return children.slice();
|
|
}
|
|
};
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
createElement: function() {
|
|
return {
|
|
dataset: {},
|
|
className: "",
|
|
textContent: "",
|
|
type: "",
|
|
title: "",
|
|
onclick: null
|
|
};
|
|
},
|
|
getElementById: function(id) {
|
|
return id === "seriesActionChips" ? container : null;
|
|
}
|
|
}
|
|
});
|
|
|
|
lib.renderSeriesActionChips([
|
|
{ main: 2531, add: [] },
|
|
{ main: 2534, add: [2533] }
|
|
]);
|
|
children[0].dataset.action = "refit";
|
|
children[1].dataset.action = "skip";
|
|
|
|
lib.renderSeriesActionChips([
|
|
{ main: 2531, add: [] },
|
|
{ main: 2534, add: [2533] },
|
|
{ main: 2536, add: [] }
|
|
]);
|
|
assert.deepStrictEqual(children.map(function(chip) {
|
|
return chip.dataset.action;
|
|
}), ["refit", "skip", "reuse"]);
|
|
assert.strictEqual(children[1].dataset.seriesKey, "2534+2533");
|
|
|
|
// Changing an ADDRUN member changes the logical data set even though its
|
|
// main run is the same, so this chip must return to the safe default.
|
|
lib.renderSeriesActionChips([
|
|
{ main: 2531, add: [] },
|
|
{ main: 2534, add: [2532] }
|
|
]);
|
|
assert.deepStrictEqual(children.map(function(chip) {
|
|
return chip.dataset.action;
|
|
}), ["refit", "reuse"]);
|
|
}
|
|
|
|
async function testInspectPlanAppliesRefitOverride() {
|
|
const lib = loadLibraryWithDOM();
|
|
const entries = [];
|
|
const config = {
|
|
all: {
|
|
runNumbers: "2531,2534,2536",
|
|
instrName: "LEM",
|
|
selYear: "2026",
|
|
workPath: "/work",
|
|
dataRoot: "/data"
|
|
},
|
|
runSelection: [
|
|
{ main: 2531, add: [] },
|
|
{ main: 2534, add: [] },
|
|
{ main: 2536, add: [] }
|
|
],
|
|
sharedFlags: {},
|
|
fileNameSuffix: "_asy",
|
|
workPath: "/work",
|
|
actionOverrides: { 2531: "reuse", 2534: "refit", 2536: "skip" }
|
|
};
|
|
lib.parseRunSelection = function(text) { return config.runSelection; };
|
|
lib.planFitExecution = function() {
|
|
return { mode: "series", reason: "independent-data-sets", dataSetCount: 3 };
|
|
};
|
|
lib.seriesDataFilePath = function(run) { return "/data/run" + run; };
|
|
lib.collectSharedParameterControls = function() { return {}; };
|
|
lib.classifySeriesFitResult = function(opts) {
|
|
const recent = opts.expectedDataSet.main === 2531;
|
|
return {
|
|
state: recent ? "converged-recent" : "converged-complete",
|
|
action: recent ? "refit" : "skip",
|
|
reusable: !recent,
|
|
reason: recent ? "not-enough-newer-data-runs" : "converged-with-newer-data-runs",
|
|
statistic: { found: true, converged: true, kind: "chi2", value: "1.0", ndf: "10", text: "" }
|
|
};
|
|
};
|
|
|
|
const msrFileExists = async function() { return true; };
|
|
const dataFileExists = async function() { return true; };
|
|
const readAsciiFile = async function() { return "converged msr text"; };
|
|
|
|
const plan = await lib.inspectSeriesFitPlan(config, {
|
|
msrFileExists: msrFileExists,
|
|
dataFileExists: dataFileExists,
|
|
readAsciiFile: readAsciiFile
|
|
});
|
|
|
|
assert.strictEqual(plan.ok, true);
|
|
const byRun = {};
|
|
for (const entry of plan.entries) byRun[entry.run] = entry;
|
|
|
|
// Explicit reuse accepts an identity-checked converged file even when the
|
|
// automatic maturity rule would otherwise schedule a conservative refit.
|
|
assert.strictEqual(byRun[2531].action, "skip");
|
|
assert.strictEqual(byRun[2531].reusable, true);
|
|
assert.strictEqual(byRun[2531].reason, "user-requested-reuse");
|
|
|
|
// 2534 forced to refit from GUI template.
|
|
assert.strictEqual(byRun[2534].action, "refit");
|
|
assert.strictEqual(byRun[2534].useGuiTemplate, true);
|
|
assert.strictEqual(byRun[2534].reusable, false);
|
|
|
|
// 2536 forced to skip.
|
|
assert.strictEqual(byRun[2536].action, "skip");
|
|
assert.strictEqual(byRun[2536].useGuiTemplate, false);
|
|
assert.strictEqual(byRun[2536].reusable, false);
|
|
}
|
|
|
|
async function testPrepareCandidatesUsesGuiTemplateForRefit() {
|
|
const lib = loadLibraryWithDOM();
|
|
// Build a minimal plan with three entries.
|
|
const entries = [
|
|
{ run: 2531, action: "skip", reusable: true, msrExists: true,
|
|
dataSet: { main: 2531, add: [] }, msrPath: "/work/2531_asy.msr",
|
|
msrText: "fitted 2531", msrHash: "h1" },
|
|
{ run: 2534, action: "refit", useGuiTemplate: true,
|
|
dataSet: { main: 2534, add: [] }, msrPath: "/work/2534_asy.msr",
|
|
msrText: "old 2534", msrHash: "h2" },
|
|
{ run: 2536, action: "skip", dataSet: { main: 2536, add: [] },
|
|
msrPath: "/work/2536_asy.msr" }
|
|
];
|
|
const plan = {
|
|
ok: true,
|
|
mode: "series",
|
|
entries: entries,
|
|
summary: { total: 3, fit: 0, retry: 0, refit: 1, skip: 2, blocked: 0 }
|
|
};
|
|
const config = { all: { instrName: "LEM", selYear: "2026" }, referenceRun: 2531 };
|
|
|
|
let guiBuilds = 0;
|
|
lib.buildSeriesGUITemplate = function(entry, all) {
|
|
guiBuilds++;
|
|
assert.strictEqual(entry.run, 2534);
|
|
assert.strictEqual(all.runNumbers, undefined);
|
|
return {
|
|
ok: true,
|
|
text: "gui-template-for-2534",
|
|
parameterNamesChanged: 0,
|
|
runBlocks: [{ run: 2534 }]
|
|
};
|
|
};
|
|
lib.transformSeriesReferenceMSR = function(referenceMSR, refDataSet, targetDataSet, all) {
|
|
assert.fail("transformed MSR must not be used for a GUI-template candidate");
|
|
};
|
|
lib.readAsciiFile = async function() { return "fitted 2531"; };
|
|
lib.parseMSRFitStatistic = function() {
|
|
return { converged: true };
|
|
};
|
|
|
|
const result = await lib.prepareSeriesMSRCandidates(plan, config, {
|
|
readAsciiFile: lib.readAsciiFile
|
|
});
|
|
assert.strictEqual(result.ok, true);
|
|
assert.strictEqual(guiBuilds, 1);
|
|
assert.strictEqual(result.candidates.length, 1);
|
|
assert.strictEqual(result.candidates[0].run, 2534);
|
|
assert.strictEqual(result.candidates[0].text, "gui-template-for-2534");
|
|
assert.strictEqual(result.candidates[0].useGuiTemplate, true);
|
|
assert.strictEqual(result.excluded.length, 2);
|
|
}
|
|
|
|
function testMarkSeriesRunParametersEdited() {
|
|
const chips = [
|
|
makeChipElement(2531, "reuse", "2531 · reuse"),
|
|
makeChipElement(2534, "skip", "2534 · skip"),
|
|
makeChipElement(2536, "reuse", "2536 · reuse")
|
|
];
|
|
const container = { querySelectorAll: function() { return chips; } };
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
getElementById: function(id) {
|
|
if (id === "seriesActionChips") return container;
|
|
if (id === "runNumbers") return { value: "2531, 2534, 2536" };
|
|
return null;
|
|
}
|
|
}
|
|
});
|
|
|
|
lib.markSeriesRunParametersEdited(2534);
|
|
assert.strictEqual(lib.window.MusrfitSeriesEditedRuns[2534], true,
|
|
"an edited run must be recorded in the module-level marker set");
|
|
assert.strictEqual(chips[1].dataset.action, "refit",
|
|
"an edited run's chip must flip to refit");
|
|
assert.strictEqual(chips[1].textContent, "2534 · refit");
|
|
assert.strictEqual(chips[0].dataset.action, "reuse",
|
|
"unrelated chips must stay untouched");
|
|
assert.strictEqual(chips[2].dataset.action, "reuse");
|
|
|
|
// Structural changes mark every data set of the current selection.
|
|
lib.markAllCurrentSeriesRunsEdited();
|
|
assert.strictEqual(lib.window.MusrfitSeriesEditedRuns[2531], true);
|
|
assert.strictEqual(lib.window.MusrfitSeriesEditedRuns[2536], true);
|
|
assert.strictEqual(chips[0].dataset.action, "refit");
|
|
assert.strictEqual(chips[2].dataset.action, "refit");
|
|
}
|
|
|
|
function testClearSeriesRunParametersEdited() {
|
|
const chips = [makeChipElement(2534, "refit", "2534 · refit")];
|
|
const container = { querySelectorAll: function() { return chips; } };
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
getElementById: function(id) {
|
|
return id === "seriesActionChips" ? container : null;
|
|
}
|
|
}
|
|
});
|
|
lib.markSeriesRunParametersEdited(2534);
|
|
assert.strictEqual(lib.window.MusrfitSeriesEditedRuns[2534], true);
|
|
lib.clearSeriesRunParametersEdited(2534);
|
|
assert.strictEqual(lib.window.MusrfitSeriesEditedRuns[2534], undefined,
|
|
"a successful refit must clear the edit marker");
|
|
assert.strictEqual(chips[0].dataset.action, "reuse",
|
|
"the chip must return to the reusable default after a successful refit");
|
|
}
|
|
|
|
function testCollectSeriesGUIEditedRuns() {
|
|
const lib = loadLibraryWithDOM({});
|
|
lib.markSeriesRunParametersEdited(2531);
|
|
lib.markSeriesRunParametersEdited(2536);
|
|
assert.strictEqual(JSON.stringify(lib.collectSeriesGUIEditedRuns()),
|
|
JSON.stringify({ 2531: true, 2536: true }));
|
|
}
|
|
|
|
function testHandleSeriesParameterEditEvent() {
|
|
const chips = [];
|
|
const marked = [];
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
getElementById: function(id) {
|
|
if (id === "seriesActionChips") {
|
|
return { querySelectorAll: function() { return chips; } };
|
|
}
|
|
if (id === "runNumbers") return { value: "2531, 2534" };
|
|
return null;
|
|
}
|
|
}
|
|
});
|
|
const original = lib.markSeriesRunParametersEdited;
|
|
lib.markSeriesRunParametersEdited = function(run) {
|
|
marked.push(Number(run));
|
|
return original.call(lib, run);
|
|
};
|
|
|
|
const row = {
|
|
dataset: {},
|
|
getAttribute: function(name) {
|
|
const key = name.replace(/^data-/, "");
|
|
return Object.prototype.hasOwnProperty.call(this.dataset, key)
|
|
? this.dataset[key] : null;
|
|
}
|
|
};
|
|
const input = {
|
|
tagName: "INPUT",
|
|
classList: { contains: function(cls) { return cls === "parameter-value-input"; } },
|
|
closest: function() { return row; }
|
|
};
|
|
|
|
row.dataset.run = "2534";
|
|
lib.handleSeriesParameterEditEvent({ target: input });
|
|
assert.deepStrictEqual(marked, [2534]);
|
|
|
|
marked.length = 0;
|
|
row.dataset.run = "";
|
|
row.dataset.shared = "1";
|
|
lib.handleSeriesParameterEditEvent({ target: input });
|
|
assert.deepStrictEqual(marked.slice().sort(function(a, b) { return a - b; }),
|
|
[2531, 2534], "a shared parameter row must mark every selected data set");
|
|
}
|
|
|
|
function testHandleSeriesRunsTabEditEvent() {
|
|
const marked = [];
|
|
const lib = loadLibraryWithDOM({});
|
|
lib.markAllCurrentSeriesRunsEdited = function() { marked.push("all"); };
|
|
|
|
lib.handleSeriesRunsTabEditEvent({ target: { id: "Tis" } });
|
|
assert.deepStrictEqual(marked, ["all"], "a fit-range edit must mark every run");
|
|
marked.length = 0;
|
|
lib.handleSeriesRunsTabEditEvent({ target: { id: "minType" } });
|
|
assert.deepStrictEqual(marked, ["all"], "a fit-option edit must mark every run");
|
|
marked.length = 0;
|
|
lib.handleSeriesRunsTabEditEvent({ target: { id: "runNumbers" } });
|
|
assert.deepStrictEqual(marked, [],
|
|
"run-number changes are owned by handleRunSelectionChange");
|
|
lib.handleSeriesRunsTabEditEvent({ target: { id: "seriesActionAll" } });
|
|
assert.deepStrictEqual(marked, [], "series action controls only choose chips");
|
|
lib.handleSeriesRunsTabEditEvent({ target: { id: "Tpis" } });
|
|
assert.deepStrictEqual(marked, [], "plot-only ranges must not mark runs as edited");
|
|
}
|
|
|
|
function testHandleSeriesT0BgEditEvent() {
|
|
const marked = [];
|
|
const lib = loadLibraryWithDOM({});
|
|
lib.markAllCurrentSeriesRunsEdited = function() { marked.push("all"); };
|
|
lib.handleSeriesT0BgEditEvent({ target: {} });
|
|
assert.deepStrictEqual(marked, ["all"],
|
|
"a t0/background edit must mark every run as edited");
|
|
}
|
|
|
|
function testSuppressedCaptureDoesNotMark() {
|
|
const marked = [];
|
|
const lib = loadLibraryWithDOM({});
|
|
lib.markSeriesRunParametersEdited = function(run) { marked.push(Number(run)); };
|
|
lib.suppressSeriesGUIEditCapture = true;
|
|
const input = {
|
|
tagName: "INPUT",
|
|
classList: { contains: function() { return true; } },
|
|
closest: function() {
|
|
return {
|
|
dataset: { shared: "1", run: "2534" },
|
|
getAttribute: function(name) {
|
|
return name === "data-shared" ? "1" : "2534";
|
|
}
|
|
};
|
|
}
|
|
};
|
|
lib.handleSeriesParameterEditEvent({ target: input });
|
|
assert.deepStrictEqual(marked, [],
|
|
"programmatic restores (MSR import, shared links) must not mark runs as edited");
|
|
}
|
|
|
|
function editedRuns(lib) {
|
|
return Object.keys(lib.window.MusrfitSeriesEditedRuns || {})
|
|
.map(Number)
|
|
.sort(function(a, b) { return a - b; });
|
|
}
|
|
|
|
function testCollectSeriesChipRuns() {
|
|
const chips = [
|
|
makeChipElement(2531, "reuse", "2531 · reuse"),
|
|
makeChipElement(2534, "refit", "2534 · refit")
|
|
];
|
|
const container = { querySelectorAll: function() { return chips; } };
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
getElementById: function(id) {
|
|
return id === "seriesActionChips" ? container : null;
|
|
}
|
|
}
|
|
});
|
|
assert.strictEqual(JSON.stringify(lib.collectSeriesChipRuns()),
|
|
JSON.stringify([2531, 2534]),
|
|
"the chip row must mirror the last committed run selection");
|
|
assert.strictEqual(JSON.stringify(lib.collectSeriesChipRuns()),
|
|
JSON.stringify([2531, 2534]));
|
|
|
|
const nullLib = loadLibraryWithDOM();
|
|
assert.strictEqual(JSON.stringify(nullLib.collectSeriesChipRuns()),
|
|
"[]", "an absent chip row yields no previous selection");
|
|
}
|
|
|
|
function testMarkSeriesRunSelectionEditedAppend() {
|
|
const lib = loadLibraryWithDOM();
|
|
lib.markSeriesRunSelectionEdited([2759, 2760, 2761, 2762], [2759, 2760, 2761]);
|
|
assert.deepStrictEqual(editedRuns(lib), [2761, 2762],
|
|
"a high-end append must flip only the new tail plus the previous boundary");
|
|
|
|
delete lib.window.MusrfitSeriesEditedRuns;
|
|
lib.markSeriesRunSelectionEdited([2759, 2760, 2762], [2759, 2760, 2761]);
|
|
assert.deepStrictEqual(editedRuns(lib), [2760, 2762],
|
|
"a drop + high-end append must refit the new run and the new pair boundary");
|
|
}
|
|
|
|
function testMarkSeriesRunSelectionEditedLowEndAppend() {
|
|
const lib = loadLibraryWithDOM();
|
|
lib.markSeriesRunSelectionEdited([2758, 2759, 2760, 2761], [2759, 2760, 2761]);
|
|
assert.deepStrictEqual(editedRuns(lib), [2758],
|
|
"a low-end extension must flip only the newly added run");
|
|
}
|
|
|
|
function testMarkSeriesRunSelectionEditedRemove() {
|
|
const lib = loadLibraryWithDOM();
|
|
lib.markSeriesRunParametersEdited(2759);
|
|
lib.markSeriesRunParametersEdited(2760);
|
|
lib.markSeriesRunParametersEdited(2761);
|
|
assert.deepStrictEqual(editedRuns(lib), [2759, 2760, 2761]);
|
|
lib.markSeriesRunSelectionEdited([2759, 2761], [2759, 2760, 2761]);
|
|
assert.deepStrictEqual(editedRuns(lib), [2759, 2761],
|
|
"removed runs lose their markers while previously-marked survivors keep them");
|
|
}
|
|
|
|
function testMarkSeriesRunSelectionEditedFullReplacement() {
|
|
const lib = loadLibraryWithDOM();
|
|
lib.markSeriesRunSelectionEdited([2761, 2762], [2759, 2760]);
|
|
assert.deepStrictEqual(editedRuns(lib), [2761, 2762],
|
|
"a full replacement flips exactly the newly selected runs, with no boundary");
|
|
}
|
|
|
|
function testMarkSeriesRunSelectionEditedNoPrevious() {
|
|
const lib = loadLibraryWithDOM();
|
|
lib.markSeriesRunSelectionEdited([2531, 2534], []);
|
|
assert.deepStrictEqual(editedRuns(lib), [2531, 2534],
|
|
"without a reference selection every data set must be marked as edited");
|
|
}
|
|
|
|
function testHandleRunSelectionChangeDiffsChips() {
|
|
const chips = [
|
|
makeChipElement(2531, "reuse", "2531 · reuse"),
|
|
makeChipElement(2534, "refit", "2534 · refit")
|
|
];
|
|
const container = { querySelectorAll: function() { return chips; } };
|
|
const lib = loadLibraryWithDOM({
|
|
document: {
|
|
getElementById: function(id) {
|
|
if (id === "seriesActionChips") return container;
|
|
return null;
|
|
}
|
|
}
|
|
});
|
|
|
|
lib.handleRunSelectionChange("2531, 2534, 2536");
|
|
assert.deepStrictEqual(editedRuns(lib), [2534, 2536],
|
|
"committing 2531,2534 -> 2531,2534,2536 must flip only the new tail and the boundary");
|
|
assert.strictEqual(JSON.stringify(lib.window.MusrfitSeriesLastSelection),
|
|
JSON.stringify([2531, 2534, 2536]),
|
|
"the committed selection must be snapshotted");
|
|
assert.strictEqual(chips[0].dataset.action, "reuse",
|
|
"the unchanged 2531 chip must stay reuse");
|
|
assert.strictEqual(chips[1].dataset.action, "refit",
|
|
"the previous boundary 2534 chip must flip to refit");
|
|
|
|
delete lib.window.MusrfitSeriesEditedRuns;
|
|
lib.handleRunSelectionChange("2531, 2534");
|
|
assert.deepStrictEqual(editedRuns(lib), [],
|
|
"shortening the selection back must refit nothing");
|
|
|
|
delete lib.window.MusrfitSeriesEditedRuns;
|
|
lib.handleRunSelectionChange("2535, 2536");
|
|
assert.deepStrictEqual(editedRuns(lib), [2535, 2536],
|
|
"a disjoint replacement must mark every newly selected run");
|
|
}
|
|
|
|
(async function main() {
|
|
testCollectSeriesActionOverrides();
|
|
testCollectSeriesActionOverridesEmptyContainer();
|
|
testUpdateSeriesActionVisibilityEligible();
|
|
testUpdateSeriesActionVisibilityHiddenForSingleRun();
|
|
testUpdateSeriesActionVisibilityHiddenForShared();
|
|
testRenderSeriesActionChipsCycles();
|
|
testRenderSeriesActionBulk();
|
|
testRenderSeriesActionChipsPreservesUnchangedDataSets();
|
|
await testInspectPlanAppliesRefitOverride();
|
|
await testPrepareCandidatesUsesGuiTemplateForRefit();
|
|
testMarkSeriesRunParametersEdited();
|
|
testClearSeriesRunParametersEdited();
|
|
testCollectSeriesGUIEditedRuns();
|
|
testHandleSeriesParameterEditEvent();
|
|
testHandleSeriesRunsTabEditEvent();
|
|
testHandleSeriesT0BgEditEvent();
|
|
testSuppressedCaptureDoesNotMark();
|
|
testCollectSeriesChipRuns();
|
|
testMarkSeriesRunSelectionEditedAppend();
|
|
testMarkSeriesRunSelectionEditedLowEndAppend();
|
|
testMarkSeriesRunSelectionEditedRemove();
|
|
testMarkSeriesRunSelectionEditedFullReplacement();
|
|
testMarkSeriesRunSelectionEditedNoPrevious();
|
|
testHandleRunSelectionChangeDiffsChips();
|
|
console.log("series action chips tests passed");
|
|
})().catch(function(error) {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|