name: Test RadioGroup Component

on:
  push:
    branches: [ main, develop ]
    paths:
      - 'packages/yew/radio-group/**'
      - 'packages/leptos/radio-group/**'
      - 'packages/test-utils/**'
      - 'tests/radio_group_integration_test.rs'
      - 'scripts/test_radio_group.sh'
  pull_request:
    branches: [ main, develop ]
    paths:
      - 'packages/yew/radio-group/**'
      - 'packages/leptos/radio-group/**'
      - 'packages/test-utils/**'
      - 'tests/radio_group_integration_test.rs'
      - 'scripts/test_radio_group.sh'

jobs:
  test-radio-group:
    name: RadioGroup Component Tests
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: wasm32-unknown-unknown
          override: true
          
      - name: Cache Rust dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-
            
      - name: Install wasm-pack
        run: cargo install wasm-pack
        
      - name: Install Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          cache: 'npm'
          
      - name: Install test dependencies
        run: |
          npm install -g wasm-bindgen-cli
          npm install -g wasm-bindgen-test-runner
          
      - name: Build test utilities
        run: cargo build -p shadcn-ui-test-utils
        
      - name: Run Yew RadioGroup tests
        run: cargo test -p shadcn-ui-yew-radio-group --lib
        
      - name: Run Leptos RadioGroup tests
        run: cargo test -p shadcn-ui-leptos-radio-group --lib
        
      - name: Run integration tests
        run: cargo test --test radio_group_integration_test
        
      - name: Run cross-framework parity tests
        run: cargo test test_radio_group_cross_framework_parity
        
      - name: Run theme consistency tests
        run: cargo test test_radio_group_theme_consistency
        
      - name: Run accessibility tests
        run: cargo test test_radio_group_accessibility_features
        
      - name: Run registry integration tests
        run: cargo test test_radio_group_registry_integration
        
      - name: Run property validation tests
        run: cargo test test_radio_group_property_validation
        
      - name: Build components
        run: |
          cargo build -p shadcn-ui-yew-radio-group
          cargo build -p shadcn-ui-leptos-radio-group
          
      - name: Generate documentation
        run: |
          cargo doc -p shadcn-ui-yew-radio-group --no-deps
          cargo doc -p shadcn-ui-leptos-radio-group --no-deps
          
      - name: Run comprehensive test script
        run: ./scripts/test_radio_group.sh
        
      - name: Upload test results
        uses: actions/upload-artifact@v3
        if: always()
        with:
          name: radio-group-test-results
          path: |
            target/test-results/
            target/doc/
          retention-days: 7
          
  test-browser:
    name: Browser Tests
    runs-on: ubuntu-latest
    needs: test-radio-group
    
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: wasm32-unknown-unknown
          override: true
          
      - name: Install wasm-pack
        run: cargo install wasm-pack
        
      - name: Install Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          cache: 'npm'
          
      - name: Install browser test dependencies
        run: |
          npm install -g wasm-bindgen-cli
          npm install -g wasm-bindgen-test-runner
          npm install -g playwright
          npx playwright install
          
      - name: Run Yew browser tests
        run: |
          wasm-pack test --headless --firefox packages/yew/radio-group
          wasm-pack test --headless --chrome packages/yew/radio-group
          
      - name: Run Leptos browser tests
        run: |
          wasm-pack test --headless --firefox packages/leptos/radio-group
          wasm-pack test --headless --chrome packages/leptos/radio-group
          
  test-examples:
    name: Example Tests
    runs-on: ubuntu-latest
    needs: test-radio-group
    
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: wasm32-unknown-unknown
          override: true
          
      - name: Install wasm-pack
        run: cargo install wasm-pack
        
      - name: Install Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          cache: 'npm'
          
      - name: Build Leptos examples
        run: |
          cd book-examples/leptos
          cargo build --features radio-group
          
      - name: Build Yew examples
        run: |
          cd book-examples/yew
          cargo build --features radio-group
          
      - name: Test example components
        run: |
          cargo test -p book-examples-leptos --features radio-group
          cargo test -p book-examples-yew --features radio-group
          
  lint-and-format:
    name: Lint and Format
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          
      - name: Install clippy
        run: rustup component add clippy
        
      - name: Run clippy
        run: |
          cargo clippy -p shadcn-ui-yew-radio-group
          cargo clippy -p shadcn-ui-leptos-radio-group
          cargo clippy -p shadcn-ui-test-utils
          
      - name: Check formatting
        run: |
          cargo fmt --check -p shadcn-ui-yew-radio-group
          cargo fmt --check -p shadcn-ui-leptos-radio-group
          cargo fmt --check -p shadcn-ui-test-utils
          
  security-audit:
    name: Security Audit
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          
      - name: Install cargo-audit
        run: cargo install cargo-audit
        
      - name: Run security audit
        run: cargo audit
