# ts-mitra-1-01a — §1 Home after login, SCENARIO 1: freshly created mitra
# with NO mitra_online_status row → home renders OFFLINE.
#
# Spec ref: requirement/flow_mitra.mermaid.md §1
# DB invariant: mitras row exists; mitra_online_status row absent.
# Expected behavior: app's first GET /api/mitra/status creates a row via
# ensureStatusRow() with DB default is_online=false → BestieHomeOffline.
#
# Setup: seed_mitra creates the mitra row. delete_mitra_status_row removes
# any pre-existing online_status row so this run starts from the true
# "freshly created" state (even if a prior test run had touched the row).
appId: com.mybestie.mitra
env:
  TEST_PHONE: "+628200000711"
  MITRA_DISPLAY_NAME: "Maestro Fresh User"
  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}
# Remove any pre-existing mitra_online_status row so the precondition is
# precisely "freshly created mitra, no status row". The app's status call
# will recreate the row with default is_online=false.
- runScript:
    file: ../scripts/delete_mitra_status_row.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: "8200000711"
- 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: fresh user lands on BestieHomeOffline.
- extendedWaitUntil:
    visible:
      text: "(?s).*Bestie Maestro Fresh User.*"
    timeout: 15000
- assertVisible:
    text: "(?s).*Kamu lagi OFFLINE.*"
- assertVisible:
    text: "(?s).*🌙.*"
- assertVisible:
    text: "(?s).*Nyalain Status \\(Online\\).*"
# Negative: should NOT render the online variant chrome.
- assertNotVisible: "(?s).*Kamu lagi ONLINE.*"
- assertNotVisible: "(?s).*Pengingat.*"

- takeScreenshot: ts-mitra-1-01a-fresh-user-offline
