# TS-03 — Returning user picks offline bestie → "tanya admin" (escape)
# (requirement/phase4-customer-flow.md → Test Scenarios → TS-03).
#
# §4 branch covered: Choice → "bestie yang udah kenal" → CheckOnline(no) →
#   OfflinePopup(pre-pay) → "tanya admin" → AdminSheet (terminal).
#
# This is a terminal-escape scenario: no payment row, no chat. The flow
# ends after asserting the admin sheet renders with at least one contact
# option (WhatsApp / Telegram).
#
# Pre-reqs (HARD):
#   - Backend reachable; NODE_ENV != 'production'.
#   - >= 1 mitra online in dev DB so `seed_history_session.js` can pick
#     someone to be the (about-to-be-forced-offline) M1. No second mitra
#     needed (no blast or accept in this scenario).
#   - `support_handles_json` in app_config has at least WA or Telegram
#     populated (default seed includes both). If empty, the admin sheet
#     renders "kontak admin belum tersedia" — the assertion will still pass
#     on the "tanya admin" title but the deeplink CTA assertion below would
#     fail; in that case the WA/Telegram assertion is the verification of
#     interest.
#
# Run:
#   maestro test client_app/.maestro/flows/ts-03_returning_lama_offline_tanya_admin.yaml
appId: com.mybestie
env:
  TEST_PHONE: "+6281234567890"
  BACKEND_INTERNAL_URL: http://localhost:3001
---
# --- Cold-start reset + onboarding prelude ---
- runScript:
    file: ../scripts/reset_phone.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}
- launchApp:
    clearState: true
- runFlow: ../subflows/onboarding_returning_user.yaml

# --- Seed history with M1 then force M1 offline ---
- runScript:
    file: ../scripts/seed_history_session.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}
- runScript:
    file: ../scripts/force_mitra_offline.js
    env:
      MITRA_ID: ${output.MITRA_ID}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}

# Refresh home so history list shows the dimmed row.
- swipe:
    start: "50%, 30%"
    end: "50%, 80%"
- extendedWaitUntil:
    visible:
      text: "(?s).*curhatan sebelumnya.*"
    timeout: 10000

# --- Steps 1-2: choice sheet → "bestie yang udah kenal" → history list ---
- tapOn:
    text: "(?s).*curhat sama bestie baru.*"
    retryTapIfNoChange: true
- extendedWaitUntil:
    visible:
      text: "(?s).*mau curhat sama siapa.*"
    timeout: 5000
- tapOn: "(?s).*bestie yang udah kenal.*"
- extendedWaitUntil:
    visible:
      text: "(?s).*bestie kamu sebelumnya.*"
    timeout: 5000

# --- Step 3: tap dimmed M1 row → BestieOfflinePopup (prePayReturning) ---
- tapOn: "(?s).*bestie ${output.MITRA_NAME_RE}.*"
- extendedWaitUntil:
    visible:
      text: "(?s).*${output.MITRA_NAME_RE}.*lagi nggak online.*"
    timeout: 10000
- assertVisible: "(?s).*cari bestie lain.*"
- assertVisible: "(?s).*tanya admin.*"

# --- Step 4: tap "tanya admin" → admin sheet opens ON TOP of the popup
# (per bestie_unavailable_dialog.dart L181-187 the popup stays alive under
# the sheet). The sheet title is "tanya admin". ---
- tapOn: "(?s).*tanya admin.*"

# The admin sheet's title is "tanya admin" — but so was the CTA we just
# tapped, which remains rendered behind the sheet. Disambiguate by also
# asserting on the subtitle copy "pilih cara yang paling enak buat kamu",
# which only exists on the sheet (verified against tanya_admin_sheet.dart).
- extendedWaitUntil:
    visible:
      text: "(?s).*pilih cara yang paling enak buat kamu.*"
    timeout: 10000
- assertVisible: "(?s).*tanya admin.*"

# Confirm at least one contact option renders. If support_handles_json is
# empty in app_config the sheet renders "kontak admin belum tersedia" — in
# that case the assertVisible above (title + subtitle) is the meaningful
# check; the WhatsApp/Telegram presence depends on CC seed.
# TODO(test-data): if dev seeds reliably populate WA + Telegram, tighten
# this to assertVisible "WhatsApp|Telegram".
