PlotDirector/PlotLine.Tests/Browser/pwa-display-mode.cjs
Nick Beckley e48889ac05 Complete desktop workspaces, context menus and plot health
Commit the pending application, help and browser regression work. Pin the patched PKCS dependency for the production release.
2026-10-31 09:27:04 +00:00

24 lines
1.7 KiB
JavaScript

const vm = require('node:vm');
const fs = require('node:fs');
const path = require('node:path');
const assert = require('node:assert/strict');
const source = fs.readFileSync(path.join(__dirname, '../../PlotLine/wwwroot/js/application-display-mode.js'), 'utf8');
for (const storageThrows of [false, true]) for (const standalone of [false, true]) {
const root = { dataset: {} }, listeners = {}, changes = [];
const media = { matches: standalone, addEventListener(name, fn) { listeners.media = fn; } };
let stored = standalone ? 'browser' : 'standalone';
const window = { matchMedia: () => media, addEventListener(name, fn) { listeners[name] = fn; }, dispatchEvent(event) { changes.push(event.detail.standalone); } };
vm.runInNewContext(source, { window, document: { documentElement: root }, navigator: {}, CustomEvent: function(name, options) { this.detail = options.detail; }, sessionStorage: {
getItem() { if (storageThrows) throw Error('storage denied'); return stored; },
setItem(key, value) { if (storageThrows) throw Error('storage denied'); stored = value; }
} });
assert.equal(root.dataset.standalone, String(standalone));
assert.equal(window.PlotDirectorPwa.standalone, standalone);
listeners.pageshow(); assert.equal(changes.length, 1, 'same-mode restoration does not reconstruct ribbon');
media.matches = !standalone; listeners.media();
assert.equal(root.dataset.standalone, String(!standalone));
assert.equal(window.PlotDirectorPwa.standalone, !standalone);
if (!storageThrows) assert.equal(stored, standalone ? 'browser' : 'standalone');
}
console.log('PASS early display mode: authoritative stale-hint correction, storage denial, media change and pageshow stability.');