Files
muSRFlow/tests/help-window.test.js
T
salman 95b0cd8dcc Illustrate user manual and include documentation in web deployment
Add real pre-fit UI screenshots, workflow diagrams, accessible captions, and image maintenance instructions. Correct run-count examples and rebuild the tracked HTML and PDF manuals.

Deploy the complete generated HTML manual with readable permissions. Check for missing documentation before modifying installed files and cover deployment, updates, and missing-doc failures with regression tests.
2026-10-30 16:25:53 +01:00

109 lines
6.0 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 os = require("os");
const { spawnSync } = require("child_process");
const repoRoot = path.resolve(__dirname, "..");
function testSharedHelpWindowInfrastructure() {
const main = fs.readFileSync(path.join(repoRoot, "main.js"), "utf8");
const lib = fs.readFileSync(path.join(repoRoot, "muSRFitlib.js"), "utf8");
const elec = fs.readFileSync(path.join(repoRoot, "muSRFitelec.js"), "utf8");
const html = fs.readFileSync(path.join(repoRoot, "index.html"), "utf8");
const help = fs.readFileSync(path.join(repoRoot, "quick-start.html"), "utf8");
const deploy = fs.readFileSync(path.join(repoRoot, "scripts", "deploy-web.sh"), "utf8");
assert.match(main, /function createAuxiliaryWindow/);
assert.match(main, /createParameterPlotWindow[\s\S]*createAuxiliaryWindow/);
assert.match(main, /ipcMain\.on\("openQuickStartWindow"/);
assert.match(main, /file: "quick-start\.html"/);
assert.match(elec, /function openElectronAuxiliaryWindow/);
assert.match(elec, /parameterPlot: "openParameterPlotWindow"/);
assert.match(elec, /quickStart: "openQuickStartWindow"/);
assert.match(lib, /openElectronAuxiliaryWindow\("quickStart"/);
assert.match(lib, /dialog\.show\(\)/);
assert.doesNotMatch(lib, /quickStartDialog[\s\S]{0,500}showModal/);
assert.match(html, /class="web-plot-window quick-start-dialog"/);
assert.match(html, /id="quickStartFrame"/);
assert.match(help, /id="helpRuns"/);
assert.match(help, /id="helpParams"/);
assert.match(help, /quickStartSection/);
assert.match(help, /class="quick-start-footer"/);
assert.match(help, /zaher\.salman@psi\.ch/);
assert.match(help, /https:\/\/musruser\.psi\.ch\/muSRFlow\/docs\//);
assert.match(help, /id="helpAbout"/);
assert.match(help, /About muSRFlow/);
assert.match(help, /id="musrflowVersion"/);
assert.match(help, /setVersion\(payload && payload\.version\)/);
assert.match(main, /version: app\.getVersion\(\)/);
assert.match(main, /shell\.openExternal/);
assert.match(main, /setWindowOpenHandler/);
assert.match(deploy, /quick-start\.html/);
assert.match(deploy, /__MUSRFLOW_VERSION__/);
assert.match(deploy, /node -p 'require\(process\.argv\[1\]\)\.version'/);
assert.doesNotMatch(lib, /musrfit-gui|bitbucket\.org\/zaher-salman\/musrfit-gui/);
}
function testDocumentationDeployment() {
// The Apache deployment script targets Linux; no real web directory is used.
if (process.platform !== "linux") return;
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "musrflow web deploy "));
try {
const source = path.join(temporary, "source");
const target = path.join(temporary, "installed");
for (const directory of ["scripts", "assets", "cgi"]) {
fs.mkdirSync(path.join(source, directory), { recursive: true });
}
fs.mkdirSync(target);
fs.copyFileSync(path.join(repoRoot, "scripts/deploy-web.sh"), path.join(source, "scripts/deploy-web.sh"));
const assets = ["index.html", "quick-start.html", "ZGUI.css", "muSRFitweb.js", "muSRFitRoot.js",
"muSRFitParameterPlot.js", "muSRFitlib.js", "assets/musrflow-favicon.png", "assets/musrflow-icon.png",
"cgi/single_musrfit.cgi", "cgi/musrfit_startup.xml"];
for (const file of assets) fs.writeFileSync(path.join(source, file), "fixture\n");
fs.writeFileSync(path.join(source, "package.json"), JSON.stringify({ version: "1.2.3" }));
const options = { encoding: "utf8", env: { ...process.env,
MUSRFLOW_WEB_TARGET: path.join(target, "web"),
MUSRFLOW_CGI_TARGET: path.join(target, "runner.cgi"),
MUSRFLOW_STARTUP_XML_TARGET: path.join(target, "startup.xml"),
MUSRFLOW_WEB_OWNER: "", MUSRFLOW_WEB_GROUP: "", MUSRFLOW_DATA_ROOT: "" } };
const script = path.join(source, "scripts/deploy-web.sh");
const missing = spawnSync("bash", [script], options);
assert.strictEqual(missing.status, 1, missing.stderr);
assert.match(missing.stderr, /HTML manual missing.*make -C/);
assert.deepStrictEqual(fs.readdirSync(target), [], "missing docs must not partially deploy the app");
const html = path.join(source, "docs/_build/html");
for (const directory of ["_static", "_sources"]) {
fs.mkdirSync(path.join(html, directory), { recursive: true, mode: 0o700 });
}
const pages = ["index.html", "searchindex.js", "_static/theme.css", "_sources/index.rst.txt"];
for (const file of pages) fs.writeFileSync(path.join(html, file), file, { mode: 0o600 });
const deployed = spawnSync("bash", [script], options);
assert.strictEqual(deployed.status, 0, deployed.stderr);
assert.match(deployed.stdout, /Installed muSRFlow HTML manual/);
for (const file of pages) {
const installed = path.join(target, "web/docs", file);
assert.strictEqual(fs.readFileSync(installed, "utf8"), file);
assert.strictEqual(fs.statSync(installed).mode & 0o777, 0o644);
}
assert.strictEqual(fs.statSync(path.join(target, "web/docs/_static")).mode & 0o777, 0o755);
fs.writeFileSync(path.join(html, "index.html"), "updated manual");
const updated = spawnSync("bash", [script], options);
assert.strictEqual(updated.status, 0, updated.stderr);
assert.strictEqual(fs.readFileSync(path.join(target, "web/docs/index.html"), "utf8"), "updated manual");
fs.writeFileSync(path.join(html, "index.html"), "");
assert.strictEqual(spawnSync("bash", [script], options).status, 1);
assert.strictEqual(fs.readFileSync(path.join(target, "web/docs/index.html"), "utf8"), "updated manual");
} finally {
fs.rmSync(temporary, { recursive: true, force: true });
}
}
testSharedHelpWindowInfrastructure();
testDocumentationDeployment();
console.log("help window tests passed");