name: Tests

on:
  push:
    branches:
      - master
  pull_request:

jobs:
  # JOB to run change detection
  changes:
    name: Detect changed files
    runs-on: ubuntu-latest
    # Set job outputs to values from filter step
    outputs:
      integration_testing: ${{ steps.filter.outputs.integration_testing }}
    steps:
    - uses: actions/checkout@v7
    - uses: dorny/paths-filter@v4
      id: filter
      with:
        filters: |
          integration_testing:
          - 'lib/**'
          - 'packages/**'
          - 'pubspec.yaml'

  integration_testing:
    needs: changes
    if: ${{ needs.changes.outputs.integration_testing == 'true' }}
    name: Integration testing
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
    - name: Checkout
      uses: actions/checkout@v7

    - name: Install missing packages
      run: |
        sudo apt-get update
        sudo apt-get install -y ninja-build libgtk-3-dev

    - name: Setup Flutter
      uses: subosito/flutter-action@v2
      with:
        cache: true
        channel: stable

    - name: Flutter doctor
      run: flutter doctor --verbose

    - name: Install required dart tools
      run: |
        dart pub global activate melos

    - name: Bootstrap
      run: melos bootstrap
      
    - name: Run large display integration testing
      run: |
        export DISPLAY=:99
        sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
        flutter test integration_test/large_display_test.dart -d linux

    - name: Run small display integration testing
      run: |
        export DISPLAY=:99
        sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
        flutter test integration_test/small_display_test.dart -d linux
