# ts-mitra-1-05 — §1 Home Perpanjang tile → Chat tab (Perpanjang sub-tab)
# Spec ref: requirement/flow_mitra.mermaid.md §1
#
# The Perpanjang tile (home_screen.dart L220-231) writes 1 to
# undanganTabProvider then calls shell.goBranch(1). UndanganScreen picks
# Perpanjang Curhat (index 1) on init.
#
# Walks: login → home online → tap Perpanjang tile → assert Perpanjang sub-
# tab is active (empty-state placeholder copy from _PerpanjangTab visible).
appId: com.mybestie.mitra
env:
  TEST_PHONE: "+628200000705"
  MITRA_DISPLAY_NAME: "Maestro Perpanjang Tile"
  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

- tapOn:
    point: "50%, 53%"
- inputText: "8200000705"
- tapOn: "(?s).*kirim kode.*"
- extendedWaitUntil:
    visible:
      text: "(?s).*masukin 6 digit kode.*"
    timeout: 10000
- runScript:
    file: ../scripts/peek_otp.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}
- inputText: ${output.OTP}

- extendedWaitUntil:
    visible:
      text: "(?s).*Kamu lagi (ONLINE|OFFLINE).*"
    timeout: 15000

# Conditional online toggle. Fresh mitra defaults to OFFLINE (per DB schema
# default for mitra_online_status.is_online). If a prior test run force-onlined
# this row already, skip the CTA. Otherwise tap "Nyalain Status (Online)" so
# downstream flow has the tile grid + is blast-eligible.
- runFlow:
    when:
      visible:
        text: "(?s).*Kamu lagi OFFLINE.*"
    commands:
      - tapOn: "(?s).*Nyalain Status.*"
      - extendedWaitUntil:
          visible:
            text: "(?s).*Kamu lagi ONLINE.*"
          timeout: 10000

# Tap the Perpanjang tile.
- tapOn: "(?s).*Perpanjang.*"

# Perpanjang sub-tab active → placeholder empty-state copy visible.
- extendedWaitUntil:
    visible:
      text: "(?s).*Belum ada permintaan perpanjangan.*"
    timeout: 8000
- assertVisible:
    text: "(?s).*Curhat Baru.*"
- assertVisible:
    text: "(?s).*Perpanjang Curhat.*"

- takeScreenshot: ts-mitra-1-05-perpanjang-from-tile
