# ts-mitra-1-01c — §1 Home after login, SCENARIO 3: existing mitra who was
# ONLINE before logout → relogin shows ONLINE.
#
# Spec ref: requirement/flow_mitra.mermaid.md §1
# DB invariant: mitras row exists; mitra_online_status row exists with
# is_online=true (the post-logout state of someone who stayed online before
# signing out, or whose ONLINE state was preserved across sessions).
# Expected behavior: app's GET /api/mitra/status returns is_online=true →
# BestieHome (online variant): 🌸 greeting, tile grid, ONLINE status card,
# Ganti Status CTA, Pengingat.
#
# Setup: seed_mitra + force_mitra_online makes the existing user ONLINE,
# then login should reflect that state.
appId: com.mybestie.mitra
env:
  TEST_PHONE: "+628200000713"
  MITRA_DISPLAY_NAME: "Maestro Existing Online"
  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}
# Force ONLINE — simulates someone who was online at logout time.
- runScript:
    file: ../scripts/force_mitra_online.js
    env:
      MITRA_ID: ${output.MITRA_ID}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}

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

# S3a → S3b → /home
- tapOn:
    point: "50%, 53%"
- inputText: "8200000713"
- 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}

# Verify: relogin lands on BestieHome (online variant — still online from pre-logout).
- extendedWaitUntil:
    visible:
      text: "(?s).*Bestie Maestro Existing Online.*"
    timeout: 15000
- assertVisible:
    text: "(?s).*Kamu lagi ONLINE.*"
- assertVisible:
    text: "(?s).*🌸.*"
- assertVisible:
    text: "(?s).*Ganti Status.*"
# Online variant has the tile grid + Pengingat.
- assertVisible:
    text: "(?s).*Undangan.*"
- assertVisible:
    text: "(?s).*Perpanjang.*"
- assertVisible:
    text: "(?s).*Pengingat.*"
- assertNotVisible: "(?s).*Kamu lagi OFFLINE.*"

- takeScreenshot: ts-mitra-1-01c-existing-online-relogin
