# Stage 5 acceptance: drive the searching screen into the 5-min timeout
# state without waiting 5 minutes, verify the new copy + both CTAs render.
#
# Self-contained: clearState=true + verified-onboarding-to-home + payment
# funnel + searching → force-timeout via dev endpoint.
#
# Pre-req:
#   1. At least one mitra is ONLINE (so the home CTA is enabled). The
#      mitra is force-timed-out server-side regardless of availability.
#   2. anonymity_enabled=true on the dev backend.
#   3. NODE_ENV != 'production' (so /internal/_test/* routes register).
appId: com.halobestie.client.client_app
env:
  TEST_PHONE: "+628155557705"
  BACKEND_INTERNAL_URL: http://localhost:3001
---
- runScript:
    file: ../scripts/reset_phone.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}
- launchApp:
    clearState: true

# --- Onboarding prelude (verified path → /home). ---
- extendedWaitUntil:
    visible:
      text: "Mulai"
    timeout: 15000
- tapOn:
    text: "Mulai"
- waitForAnimationToEnd:
    timeout: 5000
- runFlow:
    when:
      visible:
        text: "Mulai"
    commands:
      - tapOn:
          text: "Mulai"
- extendedWaitUntil:
    visible:
      text: "Lanjut sebagai Tamu"
    timeout: 15000
- tapOn:
    text: "Lanjut sebagai Tamu"
    retryTapIfNoChange: true
- extendedWaitUntil:
    visible:
      text: "Nama panggilan"
    timeout: 10000
- tapOn:
    text: "Nama panggilan"
- inputText: "Maestro"
- hideKeyboard
- tapOn:
    text: "lanjut"
    retryTapIfNoChange: true
- extendedWaitUntil:
    visible:
      text: "verifikasi nomor HP"
    timeout: 10000
- tapOn:
    text: "verifikasi nomor HP"
    retryTapIfNoChange: true
- extendedWaitUntil:
    visible:
      text: "Lagi mikirin apa.*"
    timeout: 10000
- tapOn:
    text: "lewati"
- extendedWaitUntil:
    visible:
      text: "Sebelum mulai"
    timeout: 10000
- tapOn:
    text: "aku ngerti, lanjut"
    retryTapIfNoChange: true
- extendedWaitUntil:
    visible:
      text: "Nomor HP"
    timeout: 10000
- tapOn:
    text: "Nomor HP"
- inputText: ${TEST_PHONE}
- hideKeyboard
- tapOn:
    text: "kirim OTP"
    retryTapIfNoChange: true
- extendedWaitUntil:
    visible:
      text: "Masukkan OTP"
    timeout: 15000
- runScript:
    file: ../scripts/peek_otp.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}
- inputText: ${output.OTP}
- extendedWaitUntil:
    notVisible:
      text: "Masukkan OTP"
    timeout: 15000
- extendedWaitUntil:
    visible:
      text: "Nama panggilan"
    timeout: 15000
- tapOn:
    text: "Nama panggilan"
- inputText: "Maestro"
- hideKeyboard
- tapOn:
    text: "Lanjut"
    retryTapIfNoChange: true
- extendedWaitUntil:
    visible:
      text: "Mulai Curhat"
    timeout: 15000

# --- Now on /home. Enter payment funnel via discount paywall. ---
- tapOn:
    text: "Mulai Curhat"
    retryTapIfNoChange: true
- extendedWaitUntil:
    visible:
      text: "SESI PERTAMA"
    timeout: 10000
- tapOn:
    text: "mulai.*Rp.*"
    retryTapIfNoChange: true
- extendedWaitUntil:
    visible:
      text: "cara bayar"
    timeout: 10000
- tapOn:
    text: "bayar Rp.*"
    retryTapIfNoChange: true

# --- The waiting-payment screen needs to flip to paid before pairing
# can start. We can't fake that here — flow 05 was designed assuming
# a free-trial path that doesn't exist anymore. For Stage 5 testing,
# we need a "mark as paid" dev endpoint or a free-tier path. Use the
# existing CC tooling: directly mark the latest payment as confirmed
# via DB. ---
- runScript:
    file: ../scripts/mark_latest_payment_paid.js
    env:
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}

# --- Notif gate may appear (Stage 4); tap "nanti aja" if so. ---
- extendedWaitUntil:
    visible:
      text: "nanti aja|lagi nyari bestie.*"
    timeout: 15000
- runFlow:
    when:
      visible:
        text: "nanti aja"
    commands:
      - tapOn:
          text: "nanti aja"

# --- Searching screen — verify soft-prompt + searching state. ---
- extendedWaitUntil:
    visible:
      text: "lagi nyari bestie.*"
    timeout: 15000

# --- Force 5-min timeout server-side. ---
- runScript:
    file: ../scripts/force_pairing_timeout.js
    env:
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}

# --- Verify timeout panel + both CTAs. ---
- extendedWaitUntil:
    visible:
      text: "masih nyari nih"
    timeout: 10000
- assertVisible: "coba cari lagi"
- assertVisible: "kembali ke home"
