/**
 * GenUI 组件注册表测试
 */
import { describe, it, expect } from 'vitest';
import { 
  isComponentRegistered, 
  getRegisteredComponent, 
  getSupportedComponentTypes,
  componentRegistry 
} from '../registry';

describe('GenUI Registry', () => {
  describe('isComponentRegistered', () => {
    it('should return true for registered component types', () => {
      expect(isComponentRegistered('stats_row')).toBe(true);
      expect(isComponentRegistered('data_table')).toBe(true);
      expect(isComponentRegistered('chart')).toBe(true);
      expect(isComponentRegistered('alert')).toBe(true);
      expect(isComponentRegistered('action_buttons')).toBe(true);
      expect(isComponentRegistered('approval_card')).toBe(true);
      expect(isComponentRegistered('insight_card')).toBe(true);
      expect(isComponentRegistered('progress_bar')).toBe(true);
      expect(isComponentRegistered('text')).toBe(true);
      expect(isComponentRegistered('divider')).toBe(true);
    });

    it('should return true for agent-related components', () => {
      expect(isComponentRegistered('agent_status')).toBe(true);
      expect(isComponentRegistered('agent_capabilities')).toBe(true);
      expect(isComponentRegistered('agent_thinking')).toBe(true);
      expect(isComponentRegistered('agent_settings_card')).toBe(true);
      expect(isComponentRegistered('agent_settings_list')).toBe(true);
    });

    it('should return true for special components', () => {
      expect(isComponentRegistered('sandbox_result')).toBe(true);
      expect(isComponentRegistered('insight_feed')).toBe(true);
      expect(isComponentRegistered('approval_list')).toBe(true);
    });

    it('should return true for container (special handling)', () => {
      expect(isComponentRegistered('container')).toBe(true);
    });

    it('should return false for unregistered component types', () => {
      expect(isComponentRegistered('unknown_component' as any)).toBe(false);
      expect(isComponentRegistered('random_type' as any)).toBe(false);
    });
  });

  describe('getRegisteredComponent', () => {
    it('should return component for registered types', () => {
      expect(getRegisteredComponent('stats_row')).toBeDefined();
      expect(getRegisteredComponent('data_table')).toBeDefined();
      expect(getRegisteredComponent('chart')).toBeDefined();
    });

    it('should return undefined for container (handled separately)', () => {
      expect(getRegisteredComponent('container')).toBeUndefined();
    });

    it('should return undefined for unregistered types', () => {
      expect(getRegisteredComponent('unknown' as any)).toBeUndefined();
    });
  });

  describe('getSupportedComponentTypes', () => {
    it('should return all supported component types including container', () => {
      const types = getSupportedComponentTypes();
      
      expect(types).toContain('stats_row');
      expect(types).toContain('data_table');
      expect(types).toContain('chart');
      expect(types).toContain('container');
      expect(types).toContain('agent_status');
      expect(types).toContain('insight_feed');
      expect(types).toContain('approval_list');
    });

    it('should have correct number of component types', () => {
      const types = getSupportedComponentTypes();
      // All registry keys + container
      expect(types.length).toBe(Object.keys(componentRegistry).length + 1);
    });
  });

  describe('componentRegistry', () => {
    it('should have all required display components', () => {
      const displayComponents = ['stats_row', 'data_table', 'chart', 'alert', 'progress_bar', 'text', 'divider'];
      displayComponents.forEach(type => {
        expect(componentRegistry[type]).toBeDefined();
      });
    });

    it('should have all required action components', () => {
      const actionComponents = ['action_buttons', 'approval_card', 'insight_card'];
      actionComponents.forEach(type => {
        expect(componentRegistry[type]).toBeDefined();
      });
    });

    it('should have all required agent components', () => {
      const agentComponents = ['agent_status', 'agent_capabilities', 'agent_thinking', 'agent_settings_card', 'agent_settings_list'];
      agentComponents.forEach(type => {
        expect(componentRegistry[type]).toBeDefined();
      });
    });
  });
});
