# profile/view-and-edit.yaml
# Tests: Login → open Header dropdown → tap "Profil" → ProfileScreen loads →
#        tap edit (navigates to /profile/edit) → change nickname → tap Save.
# Pre-requisite: App installed. Test-user account exists on staging.
# Env-Vars: E2E_TEST_USER, E2E_TEST_PASSWORD
# Expected outcome: Save button (t('profile.edit_save') = "Speichern") tapped,
#                   screen returns to ProfileScreen without error.
#
# BLOCKER: Avatar Pressable in AppHeader has NO testID and NO accessibilityLabel.
# The dropdown open-tap uses a coordinate fallback (93%, 6%). This breaks if
# header layout changes. See TODO_TESTIDS.md — needs testID="header-avatar-btn".

appId: org.rebreak.app
---
- launchApp:
    clearState: true

- waitForAnimationToEnd:
    timeout: 5000

# --- Auth ---
- assertVisible:
    text: "E-Mail"
- tapOn:
    text: "E-Mail"
- inputText: ${E2E_TEST_USER}@rebreak.internal
- tapOn:
    text: "Passwort"
- inputText: ${E2E_TEST_PASSWORD}
- tapOn:
    text: "Anmelden"
- waitForAnimationToEnd:
    timeout: 10000

# --- Home ---
- assertVisible:
    text: "ReBreak"

# Open HeaderDropdownMenu via Avatar tap (top-right corner).
# FRAGILE — needs testID="header-avatar-btn" to become stable. See TODO_TESTIDS.md.
- tapOn:
    point: "93%, 6%"
- waitForAnimationToEnd:
    timeout: 2000

# Dropdown label = t('headerMenu.profile') = "Profil" (de.json)
- assertVisible:
    text: "Profil"
- tapOn:
    text: "Profil"
- waitForAnimationToEnd:
    timeout: 4000

# ProfileScreen: AppHeader title is hardcoded "Profil" in ProfileScreen.
# "Posts" label in StatsBar (hardcoded, no i18n) confirms the screen rendered.
- assertVisible:
    text: "Profil"
- assertVisible:
    text: "Posts"

# Scroll down to make sure StatsBar area is visible before continuing
- scrollUntilVisible:
    element:
      text: "Posts"
    direction: DOWN
    timeout: 3000

# Navigate to edit screen.
# ProfileHeader has two Pressables: onEditAvatar + onEditNickname — both push /profile/edit.
# The camera icon area has no testID. We scroll back up first and tap the nickname area.
# FRAGILE — needs testID="profile-edit-nickname-btn" on the nickname Pressable.
# See TODO_TESTIDS.md.
- scrollUntilVisible:
    element:
      text: "Profil"
    direction: UP
    timeout: 3000
- tapOn:
    point: "50%, 28%"

- waitForAnimationToEnd:
    timeout: 3000

# Edit screen: title = t('profile.edit_title') — check SETUP.md for de.json value.
# Nickname TextInput has no testID. Tap and clear existing value, type new one.
# We use scrollUntilVisible to reach the nickname section.
- scrollUntilVisible:
    element:
      text: "NICKNAME"
    direction: DOWN
    timeout: 3000

# Nickname TextInput has no testID. Tap the placeholder text (t('auth.nicknamePlaceholder'))
# if field is empty, or tap directly below the "NICKNAME" label.
# clearText clears whatever is in the focused input.
- tapOn:
    text: "NICKNAME"
- waitForAnimationToEnd:
    timeout: 500
# The TextInput sits directly below the NICKNAME label — Maestro focuses the last
# tapped element. If placeholder is visible, tap it instead.
- clearText
- inputText: "TestNick"

# Save button = t('profile.edit_save') = "Speichern" (de.json). Only active when hasChanges.
- tapOn:
    text: "Speichern"
- waitForAnimationToEnd:
    timeout: 5000

# After save: router.back() → ProfileScreen. "Profil" title visible again.
- assertVisible:
    text: "Profil"
