Skip to content

~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.

2.8 KB
Raw Blame
/**
 * Tests for pages/note-detail.js — loadNoteCollections + showFactCheckStatus.
 *
 * loadNoteCollections loads the note's collections and derives note.is_indexed
 * from membership (indexed iff at least one collection has it indexed), keeping
 * the badge in sync after both index and un-index. showFactCheckStatus renders
 * the status message + the claims list into the AI panel.
 *
 * Driven via the production-inert window.__noteDetailTest hook.
 */

let hook;

beforeAll(async () => {
    window.__VITEST_TEST__ = true;
    globalThis.safeFetch = vi.fn(() =>
        Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true, collections: [] }) })
    );
    globalThis.escapeHtml = (s) => String(s ?? '');
    await import('@js/pages/note-detail.js');
    hook = window.__noteDetailTest;
});

afterAll(() => {
    delete window.__VITEST_TEST__;
});

describe('loadNoteCollections — is_indexed derivation', () => {
    beforeEach(() => {
        document.body.innerHTML =
            '<div id="ldr-note-collections"><button class="ldr-add-collection-btn"></button></div>' +
            '<span id="note-indexed"></span>';
        hook.setNote({ id: 'note-1', title: 'T', content: 'c', tags: [], is_indexed: false });
    });

    it('marks the note indexed when any collection has it indexed', async () => {
        globalThis.safeFetch = vi.fn(() =>
            Promise.resolve({ json: () => Promise.resolve({
                success: true,
                collections: [{ id: 'c1', name: 'A', indexed: false }, { id: 'c2', name: 'B', indexed: true }],
            }) })
        );

        await hook.loadNoteCollections();

        expect(hook.getNote().is_indexed).toBe(true);
    });

    it('marks the note not-indexed when no collection has it indexed', async () => {
        hook.setNote({ id: 'note-1', title: 'T', content: 'c', tags: [], is_indexed: true });
        globalThis.safeFetch = vi.fn(() =>
            Promise.resolve({ json: () => Promise.resolve({
                success: true,
                collections: [{ id: 'c1', name: 'A', indexed: false }],
            }) })
        );

        await hook.loadNoteCollections();

        expect(hook.getNote().is_indexed).toBe(false);
    });
});

describe('showFactCheckStatus', () => {
    it('renders the status message and the claims list', () => {
        document.body.innerHTML =
            '<div id="ldr-ai-results-panel"><span id="ldr-ai-results-title"></span>' +
            '<div id="ldr-ai-results-content"></div></div>';

        hook.showFactCheckStatus('Researching…', ['The sky is blue', 'Water is wet']);

        const html = document.getElementById('ldr-ai-results-content').innerHTML;
        expect(html).toContain('Researching');
        expect(html).toContain('The sky is blue');
        expect(html).toContain('Water is wet');
    });
});