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
/** Direct runtime contracts for the results-page help modal. */

let reportButton;
let modal;

beforeAll(async () => {
    document.body.innerHTML = `
        <button id="report-issue-btn">Help improve</button>
        <div id="reportIssueModal"><div id="modal-content">Content</div></div>
    `;
    reportButton = document.getElementById('report-issue-btn');
    modal = document.getElementById('reportIssueModal');

    await import('@js/components/report_issue.js');
    document.dispatchEvent(new Event('DOMContentLoaded'));
});

afterEach(() => {
    delete globalThis.bootstrap;
    modal.style.display = '';
    modal.classList.remove('show');
});

afterAll(() => {
    document.body.innerHTML = '';
});

it('opens and closes the modal without Bootstrap', () => {
    reportButton.click();

    expect(modal.style.display).toBe('block');
    expect(modal.classList.contains('show')).toBe(true);

    modal.dispatchEvent(new MouseEvent('click', { bubbles: true }));
    expect(modal.style.display).toBe('none');
    expect(modal.classList.contains('show')).toBe(false);
});

it('does not close when a click bubbles from the modal contents', () => {
    reportButton.click();
    document.getElementById('modal-content').click();

    expect(modal.style.display).toBe('block');
    expect(modal.classList.contains('show')).toBe(true);
});

it('delegates modal ownership to the checked-in Bootstrap API when present', () => {
    const show = vi.fn();
    const hide = vi.fn();
    const Modal = vi.fn(function BootstrapModal() {
        return { show };
    });
    Modal.getInstance = vi.fn(() => ({ hide }));
    globalThis.bootstrap = { Modal };

    reportButton.click();
    expect(Modal).toHaveBeenCalledWith(modal);
    expect(show).toHaveBeenCalledOnce();

    modal.dispatchEvent(new MouseEvent('click', { bubbles: true }));
    expect(Modal.getInstance).toHaveBeenCalledWith(modal);
    expect(hide).toHaveBeenCalledOnce();
});