# ts-mitra-A-03 — §A.2 happy path → /home
# Spec ref: requirement/flow_mitra.mermaid.md §A.2 (200 + is_active=true branch).
#
# End-to-end S3a → S3b → home for an active mitra:
#   1. Seed mitra row with is_active=true
#   2. Reset OTP requests (so cooldown/rate-limit doesn't trip)
#   3. Drive S3a, request OTP
#   4. Peek the stub OTP code from the backend
#   5. Submit it on S3b → /home renders
appId: com.mybestie.mitra
env:
  TEST_PHONE: "+628200000301"
  MITRA_DISPLAY_NAME: "Maestro Active"
  BACKEND_INTERNAL_URL: http://localhost:3001
---
- runScript:
    file: ../scripts/seed_mitra.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      MITRA_DISPLAY_NAME: ${MITRA_DISPLAY_NAME}
      IS_ACTIVE: "true"
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}
- runScript:
    file: ../scripts/reset_phone.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}

- launchApp:
    clearState: true
- extendedWaitUntil:
    visible:
      text: "(?s).*Halo Mitra Bestie.*"
    timeout: 10000

# S3a — request OTP.
- tapOn:
    point: "50%, 53%"
- inputText: "8200000301"
- tapOn: "(?s).*kirim kode.*"

- extendedWaitUntil:
    visible:
      text: "(?s).*masukin 6 digit kode.*"
    timeout: 10000

# Peek the stub OTP that the backend just generated. Stored in output.OTP.
- runScript:
    file: ../scripts/peek_otp.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}

# Submit it. inputText delivers the chars one-at-a-time via adb shell input;
# the Focus(canRequestFocus:false)-wrapped TextFields chain focus on each
# digit and _submit() fires automatically when the 6th digit lands.
- inputText: ${output.OTP}

# Assert: home renders. Stage 2 removed the "Sesi Aktif" / "Riwayat Chat"
# shortcut tiles — the new BestieHome chrome is greeting + status card +
# Ganti Status. Asserting "Kamu lagi ONLINE" is the most stable marker
# that we've made it past auth and the status_notifier loaded.
- extendedWaitUntil:
    visible:
      text: "(?s).*Kamu lagi (ONLINE|OFFLINE).*"
    timeout: 15000
- assertVisible:
    text: "(?s).*(Ganti Status|Nyalain Status).*"

# Also serves as the Stage 7 design-review visual baseline for the new home.
- takeScreenshot: ts-mitra-A-03-home-online
