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.

1.9 KB
Raw Blame
/**
 * Tests for pages/note-detail.js — renderVersionHistory null change_type.
 *
 * renderVersionHistory builds the panel with `versions.map(... v.change_type
 * .replace('_',' ') ...)`. A version row with a null/undefined change_type
 * threw inside the map, so the assignment `container.innerHTML = ...` never
 * ran and the ENTIRE version panel broke (not just the one row). The fix
 * defaults a missing change_type to 'unknown' so the panel still renders.
 *
 * 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 }) })
    );
    globalThis.escapeHtml = (s) => String(s ?? '');
    globalThis.formatDateTime = (s) => String(s ?? '');

    await import('@js/pages/note-detail.js');
    hook = window.__noteDetailTest;
});

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

beforeEach(() => {
    document.body.innerHTML = '<div id="ldr-versions-list"></div>';
});

function container() {
    return document.getElementById('ldr-versions-list').innerHTML;
}

describe('renderVersionHistory — null change_type', () => {
    it('renders the panel (with an "unknown" badge) instead of throwing on a null change_type', () => {
        const versions = [
            { id: 'v1', version_number: 2, change_type: 'manual_save', created_at: 'x' },
            { id: 'v2', version_number: 1, change_type: null, created_at: 'y' },
        ];

        // Pre-fix this threw inside .map and left the panel unrendered.
        expect(() => hook.renderVersionHistory(versions)).not.toThrow();

        const html = container();
        // Both rows rendered; the null one degrades to "unknown".
        expect(html).toContain('Version 2');
        expect(html).toContain('Version 1');
        expect(html).toContain('manual save');
        expect(html).toContain('unknown');
    });
});