refactor: code quality improvements for task-7 settings effects

- Extract getVisibleSessions() helper to consolidate hidden-session
  filter used by renderGrid() and renderSidebar() (DRY reduction)
- Add comment to terminal.js magic literal 600 noting it matches
  MOBILE_THRESHOLD in app.js
- Move TERMINAL_JS_PATH and _TERMINAL_JS module fixtures to the top
  of the test file alongside JS_PATH and _JS for consistency
- Strengthen test_render_grid_uses_visible_for_empty_state_check to
  assert visible.length specifically, distinguishing it from
  test_render_grid_creates_visible_array
- Update renderGrid/renderSidebar filter tests to assert getVisibleSessions()
  call; add test_get_visible_sessions_filters_hidden_sessions to cover
  the extracted helper directly
This commit is contained in:
Brian Krabach
2026-03-30 02:28:54 -07:00
parent 142c68d644
commit 851036bac0
18 changed files with 47 additions and 28 deletions
+13 -6
View File
@@ -448,6 +448,17 @@ function buildSidebarHTML(session, currentSession) {
);
}
/**
* Returns sessions with hidden session names removed.
* Consolidates the hidden-session filter used by all render paths.
* @param {object[]} sessions
* @returns {object[]}
*/
function getVisibleSessions(sessions) {
const hidden = (_serverSettings && _serverSettings.hidden_sessions) || [];
return (sessions || []).filter((s) => !hidden.includes(s.name));
}
/**
* Render the session sidebar list. Only renders in fullscreen view.
* Shows empty state when no sessions exist.
@@ -461,9 +472,7 @@ function renderSidebar(sessions, currentSession) {
const list = $('sidebar-list');
if (!list) return;
// Filter hidden sessions
const hiddenSessions = (_serverSettings && _serverSettings.hidden_sessions) || [];
const visible = (sessions || []).filter((s) => !hiddenSessions.includes(s.name));
const visible = getVisibleSessions(sessions);
if (visible.length === 0) {
list.innerHTML = '<div class="sidebar-empty">No sessions</div>';
@@ -594,9 +603,7 @@ function renderGrid(sessions) {
const grid = $('session-grid');
const emptyState = $('empty-state');
// Filter hidden sessions
const hiddenSessions = (_serverSettings && _serverSettings.hidden_sessions) || [];
const visible = (sessions || []).filter((s) => !hiddenSessions.includes(s.name));
const visible = getVisibleSessions(sessions);
if (visible.length === 0) {
if (grid) grid.innerHTML = '';
+1 -1
View File
@@ -150,7 +150,7 @@ function createTerminal() {
}
} catch (_) { /* use default 14 */ }
const mobile = window.innerWidth < 600;
const mobile = window.innerWidth < 600; // matches MOBILE_THRESHOLD in app.js
const fontSize = mobile ? Math.min(storedFontSize, 12) : storedFontSize;
_term = new window.Terminal({