~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
test(logpanel): cover toggle handler, filters, and queue draining (#3880)
LearningCircuit405c67727d23
diff --git a/tests/js/components/logpanel.test.js b/tests/js/components/logpanel.test.jsindex 9943b6a00b..870dec3402 100644--- a/tests/js/components/logpanel.test.js+++ b/tests/js/components/logpanel.test.js@@ -28,9 +28,12 @@ beforeAll(async () => {};// Pretend we're on a research page so the auto-initialize path runs.+ // Spread doesn't copy non-enumerable props off the Location prototype, so+ // explicitly include `search` and `hash` — initializeLogPanel reads them+ // for its debug-flag check (logpanel.js:321).Object.defineProperty(window, 'location', {configurable: true,- value: { ...window.location, pathname: '/' },+ value: { ...window.location, pathname: '/', search: '', hash: '' },});await import('@js/components/logpanel.js');@@ -62,9 +65,75 @@ beforeEach(() => {window._logPanelState.queuedLogs = [];window._logPanelState.expanded = false;window._logPanelState.logCount = 0;+ window._logPanelState.currentFilter = 'all';+ window._logPanelState.autoscroll = true;+ // Force re-binding of click handlers in tests that call initialize();+ // tests that only exercise loadLogs/addLog don't rely on this.+ window._logPanelState.initialized = false;+ window._logPanelState.connectedResearchId = null;}});+/**+ * Build the full log-panel DOM (filter buttons, autoscroll button, etc.)+ * inside an optional research-page wrapper, then call logPanel.initialize so+ * the click handlers from initializeLogPanel get bound.+ *+ * @param {Object} opts+ * @param {'progress'|'results'|null} [opts.page] - Wrap the panel in a+ * research page container so initializeLogPanel sees a research page.+ * 'progress' makes the toggle handler take the new CSS-flex branch from+ * PR #3851; 'results' takes the legacy autoscroll-hide branch.+ * @param {string} [opts.researchId] - Passed through to initialize();+ * each call uses a fresh ID to bypass the same-ID early return.+ */+function setupPanelDom({ page = 'progress', researchId } = {}) {+ // Reset the document body, then optionally wrap the panel in a research+ // page container so initializeLogPanel sees a research page.+ document.body.innerHTML = `+ <div class="ldr-collapsible-log-panel">+ <div class="ldr-log-panel-header" id="log-panel-toggle">+ <i class="fas fa-chevron-right ldr-toggle-icon"></i>+ </div>+ <div class="ldr-log-panel-content collapsed" id="log-panel-content">+ <div class="ldr-log-controls">+ <div class="ldr-log-filter">+ <div class="ldr-filter-buttons">+ <button class="ldr-small-btn ldr-selected">All</button>+ <button class="ldr-small-btn">Milestones</button>+ <button class="ldr-small-btn">Info</button>+ <button class="ldr-small-btn">Warning</button>+ <button class="ldr-small-btn">Errors</button>+ </div>+ </div>+ <button id="log-autoscroll-button" class="ldr-selected"></button>+ </div>+ <div class="ldr-console-log" id="console-log-container"></div>+ </div>+ </div>+ <template id="console-log-entry-template">+ <div class="ldr-console-log-entry">+ <span class="ldr-log-timestamp"></span>+ <span class="ldr-log-badge"></span>+ <span class="ldr-log-message"></span>+ </div>+ </template>+ `;++ if (page === 'progress' || page === 'results') {+ const wrapper = document.createElement('div');+ wrapper.id = page === 'progress' ? 'research-progress' : 'research-results';+ const panel = document.querySelector('.ldr-collapsible-log-panel');+ document.body.insertBefore(wrapper, panel);+ wrapper.appendChild(panel);+ }++ // Each test uses a fresh research ID so initialize() doesn't short-circuit+ // on the same-ID check at logpanel.js:44.+ const rid = researchId || `rid-${Math.random().toString(36).slice(2)}`;+ logPanel.initialize(rid);+}+function makeLiveEntry(message) {// Mimic what addLogEntryToPanel produces in the DOM.const entry = document.createElement('div');@@ -240,3 +309,190 @@ describe('addConsoleLog — placeholder removal', () => {expect(container.querySelector('.ldr-console-log-entry')).not.toBeNull();});});++/**+ * Toggle handler tests — locks in the contract introduced by PR #3851.+ *+ * The fix replaced a JS height calc with a CSS flex layout scoped to+ * `#research-progress`. The toggle handler now toggles a `.ldr-expanded`+ * class and clears any inline `style.height` on the progress page; on+ * non-progress pages it falls back to `style.height = 'auto'` and hides the+ * autoscroll button. These tests guard against a future refactor silently+ * re-introducing a JS-driven height formula or dropping the autoscroll-hide+ * branch.+ *+ * Note: CSS layout (no scrollbar at viewport heights, panel fills available+ * space) cannot be validated in happy-dom and remains a manual browser check.+ */+describe('toggle handler — progress page', () => {+ it('toggles .ldr-expanded on/off across two clicks', () => {+ setupPanelDom({ page: 'progress' });+ const panel = document.querySelector('.ldr-collapsible-log-panel');+ const toggle = document.getElementById('log-panel-toggle');++ toggle.click();+ expect(panel.classList.contains('ldr-expanded')).toBe(true);++ toggle.click();+ expect(panel.classList.contains('ldr-expanded')).toBe(false);+ });++ it('clears any inline style.height when expanding', () => {+ setupPanelDom({ page: 'progress' });+ const panel = document.querySelector('.ldr-collapsible-log-panel');+ // Simulate a stale inline height left over from the old JS-calc code+ // path. Expanding on a progress page must clear it so the new CSS+ // flex layout can size the panel.+ panel.style.height = '500px';++ document.getElementById('log-panel-toggle').click();++ expect(panel.style.height).toBe('');+ });++ it('enables autoscroll on first expand', () => {+ setupPanelDom({ page: 'progress' });++ document.getElementById('log-panel-toggle').click();++ // The handler sets autoscroll=false then calls toggleAutoscroll(),+ // which flips it to true. Locking this in guards against a refactor+ // that drops the toggleAutoscroll() call.+ expect(window._logPanelState.autoscroll).toBe(true);+ });+});++describe('toggle handler — non-progress page', () => {+ it('does not add .ldr-expanded when there is no #research-progress', () => {+ setupPanelDom({ page: 'results' });+ const panel = document.querySelector('.ldr-collapsible-log-panel');++ document.getElementById('log-panel-toggle').click();++ expect(panel.classList.contains('ldr-expanded')).toBe(false);+ });++ it('sets style.height to auto on expand', () => {+ setupPanelDom({ page: 'results' });+ const panel = document.querySelector('.ldr-collapsible-log-panel');++ document.getElementById('log-panel-toggle').click();++ expect(panel.style.height).toBe('auto');+ });++ it('hides the autoscroll button on expand', () => {+ setupPanelDom({ page: 'results' });++ document.getElementById('log-panel-toggle').click();++ const autoscrollButton = document.getElementById('log-autoscroll-button');+ expect(autoscrollButton.style.display).toBe('none');+ });+});++describe('filter buttons', () => {+ it('moves .ldr-selected to the clicked button', () => {+ setupPanelDom({ page: 'progress' });+ const buttons = document.querySelectorAll(+ '.ldr-log-filter .ldr-filter-buttons button'+ );+ const allBtn = Array.from(buttons).find(+ (b) => b.textContent.toLowerCase() === 'all'+ );+ const errorsBtn = Array.from(buttons).find(+ (b) => b.textContent.toLowerCase() === 'errors'+ );+ expect(allBtn.classList.contains('ldr-selected')).toBe(true);++ errorsBtn.click();++ expect(allBtn.classList.contains('ldr-selected')).toBe(false);+ expect(errorsBtn.classList.contains('ldr-selected')).toBe(true);+ });++ it('updates _logPanelState.currentFilter to the clicked type', () => {+ setupPanelDom({ page: 'progress' });+ const buttons = document.querySelectorAll(+ '.ldr-log-filter .ldr-filter-buttons button'+ );+ const errorsBtn = Array.from(buttons).find(+ (b) => b.textContent.toLowerCase() === 'errors'+ );++ errorsBtn.click();++ expect(window._logPanelState.currentFilter).toBe('errors');+ });++ it('hides entries whose log type does not match the filter', () => {+ setupPanelDom({ page: 'progress' });+ // Seed the container with one info and one error entry so we can+ // verify the filter actually toggles display on each.+ window._logPanelState.expanded = true;+ logPanel.addLog('an info message', 'info');+ logPanel.addLog('an error message', 'error');++ const container = document.getElementById('console-log-container');+ const entries = container.querySelectorAll('.ldr-console-log-entry');+ expect(entries.length).toBe(2);++ const errorsBtn = Array.from(+ document.querySelectorAll(+ '.ldr-log-filter .ldr-filter-buttons button'+ )+ ).find((b) => b.textContent.toLowerCase() === 'errors');+ errorsBtn.click();++ const infoEntry = container.querySelector('.ldr-log-info');+ const errorEntry = container.querySelector('.ldr-log-error');+ expect(infoEntry.style.display).toBe('none');+ expect(errorEntry.style.display).toBe('');+ });+});++describe('queued logs', () => {+ it('queues logs added while collapsed when no toggle handler is bound', () => {+ // No initialize() call → no auto-expand handler, so the synthetic+ // toggle.click() inside addConsoleLog is a no-op and the queue+ // accumulates. This is the path that triggers when logs arrive+ // before the panel finishes initializing.+ const container = document.getElementById('console-log-container');++ logPanel.addLog('queued before init', 'info');++ expect(window._logPanelState.queuedLogs.length).toBe(1);+ expect(container.querySelector('.ldr-console-log-entry')).toBeNull();+ });++ it('drains the queue when the panel is expanded', () => {+ setupPanelDom({ page: 'progress' });+ // Pre-seed a queued entry, simulating a log that arrived while the+ // panel was still collapsed.+ window._logPanelState.queuedLogs.push({+ id: 'pre-queued-1',+ time: new Date().toISOString(),+ message: 'pre-queued',+ type: 'info',+ metadata: { type: 'info' },+ });+ expect(window._logPanelState.queuedLogs.length).toBe(1);++ document.getElementById('log-panel-toggle').click();++ expect(window._logPanelState.queuedLogs.length).toBe(0);+ const container = document.getElementById('console-log-container');+ expect(container.querySelector('.ldr-console-log-entry')).not.toBeNull();+ });++ it('bypasses the queue when the panel is already expanded', () => {+ setupPanelDom({ page: 'progress' });+ window._logPanelState.expanded = true;++ logPanel.addLog('direct', 'info');++ expect(window._logPanelState.queuedLogs.length).toBe(0);+ const container = document.getElementById('console-log-container');+ expect(container.querySelector('.ldr-console-log-entry')).not.toBeNull();+ });+});