// @vitest-environment jsdom
import { describe, expect, it } from 'vitest';
import { render, screen } from '@testing-library/react';
import { TopVolatile, AISetups } from './MarketOpportunities';

describe('MarketOpportunities Components', () => {
    const mockBotState: any = {
        symbols: {
            'BTC/USDT': {
                change24h: 5.25,
                rules: {
                    'AIAnalysisRule': { metadata: { confidence: 85 } }
                }
            },
            'ETH/USDT': {
                change24h: -2.1,
                rules: {
                    'AIAnalysisRule': { metadata: { confidence: 92 } }
                }
            },
            'SOL/USDT': {
                change24h: 0,
                rules: {
                    'TrendBiasRule': {} // No AI data
                }
            }
        }
    };

    describe('TopVolatile', () => {
        it('renders up/down classes and values correctly', () => {
            render(<TopVolatile botState={mockBotState} />);

            expect(screen.getByText('BTC/USDT')).toBeInTheDocument();
            expect(screen.getByText('+5.25%')).toBeInTheDocument();
            expect(screen.getByText('+5.25%')).toHaveClass('up');

            expect(screen.getByText('ETH/USDT')).toBeInTheDocument();
            expect(screen.getByText('-2.10%')).toBeInTheDocument();
            expect(screen.getByText('-2.10%')).toHaveClass('down');
        });

        it('shows scanning when no symbols', () => {
            render(<TopVolatile botState={{ symbols: {} } as any} />);
            expect(screen.getByText('Scanning...')).toBeInTheDocument();
        });
    });

    describe('AISetups', () => {
        it('renders and sorts by confidence correctly', () => {
            render(<AISetups botState={mockBotState} />);

            expect(screen.getByText('ETH/USDT')).toBeInTheDocument();
            expect(screen.getByText('92% Conf')).toBeInTheDocument();

            // SOL should be filtered out
            expect(screen.queryByText('SOL/USDT')).not.toBeInTheDocument();
        });

        it('shows empty state when no AI data exists', () => {
            const state = {
                symbols: {
                    'AAPL': { rules: {} }
                }
            } as any;
            render(<AISetups botState={state} />);
            expect(screen.getByText('No AI data yet...')).toBeInTheDocument();
        });
    });
});
