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.6 KB
Raw Blame
/**
 * Tests for pages/notes.js — stripMarkdownForPreview.
 *
 * The list endpoint sends the first 300 RAW characters of the note body as
 * content_preview, so the note cards used to render syntax soup:
 * "# Title Some **bold** [[Second note]] ## Open questions - item". The
 * card preview strips markdown down to plain text; the result is still
 * escapeHtml'd and rendered as text, so an imperfect strip degrades to
 * stray punctuation, never markup.
 */

let strip;

beforeAll(async () => {
    window.__VITEST_TEST__ = true;
    globalThis.safeFetch = vi.fn(() =>
        Promise.resolve({ json: () => Promise.resolve({ success: true, notes: [] }) })
    );
    globalThis.escapeHtml = (s) => String(s ?? '');
    // stripMarkdownForPreview delegates to window.formatting.stripMarkdownToText,
    // which the shared tests/js/setup.js loads for every test.
    await import('@js/pages/notes.js');
    strip = window.__notesTest.stripMarkdownForPreview;
});

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

describe('stripMarkdownForPreview', () => {
    it('strips the syntax soup the card previews used to show', () => {
        const raw = '# Research kickoff\n\nSome **bold** thoughts, with a [[Second note]] wiki-link.\n\n## Open questions\n- How does the cache behave?\n- Which retriever wins?';
        expect(strip(raw)).toBe(
            'Research kickoff Some bold thoughts, with a Second note wiki-link. Open questions How does the cache behave? Which retriever wins?'
        );
    });

    it('resolves wiki-link aliases and markdown links to their text', () => {
        expect(strip('See [[Real Title|the alias]] and [docs](https://x.test/d).'))
            .toBe('See the alias and docs.');
    });

    it('keeps image alt text and drops the URL', () => {
        expect(strip('![diagram](https://x.test/i.png) explains it')).toBe('diagram explains it');
    });

    it('unwraps inline code, emphasis, and strikethrough', () => {
        expect(strip('`code` *em* _also_ ~~gone~~ __strong__')).toBe('code em also gone strong');
    });

    it('drops blockquote markers and horizontal rules', () => {
        expect(strip('> quoted wisdom\n\n---\n\nafter the rule')).toBe('quoted wisdom after the rule');
    });

    it('passes plain text through unchanged (modulo whitespace collapse)', () => {
        expect(strip('The linked target note. Nothing fancy.')).toBe('The linked target note. Nothing fancy.');
    });

    it('returns empty string for null/undefined/empty', () => {
        expect(strip(null)).toBe('');
        expect(strip(undefined)).toBe('');
        expect(strip('')).toBe('');
    });
});