~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(js): add vitest coverage for three pure Tier-1 helpers (#4297)
LearningCircuit9592f33130a8
diff --git a/tests/js/components/context-overflow-shared.test.js b/tests/js/components/context-overflow-shared.test.jsnew file mode 100644index 0000000000..81080a0db9--- /dev/null+++ b/tests/js/components/context-overflow-shared.test.js@@ -0,0 +1,51 @@+/**+ * Tests for components/context-overflow-shared.js+ *+ * Pure HTML renderer for the truncation status badge shown in+ * context-overflow details. The single branch (count > 0 vs not) drives+ * which CSS variable the badge uses, so a regression here would change+ * the surfaced color and wording.+ */++import '@js/components/context-overflow-shared.js';++const { renderTruncationBadge } = window.contextOverflowShared;++describe('renderTruncationBadge', () => {+ it('returns the "No truncation" badge when count is 0', () => {+ const html = renderTruncationBadge(0);+ expect(html).toContain('--success-color');+ expect(html).toContain('No truncation');+ expect(html).not.toContain('--error-color');+ });++ it('returns the "Yes" badge with the count when count > 0', () => {+ const html = renderTruncationBadge(5);+ expect(html).toContain('--error-color');+ expect(html).toContain('Yes (5 requests)');+ });++ it('treats null as 0 (no truncation)', () => {+ expect(renderTruncationBadge(null)).toContain('No truncation');+ });++ it('treats undefined as 0 (no truncation)', () => {+ expect(renderTruncationBadge(undefined)).toContain('No truncation');+ });++ it('treats a non-numeric string as 0 (no truncation)', () => {+ // Number('foo') => NaN => falsy => || 0+ expect(renderTruncationBadge('foo')).toContain('No truncation');+ });++ it('coerces a numeric string into a number for the count', () => {+ const html = renderTruncationBadge('42');+ expect(html).toContain('--error-color');+ expect(html).toContain('Yes (42 requests)');+ });++ it('treats negative numbers as no truncation (-3 is truthy but > 0 fails)', () => {+ // Number(-3) === -3 (truthy, so || 0 keeps -3), but the > 0 branch fails => returns success.+ expect(renderTruncationBadge(-3)).toContain('No truncation');+ });+});diff --git a/tests/js/components/subscription-manager.test.js b/tests/js/components/subscription-manager.test.jsnew file mode 100644index 0000000000..ba422b52e7--- /dev/null+++ b/tests/js/components/subscription-manager.test.js@@ -0,0 +1,69 @@+/**+ * Tests for components/subscription-manager.js — formatTimeUntil.+ *+ * Pure math that powers the "Next refresh" label on subscription cards.+ * Boundary behavior (≤0 collapses to "Now", minute/hour/day transitions)+ * has bitten this kind of code before; lock it down here so future+ * refactors of the display label don't silently flip a day boundary.+ */++import '@js/components/subscription-manager.js';++let formatTimeUntil;++beforeAll(() => {+ // The module wires up its singleton inside a DOMContentLoaded listener.+ // happy-dom usually fires the lifecycle event before the import settles,+ // so dispatch it manually if the singleton isn't there yet.+ if (!window.subscriptionManager) {+ document.dispatchEvent(new Event('DOMContentLoaded'));+ }+ formatTimeUntil = window.subscriptionManager.formatTimeUntil.bind(+ window.subscriptionManager+ );+});++describe('subscriptionManager.formatTimeUntil', () => {+ it('returns "Now" for 0 ms', () => {+ expect(formatTimeUntil(0)).toBe('Now');+ });++ it('returns "Now" for negative ms (overdue subscription)', () => {+ expect(formatTimeUntil(-5000)).toBe('Now');+ expect(formatTimeUntil(-86_400_000)).toBe('Now');+ });++ it('returns minutes for sub-hour durations', () => {+ expect(formatTimeUntil(2 * 60 * 1000)).toBe('2m');+ expect(formatTimeUntil(59 * 60 * 1000)).toBe('59m');+ });++ it('returns "0m" for sub-minute positive durations', () => {+ // 30 seconds — too short for a minute, but > 0 so not "Now".+ expect(formatTimeUntil(30_000)).toBe('0m');+ });++ it('returns hours once at the 1-hour boundary', () => {+ expect(formatTimeUntil(60 * 60 * 1000)).toBe('1h');+ expect(formatTimeUntil(23 * 60 * 60 * 1000)).toBe('23h');+ });++ it('returns days once at the 24-hour boundary', () => {+ expect(formatTimeUntil(24 * 60 * 60 * 1000)).toBe('1d');+ expect(formatTimeUntil(7 * 24 * 60 * 60 * 1000)).toBe('7d');+ });++ it('handles very large durations without overflow', () => {+ // 999 days+ expect(formatTimeUntil(999 * 24 * 60 * 60 * 1000)).toBe('999d');+ });++ it('floors at unit boundaries — 25h reports as 1d, not 1h', () => {+ expect(formatTimeUntil(25 * 60 * 60 * 1000)).toBe('1d');+ });++ it('floors just under the next unit (59m59s stays minutes)', () => {+ const ms = 59 * 60 * 1000 + 59 * 1000;+ expect(formatTimeUntil(ms)).toBe('59m');+ });+});diff --git a/tests/js/mobile-navigation.test.js b/tests/js/mobile-navigation.test.jsnew file mode 100644index 0000000000..f492407c86--- /dev/null+++ b/tests/js/mobile-navigation.test.js@@ -0,0 +1,173 @@+/**+ * Tests for mobile-navigation.js — pure helpers on the MobileNavigation class.+ *+ * checkViewport drives whether the mobile bottom-nav is shown at all,+ * and isCurrentPage decides which tab is highlighted. Both are pure+ * reads of `window.innerWidth` / `window.location.pathname`, so they+ * are testable without touching the rest of the class wiring.+ *+ * The module auto-instantiates a singleton when imported (`initMobileNav`+ * runs immediately because happy-dom reports `document.readyState === 'complete'`).+ * That constructor path renders HTML that references the global `URLS`+ * config, so we stub it before the dynamic import.+ */++let MobileNavigation;++beforeAll(async () => {+ // Minimal URLS stub — only the PAGES keys the constructor's bottom-nav+ // and sheet-menu templates dereference.+ globalThis.URLS = {+ PAGES: {+ HOME: '/',+ HISTORY: '/history/',+ LIBRARY: '/library',+ NEWS: '/news',+ NEWS_SUBSCRIPTIONS: '/news/subscriptions',+ COLLECTIONS: '/library/collections',+ METRICS: '/metrics',+ BENCHMARK: '/benchmark',+ BENCHMARK_RESULTS: '/benchmark/results',+ EMBEDDING_SETTINGS: '/settings/embedding',+ SETTINGS: '/settings',+ },+ };++ await import('@js/mobile-navigation.js');+ MobileNavigation = window.MobileNavigation;+});++describe('MobileNavigation.checkViewport', () => {+ let originalInnerWidth;++ beforeEach(() => {+ originalInnerWidth = window.innerWidth;+ });++ afterEach(() => {+ Object.defineProperty(window, 'innerWidth', {+ value: originalInnerWidth,+ configurable: true,+ writable: true,+ });+ });++ function setInnerWidth(px) {+ Object.defineProperty(window, 'innerWidth', {+ value: px,+ configurable: true,+ writable: true,+ });+ }++ it('returns true and sets state.isVisible=true below the breakpoint', () => {+ const nav = new MobileNavigation();+ setInnerWidth(500);+ expect(nav.checkViewport()).toBe(true);+ expect(nav.state.isVisible).toBe(true);+ });++ it('returns false and sets state.isVisible=false at the breakpoint (768)', () => {+ // Uses strict < (not <=) — 768px is tablet, sidebar should be visible.+ const nav = new MobileNavigation();+ setInnerWidth(768);+ expect(nav.checkViewport()).toBe(false);+ expect(nav.state.isVisible).toBe(false);+ });++ it('returns false above the breakpoint', () => {+ const nav = new MobileNavigation();+ setInnerWidth(1280);+ expect(nav.checkViewport()).toBe(false);+ expect(nav.state.isVisible).toBe(false);+ });++ it('respects a custom breakpoint passed via options', () => {+ const nav = new MobileNavigation({ breakpoint: 1024 });+ setInnerWidth(900);+ expect(nav.checkViewport()).toBe(true);+ setInnerWidth(1024);+ expect(nav.checkViewport()).toBe(false);+ });+});++describe('MobileNavigation.isCurrentPage', () => {+ let originalLocation;++ beforeAll(() => {+ originalLocation = window.location;+ });++ afterAll(() => {+ Object.defineProperty(window, 'location', {+ value: originalLocation,+ configurable: true,+ });+ });++ function setPath(pathname) {+ Object.defineProperty(window, 'location', {+ value: { pathname },+ configurable: true,+ writable: true,+ });+ }++ function nav() {+ return new MobileNavigation();+ }++ it('treats the research tab as active only on the bare root path', () => {+ setPath('/');+ expect(nav().isCurrentPage({ id: 'research' })).toBe(true);++ setPath('/something');+ expect(nav().isCurrentPage({ id: 'research' })).toBe(false);+ });++ it('matches the history tab on /history and any sub-path', () => {+ setPath('/history');+ expect(nav().isCurrentPage({ id: 'history' })).toBe(true);++ setPath('/history/abc-123');+ expect(nav().isCurrentPage({ id: 'history' })).toBe(true);++ setPath('/');+ expect(nav().isCurrentPage({ id: 'history' })).toBe(false);+ });++ it('matches the library tab on /library prefix', () => {+ setPath('/library');+ expect(nav().isCurrentPage({ id: 'library' })).toBe(true);++ setPath('/library/collections/42');+ expect(nav().isCurrentPage({ id: 'library' })).toBe(true);+ });++ it('matches the metrics tab on /metrics prefix', () => {+ setPath('/metrics');+ expect(nav().isCurrentPage({ id: 'metrics' })).toBe(true);++ setPath('/metrics/dashboard');+ expect(nav().isCurrentPage({ id: 'metrics' })).toBe(true);+ });++ it('matches the news tab on /news prefix', () => {+ setPath('/news');+ expect(nav().isCurrentPage({ id: 'news' })).toBe(true);++ setPath('/news/subscriptions');+ expect(nav().isCurrentPage({ id: 'news' })).toBe(true);+ });++ it('returns false for unknown tab ids', () => {+ setPath('/');+ expect(nav().isCurrentPage({ id: 'unknown' })).toBe(false);+ });++ it('does not cross-match: /library should not light up history or news', () => {+ setPath('/library');+ expect(nav().isCurrentPage({ id: 'history' })).toBe(false);+ expect(nav().isCurrentPage({ id: 'news' })).toBe(false);+ });+});