name: UI Smoke Tests (Playwright)

# Запускается автоматически после каждого успешного деплоя GitHub Pages.
# Можно запустить вручную: Actions → UI Smoke Tests → Run workflow
on:
  workflow_run:
    workflows: ["Deploy MiniApp to GitHub Pages"]
    types: [completed]
  workflow_dispatch:
    inputs:
      url:
        description: "URL для тестирования (пусто = https://wasrusgen.github.io/zov-tech/)"
        required: false
        default: ""

jobs:
  smoke-ui:
    name: UI Smoke (Playwright)
    runs-on: ubuntu-latest

    # При автозапуске — только если деплой прошёл успешно
    if: >
      github.event_name == 'workflow_dispatch' ||
      github.event.workflow_run.conclusion == 'success'

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: "npm"

      - name: Установка зависимостей
        run: npm ci

      - name: Установка Playwright (Chromium)
        run: npx playwright install chromium --with-deps

      - name: Запуск UI smoke-теста
        env:
          SMOKE_URL: ${{ inputs.url || 'https://wasrusgen.github.io/zov-tech/' }}
        run: node tests/ui_smoke.js

      - name: Загрузить скриншот при провале
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: smoke-screenshot
          path: tests/ui_last_run.png
          retention-days: 7
