# ts-mitra-1-04 — §1 Home Undangan tile → Chat tab (Curhat Baru sub-tab)
# Spec ref: requirement/flow_mitra.mermaid.md §1
#
# The Undangan tile on BestieHome (home_screen.dart L200-212) writes 0 to
# undanganTabProvider then calls shell.goBranch(1) which routes to the Chat
# branch (Undangan). UndanganScreen reads the provider on init and selects
# the Curhat Baru tab (index 0).
#
# Walks: login → home online → tap Undangan tile → assert we landed on the
# Chat branch with Curhat Baru as the active sub-tab (empty-state copy
# proves we're on the right sub-tab).
appId: com.mybestie.mitra
env:
  TEST_PHONE: "+628200000704"
  MITRA_DISPLAY_NAME: "Maestro Undangan 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: "8200000704"
- 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 Undangan tile (online-only chrome — tile grid is hidden when offline).
# Use the tile label "Undangan" rather than the icon (emoji selectors are flaky
# across renderers). The tile is the topmost match for "Undangan" since the
# tab bar label hasn't rendered yet on the Home screen.
- tapOn: "(?s).*Undangan.*"

# Curhat Baru sub-tab visible + empty-state copy (no pending invites in this
# fresh DB row). Both tabs labels are visible — verify Curhat Baru is the
# active one by asserting on the empty-state copy (which only appears under
# the Curhat Baru tab, not under Perpanjang).
- extendedWaitUntil:
    visible:
      text: "(?s).*Curhat Baru.*"
    timeout: 8000
- assertVisible:
    text: "(?s).*Perpanjang Curhat.*"
- assertVisible:
    text: "(?s).*Belum ada undangan masuk.*"

- takeScreenshot: ts-mitra-1-04-curhat-baru-from-tile
