/**
 * 基础测试
 */

import { BrowserFactory } from '../src/factory/BrowserFactory';
import { BrowserProviderType } from '../src/core/types';
import { AdsPowerProvider } from '../src/providers/adspower/AdsPowerProvider';

describe('Browser Automation Framework', () => {
  
  describe('Factory', () => {
    test('should have AdsPower registered', () => {
      const providers = BrowserFactory.getAvailableProviders();
      expect(providers).toContain(BrowserProviderType.ADSPOWER);
    });

    test('should create AdsPower provider', () => {
      const provider = BrowserFactory.create(BrowserProviderType.ADSPOWER, {
        profileId: 'test-profile'
      });

      expect(provider).toBeInstanceOf(AdsPowerProvider);
      expect(provider.getName()).toBe('AdsPower');
    });

    test('should throw error for unknown provider', () => {
      expect(() => {
        BrowserFactory.create('unknown' as BrowserProviderType);
      }).toThrow();
    });
  });

  describe('AdsPower Provider', () => {
    let provider: AdsPowerProvider;

    beforeEach(() => {
      provider = new AdsPowerProvider({
        profileId: 'test-profile',
        siteName: 'Test'
      });
    });

    test('should have correct metadata', () => {
      expect(provider.getName()).toBe('AdsPower');
      expect(provider.getVersion()).toBe('1.0.0');
      expect(provider.isFree()).toBe(false);
    });

    test('should have correct capabilities', () => {
      const caps = provider.getCapabilities();
      
      expect(caps.stealth).toBe(true);
      expect(caps.fingerprint).toBe(true);
      expect(caps.cloudflareBypass).toBe(true);
      expect(caps.stripeCompatible).toBe(true);
    });

    test('should validate config', async () => {
      await expect(provider.validateConfig()).resolves.toBe(true);
    });

    test('should fail validation without profileId', async () => {
      const invalidProvider = new AdsPowerProvider({});
      await expect(invalidProvider.validateConfig()).rejects.toThrow();
    });
  });
});
