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.

3.7 KB
Raw Blame
/** Completed bootstrap parity for the migrated progress status endpoint. */

import '@js/config/urls.js';

const RESEARCH_ID = 'initial-completed-3299';

beforeEach(() => {
    document.title = 'Research in progress';
    document.body.innerHTML = `
        <div role="progressbar" aria-valuenow="0">
            <div id="progress-bar"></div>
        </div>
        <div id="progress-percentage"></div>
        <div id="status-text" class="ldr-status-indicator"></div>
        <div id="current-task"></div>
        <button id="cancel-research-btn"></button>
        <a id="view-results-btn" style="display: none"></a>
    `;
    window.RESEARCH_STATUS = {
        QUEUED: 'queued',
        IN_PROGRESS: 'in_progress',
        COMPLETED: 'completed',
        FAILED: 'failed',
        ERROR: 'error',
        CANCELLED: 'cancelled',
    };
    window.ResearchStates = {
        isTerminal: status => [
            'completed', 'failed', 'error', 'cancelled',
        ].includes(status),
        isCompleted: status => status === 'completed',
        isFailed: status => ['failed', 'error'].includes(status),
        isCancelled: status => status === 'cancelled',
        isInProgress: status => status === 'in_progress',
        formatStatus: status => status,
        logLevel: () => 'info',
    };
    window.socket = {
        subscribeToResearch: vi.fn(),
        onReconnect: vi.fn(),
        isUsingPolling: vi.fn(() => false),
    };
});

afterEach(() => {
    vi.restoreAllMocks();
    vi.unstubAllGlobals();
    delete window.api;
    delete window.ui;
    delete window.socket;
    delete window.ResearchStates;
    delete window.RESEARCH_STATUS;
    delete window.progressComponent;
    delete window.showNotification;
    document.body.replaceChildren();
});

it('restores result navigation, title, and overflow recovery from an initial completed status', async () => {
    vi.stubGlobal('URLBuilder', window.URLBuilder);
    vi.stubGlobal('ResearchStates', window.ResearchStates);
    vi.stubGlobal('Notification', { permission: 'denied' });
    vi.stubGlobal('URLValidator', {
        safeAssign: vi.fn((element, property, value) => {
            element.setAttribute(property, value);
        }),
    });
    const contextFetch = vi.fn().mockResolvedValue({
        ok: true,
        json: vi.fn().mockResolvedValue({
            status: 'success',
            data: { overview: { truncation_occurred: false } },
        }),
    });
    vi.stubGlobal('fetch', contextFetch);
    vi.spyOn(window.URLBuilder, 'extractResearchIdFromPattern')
        .mockReturnValue(RESEARCH_ID);
    window.api = {
        getResearchStatus: vi.fn()
            .mockResolvedValueOnce({
                status: 'in_progress',
                progress: 75,
                current_task: 'Finishing report',
            })
            .mockResolvedValueOnce({
                status: 'completed',
                progress: 100,
            }),
    };
    window.ui = {
        updateFavicon: vi.fn(),
        showError: vi.fn(),
    };

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

    await vi.waitFor(() => {
        expect(document.getElementById('view-results-btn').getAttribute('href'))
            .toBe(`/results/${RESEARCH_ID}`);
    });
    expect(document.getElementById('view-results-btn').style.display)
        .toBe('inline-block');
    expect(document.getElementById('cancel-research-btn').style.display)
        .toBe('none');
    expect(document.getElementById('current-task').textContent)
        .toBe('Research completed successfully');
    expect(document.title).toBe('Research (100%) - Local Deep Research');
    expect(contextFetch).toHaveBeenCalledWith(
        `/api/research/${RESEARCH_ID}/context-overflow`,
    );
});