From 844311b4759f34af98bb96772899cff3642d9324 Mon Sep 17 00:00:00 2001 From: Brian Krabach Date: Mon, 30 Mar 2026 22:29:30 -0700 Subject: [PATCH] feat: add federation state globals and test-only helpers to app.js Add new module-level globals: - let _gridViewMode = 'flat' - let _activeFilterDevice = 'all' Add test-only helper functions: - _setSources(sources): sets internal _sources array - _setServerSettings(settings): sets internal _serverSettings - _getGridViewMode(): returns current _gridViewMode value - _getSources(): returns current _sources array All 4 helpers exported in module.exports. Tests added (all passing, 143/143): - '_setSources sets internal _sources array' - '_setServerSettings sets internal _serverSettings' - '_getGridViewMode returns current _gridViewMode value' - '_getSources returns current _sources array' Task: task-3 (federation state helpers) --- muxplex/frontend/app.js | 18 ++++++++++++++++++ muxplex/frontend/tests/test_app.mjs | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/muxplex/frontend/app.js b/muxplex/frontend/app.js index bbfc9ae..be09494 100644 --- a/muxplex/frontend/app.js +++ b/muxplex/frontend/app.js @@ -134,6 +134,8 @@ var _previewSessionName = null; // track by NAME, not DOM element let _sources = []; let _settingsOpen = false; let _serverSettings = null; +let _gridViewMode = 'flat'; +let _activeFilterDevice = 'all'; const DISPLAY_SETTINGS_KEY = 'muxplex.display'; const DISPLAY_DEFAULTS = { fontSize: 14, @@ -1671,6 +1673,18 @@ function _setViewMode(mode) { _viewMode = mode; } +/** Test-only: set _sources directly. */ +function _setSources(sources) { _sources = sources; } + +/** Test-only: set _serverSettings directly. */ +function _setServerSettings(settings) { _serverSettings = settings; } + +/** Test-only: get _gridViewMode. */ +function _getGridViewMode() { return _gridViewMode; } + +/** Test-only: get _sources. */ +function _getSources() { return _sources; } + document.addEventListener('DOMContentLoaded', () => { initDeviceId(); applyDisplaySettings(loadDisplaySettings()); @@ -1759,5 +1773,9 @@ if (typeof module !== 'undefined' && module.exports) { // Test-only helpers _setCurrentSessions, _setViewMode, + _setSources, + _setServerSettings, + _getGridViewMode, + _getSources, }; } diff --git a/muxplex/frontend/tests/test_app.mjs b/muxplex/frontend/tests/test_app.mjs index aaf70d8..5ef0479 100644 --- a/muxplex/frontend/tests/test_app.mjs +++ b/muxplex/frontend/tests/test_app.mjs @@ -2004,6 +2004,28 @@ test('createNewSession polls for session before auto-opening (not immediate setT ); }); +// --- federation state helpers (task-3) --- + +test('_setSources sets internal _sources array', () => { + assert.doesNotThrow(() => app._setSources([{ url: '', name: 'test' }])); +}); + +test('_setServerSettings sets internal _serverSettings', () => { + assert.doesNotThrow(() => app._setServerSettings({ sort_order: 'recent' })); +}); + +test('_getGridViewMode returns current _gridViewMode value', () => { + assert.strictEqual(typeof app._getGridViewMode(), 'string', '_getGridViewMode should return a string'); + assert.strictEqual(app._getGridViewMode(), 'flat', '_gridViewMode should default to flat'); +}); + +test('_getSources returns current _sources array', () => { + app._setSources([{ url: 'http://test', name: 'Test' }]); + const sources = app._getSources(); + assert.ok(Array.isArray(sources), '_getSources should return an array'); + assert.strictEqual(sources[0].url, 'http://test', '_getSources should return value set by _setSources'); +}); + // --- buildSources --- test('buildSources returns only local source when no remote_instances', () => {