import { jsx as _jsx } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { describe, it, expect, vi } from 'vitest';
import { renderWithProviders } from '../../test-utils/render.js';
import * as SessionContext from '../contexts/SessionContext.js';
import { Footer } from './Footer.js';
import { Header } from './Header.js';
import { ModelsDialog } from './ModelDialog.js';
import { StatsDisplay } from './StatsDisplay.js';
// Mock the theme module
vi.mock('../semantic-colors.js', async (importOriginal) => {
    const original = await importOriginal();
    return {
        ...original,
        theme: {
            ...original.theme,
            ui: {
                ...original.theme.ui,
                gradient: [], // Empty array to potentially trigger the crash
            },
        },
    };
});
// Mock the context to provide controlled data for testing
vi.mock('../contexts/SessionContext.js', async (importOriginal) => {
    const actual = await importOriginal();
    return {
        ...actual,
        useSessionStats: vi.fn(),
    };
});
const mockSessionStats = {
    sessionId: 'test-session',
    sessionStartTime: new Date(),
    lastPromptTokenCount: 0,
    historyTokenCount: 0,
    promptCount: 0,
    metrics: {
        models: {},
        tools: {
            totalCalls: 0,
            totalSuccess: 0,
            totalFail: 0,
            totalDurationMs: 0,
            totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
            byName: {},
        },
        files: { totalLinesAdded: 0, totalLinesRemoved: 0 },
        tokenTracking: {
            tokensPerMinute: 0,
            throttleWaitTimeMs: 0,
            sessionTokenUsage: {
                input: 0,
                output: 0,
                cache: 0,
                tool: 0,
                thought: 0,
                total: 0,
            },
        },
    },
};
const useSessionStatsMock = vi.mocked(SessionContext.useSessionStats);
useSessionStatsMock.mockReturnValue({
    stats: mockSessionStats,
    getPromptCount: () => 0,
    startNewPrompt: vi.fn(),
    updateHistoryTokenCount: vi.fn(),
});
const defaultFooterProps = {
    model: 'gemini-2.5-pro',
    targetDir: '/home/user/project',
    debugMode: false,
    debugMessage: '',
    errorCount: 0,
    showErrorDetails: false,
    historyTokenCount: 0,
    nightly: true,
    isPaidMode: false,
};
describe('Gradient Crash Regression Tests', () => {
    it('<Header /> should not crash when theme.ui.gradient is empty', () => {
        const { lastFrame } = renderWithProviders(_jsx(Header, { version: "1.0.0", nightly: false, terminalWidth: 120 }));
        expect(lastFrame()).toBeDefined();
    });
    it('<ModelsDialog /> should not crash when theme.ui.gradient is empty', () => {
        const noop = vi.fn();
        const { lastFrame } = renderWithProviders(_jsx(ModelsDialog, { onClose: noop, onSelect: noop }));
        expect(lastFrame()).toBeDefined();
    });
    it('<Footer /> should not crash when theme.ui.gradient has only one color (or empty) and nightly is true', () => {
        const { lastFrame } = renderWithProviders(_jsx(Footer, { ...defaultFooterProps }));
        // If it crashes, this line won't be reached or lastFrame() will throw
        expect(lastFrame()).toBeDefined();
        // It should fall back to rendering text without gradient
        expect(lastFrame()).not.toContain('Gradient');
    });
    it('<StatsDisplay /> should not crash when theme.ui.gradient is empty', () => {
        const { lastFrame } = renderWithProviders(_jsx(StatsDisplay, { duration: "1s", title: "My Stats" }));
        expect(lastFrame()).toBeDefined();
        // Ensure title is rendered
        expect(lastFrame()).toContain('My Stats');
    });
});
//# sourceMappingURL=GradientRegression.test.js.map