# ts-customer-02-10 — SHome1st "masuk →" login-recover banner · existing
# identified user → /home directly (no set-name detour).
# Spec refs:
#   - requirement/flow_customer.mermaid.md §2 (post-OTP path for existing
#     identified customer with display_name stored)
#   - Project directive: login-intent entries (masuk → banner) land on
#     /home; transaction-CTA entries (aku mau curhat / curhat sama bestie
#     baru) land on /payment/entry.
#
# Pre-seeds an existing identified customer with phone + display_name.
# After OTP succeeds, backend's resolveCustomerForIdentity returns the
# existing row unchanged. The router's onboardingIntentProvider stays at
# `recover` (the masuk → handler resets it defensively), so the post-OTP
# redirect lands on /home rather than /payment/entry.
#
# This was previously named TS-07 (under the §4-driven naming scheme).
# Renamed 2026-05-18 to the ts-customer-NN-MM-* convention; the assertion
# semantics are unchanged.
#
# Pre-reqs:
#   - Backend reachable, NODE_ENV != 'production'.
#   - (No mitra requirement — flow stops at /home.)
#
# Run:
#   maestro test client_app/.maestro/flows/ts-customer-02-10-recover_via_masuk_existing_user_to_home.yaml
appId: com.mybestie
env:
  TEST_PHONE: "+6281234567890"
  EXISTING_NAME: "Returning User"
  BACKEND_INTERNAL_URL: http://localhost:3001
---
# --- Setup: wipe the phone, then re-seed an identified customer with name ---
- runScript:
    file: ../scripts/reset_phone.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}
- runScript:
    file: ../scripts/seed_customer.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      DISPLAY_NAME: ${EXISTING_NAME}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}
- launchApp:
    clearState: true

# --- Welcome carousel → home (anon) ---
- extendedWaitUntil:
    visible:
      text: "Mulai"
    timeout: 15000
- tapOn:
    text: "Mulai"
    retryTapIfNoChange: true

# Home anon view shows the `masuk →` banner.
- extendedWaitUntil:
    visible:
      text: "(?s).*udah pernah pakai HaloBestie.*"
    timeout: 30000

# --- Tap masuk → register → phone → OTP ---
- tapOn:
    text: "(?s).*masuk →.*"

- extendedWaitUntil:
    visible:
      text: "(?s).*nomor wa-mu.*"
    timeout: 10000
- tapOn:
    point: "60%, 47%"
- inputText: "81234567890"
- hideKeyboard
- tapOn:
    text: "(?s).*kirim kode.*"

- extendedWaitUntil:
    visible:
      text: "Masukkan OTP"
    timeout: 15000
- runScript:
    file: ../scripts/peek_otp.js
    env:
      TEST_PHONE: ${TEST_PHONE}
      BACKEND_INTERNAL_URL: ${BACKEND_INTERNAL_URL}
- inputText: ${output.OTP}

# --- KEY ASSERTIONS ---
# 1. OTP entry should disappear (auto-submit on 6th digit).
- extendedWaitUntil:
    notVisible:
      text: "Masukkan OTP"
    timeout: 15000

# 2. Home renders directly. Identified (verified) users land on the
#    `_SHomeReturningView` regardless of chat history: greeting becomes
#    "halo, <name>" and CTA flips to "curhat sama bestie baru". The
#    1st-time view ("aku mau curhat") is the anon-user variant only.
- extendedWaitUntil:
    visible:
      text: "(?s).*halo, ${EXISTING_NAME}.*"
    timeout: 20000
- assertVisible: "(?s).*curhat sama bestie baru.*"

# 3. The "Siapa namamu?" set-name screen must NOT have been shown —
#    if it had, the assertion above would have failed at the set-name
#    intermediate. This belt-and-braces assert catches the case where
#    the set-name screen briefly flashes then auto-redirects.
- assertNotVisible:
    text: "(?s).*Siapa namamu.*"
