Files
muSRFlow/tests/window-layering.test.js
T
2026-09-22 20:18:08 +02:00

64 lines
2.9 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 loadLibrary() {
const code = fs.readFileSync(path.join(repoRoot, "muSRFitlib.js"), "utf8");
const sandbox = {
console: { log: function() {}, error: console.error, warn: console.warn },
window: { MSREditor: {} }
};
sandbox.global = sandbox;
vm.runInNewContext(code, sandbox, { filename: "muSRFitlib.js" });
return sandbox;
}
function testSharedLayerCounter(lib) {
const rootPlot = { style: {} };
const parameterPlot = { style: {} };
const runLog = { style: {} };
assert.strictEqual(lib.bringMusrfitFloatingWindowToFront(rootPlot), 1101);
assert.strictEqual(rootPlot.style.zIndex, "1101");
assert.strictEqual(lib.bringMusrfitFloatingWindowToFront(parameterPlot), 1102);
assert.strictEqual(parameterPlot.style.zIndex, "1102");
assert.strictEqual(lib.bringMusrfitFloatingWindowToFront(runLog), 1103);
assert.strictEqual(runLog.style.zIndex, "1103");
// Returning to an older ROOT plot must bring it above every later window,
// including parameter plots that previously used a separate counter.
assert.strictEqual(lib.bringMusrfitFloatingWindowToFront(rootPlot), 1104);
assert.ok(Number(rootPlot.style.zIndex) > Number(parameterPlot.style.zIndex));
}
function testEveryBrowserWindowUsesTheManager() {
const root = fs.readFileSync(path.join(repoRoot, "muSRFitRoot.js"), "utf8");
const web = fs.readFileSync(path.join(repoRoot, "muSRFitweb.js"), "utf8");
const lib = fs.readFileSync(path.join(repoRoot, "muSRFitlib.js"), "utf8");
const css = fs.readFileSync(path.join(repoRoot, "ZGUI.css"), "utf8");
assert.doesNotMatch(root, /webRootPlotWindowZIndex/);
assert.doesNotMatch(web, /webMusrfitParameterPlotZIndex/);
assert.match(root, /bringMusrfitFloatingWindowToFront\(plotWindow\)/);
assert.match(web, /bringMusrfitFloatingWindowToFront\(plotWindow\)/);
assert.match(lib, /function bringMusrfitFloatingWindowToFront/);
assert.match(lib, /makeModelessDialogDraggable[\s\S]*bringMusrfitFloatingWindowToFront\(dialog\)/);
assert.match(lib, /showJobLogWindow[\s\S]*bringMusrfitFloatingWindowToFront\(logWindow\)/);
assert.match(lib, /showJobLogWindow[\s\S]*scrollTop\s*=\s*logText\.scrollHeight/);
assert.match(lib, /showQuickStartHelp[\s\S]*bringMusrfitFloatingWindowToFront\(dialog\)/);
assert.match(css, /\.main-action-bar\s*\{[\s\S]*?z-index:\s*900/);
assert.match(css, /\.job-log-window\s*\{[\s\S]*?z-index:\s*1100/);
assert.match(css, /\.quick-start-dialog\s*\{[\s\S]*?z-index:\s*1100/);
}
const lib = loadLibrary();
testSharedLayerCounter(lib);
testEveryBrowserWindowUsesTheManager();
console.log("Browser floating-window layering tests passed");