# Stage 7 acceptance: customer-initiated end-of-session 2-step flow.
#
# Flow:
#   1. Customer is on the chat screen of an ACTIVE session (run flow 03 first).
#   2. Tap "akhiri" in the AppBar → step-1 confirm popup ("yakin mau akhiri sesi?").
#   3. Tap "lanjut akhiri" → step-2 confirm popup ("mau tinggalin pesan penutup?").
#   4. Tap "tulis pesan penutup" → closing-message bottom sheet.
#   5. Type a message → "kirim & akhiri sesi" → POSTs goodbye + closes session.
#   6. Verify navigation to S11 thank-you screen ("makasih udah curhat").
#   7. Tap "balik ke home" → home screen ("Mulai Curhat").
#
# Pre-req:
#   1. A live chat session is on screen (paired + active). Chain after flow
#      03_payment_to_chat_happy.yaml.
#
# Run (chained):
#   maestro test client_app/.maestro/flows/03_payment_to_chat_happy.yaml \
#                client_app/.maestro/flows/07_end_session_2step.yaml
appId: ${APP_ID_ANDROID}
---
- launchApp:
    clearState: false

# Step 0: assert we're on the chat screen.
- extendedWaitUntil:
    visible:
      text: "Ketik Pesan"
    timeout: 10000

# Step 1: tap "akhiri" in the AppBar → step-1 popup.
- tapOn: "akhiri"
- extendedWaitUntil:
    visible:
      text: "yakin mau akhiri sesi?"
    timeout: 5000
- assertVisible: "lanjut akhiri"
- assertVisible: "gak jadi, balik"

# Step 2: tap "lanjut akhiri" → step-2 popup.
- tapOn: "lanjut akhiri"
- extendedWaitUntil:
    visible:
      text: "mau tinggalin pesan penutup?"
    timeout: 5000
- assertVisible: "tulis pesan penutup"
- assertVisible: "lewati saja"

# Step 3: tap "tulis pesan penutup" → closing-message bottom sheet.
- tapOn: "tulis pesan penutup"
- extendedWaitUntil:
    visible:
      text: "pesan penutup"
    timeout: 5000
- assertVisible: "kirim & akhiri sesi"
- assertVisible: "lewat — langsung akhiri"

# Step 4: type a message + send.
- tapOn:
    text: "makasih ya bestie..."
- inputText: "makasih bestie, sesi ini ngebantu banget"
- hideKeyboard
- tapOn: "kirim & akhiri sesi"

# Step 5: verify S11 thank-you screen.
- extendedWaitUntil:
    visible:
      text: "makasih udah curhat"
    timeout: 10000
- assertVisible: "balik ke home"

# Step 6: tap "balik ke home" → home.
- tapOn: "balik ke home"
- extendedWaitUntil:
    visible:
      text: "Mulai Curhat"
    timeout: 5000
