/**
 * Tests for collection_details.js — getProviderLabel.
 *
 * Tiny pure helper that maps an embedding-provider value to a
 * user-facing label, falling back to the raw value, then to a
 * default sentinel. Used in the collection-details page header.
 */

let getProviderLabel;

beforeAll(async () => {
    // collection_details.js has a DOMContentLoaded listener that
    // queries DOM elements that don't exist in the test env. The event
    // has typically already fired in happy-dom by import time, so the
    // listener never runs. Stub fetch defensively just in case.
    globalThis.fetch = vi.fn(() =>
        Promise.resolve({ ok: true, json: () => Promise.resolve({}) })
    );

    await import('@js/collection_details.js');
    getProviderLabel = window.getProviderLabel;
});

describe('getProviderLabel', () => {
    it('maps known provider keys to their friendly labels', () => {
        expect(getProviderLabel('sentence_transformers')).toBe('Sentence Transformers');
        expect(getProviderLabel('ollama')).toBe('Ollama');
        expect(getProviderLabel('openai')).toBe('OpenAI');
        expect(getProviderLabel('anthropic')).toBe('Anthropic');
        expect(getProviderLabel('cohere')).toBe('Cohere');
    });

    it('returns the input verbatim for unknown keys (so the UI shows the raw value)', () => {
        expect(getProviderLabel('huggingface')).toBe('huggingface');
        expect(getProviderLabel('local-custom-provider')).toBe('local-custom-provider');
    });

    it('falls back to "Not configured" for null', () => {
        expect(getProviderLabel(null)).toBe('Not configured');
    });

    it('falls back to "Not configured" for undefined', () => {
        expect(getProviderLabel(undefined)).toBe('Not configured');
    });

    it('falls back to "Not configured" for the empty string', () => {
        // '' is falsy and not in the map, so both `providerMap[v]` and the
        // `providerValue` fallback fail, landing on the sentinel.
        expect(getProviderLabel('')).toBe('Not configured');
    });
});
