# Frontend Unit Tests CI Pipeline
#
# Rename this file to frontend-tests.yml to enable it
# This will make the frontend test badges dynamic
#
# Required repository secrets:
# - CODECOV_TOKEN (for coverage upload)

name: Frontend Tests

on:
  push:
    branches: [ main, develop ]
    paths:
      - 'frontend/**'
      - '.github/workflows/frontend-tests.yml'
  pull_request:
    branches: [ main, develop ]
    paths:
      - 'frontend/**'

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Set up Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '20'
        cache: 'npm'
        cache-dependency-path: './frontend/package-lock.json'

    - name: Install dependencies
      working-directory: ./frontend
      run: npm ci

    - name: Run unit tests with coverage
      working-directory: ./frontend
      run: npm run test:coverage

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v4
      with:
        files: ./frontend/coverage/coverage-final.json
        flags: frontend
        name: frontend-coverage
        fail_ci_if_error: true
        token: ${{ secrets.CODECOV_TOKEN }}
