# stress/dm-scroll-performance.yaml
#
# Stress scenario: Open a DM conversation with many messages and scroll
# the entire history. Designed to catch FlatList perf issues on slow devices
# (Samsung A50 — primary Android test target, known slow).
#
# What this tests:
#   - DM FlatList renders without ANR (App Not Responding) on large history
#   - Scroll from bottom to top of message list completes
#   - Scroll back to bottom (chat.scrollToBottom behavior)
#   - App does not crash or freeze during scroll
#   - "Scroll to bottom" action returns to latest message correctly
#
# Samsung A50 characteristics:
#   - Exynos 9610 — single-core perf ~35% slower than Pixel 5
#   - 4GB RAM — RN FlatList with 100+ messages + image attachments can OOM
#   - Expected: 5–10s for initial load on large history (100 messages)
#
# Pre-requisite:
#   - Test user has a DM conversation with 50+ messages (seed if not present).
#   - If conversation is short: the stress value is reduced but the flow still
#     validates basic scroll behavior.
# Env-Vars: E2E_TEST_USER, E2E_TEST_PASSWORD, E2E_TEST_PEER_NICKNAME

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

# Extended wait — A50 cold boot is slow
- waitForAnimationToEnd:
    timeout: 8000

# --- 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"
# Extended timeout for A50 + Staging network round-trip
- waitForAnimationToEnd:
    timeout: 15000

- assertVisible:
    text: "ReBreak"

# --- Navigate to Chat tab ---
- tapOn:
    text: "Chat"
- waitForAnimationToEnd:
    timeout: 5000

- assertVisible:
    text: "Direktnachrichten"

# --- Open target DM ---
- tapOn:
    text: ${E2E_TEST_PEER_NICKNAME}

# Extended load time for large message history on A50
- waitForAnimationToEnd:
    timeout: 10000

# DM screen input is the load-complete signal
- assertVisible:
    text: "Nachricht schreiben…"

# --- Scroll UP through history ---
# Repeat swipe-up 8 times to simulate user browsing through history.
# Each swipe = ~3 visible messages scrolled on an A50 screen.
# 8 swipes = ~24 messages reviewed without crash.
- swipe:
    direction: UP
    duration: 600
- waitForAnimationToEnd:
    timeout: 2000

- swipe:
    direction: UP
    duration: 600
- waitForAnimationToEnd:
    timeout: 2000

- swipe:
    direction: UP
    duration: 600
- waitForAnimationToEnd:
    timeout: 2000

- swipe:
    direction: UP
    duration: 600
- waitForAnimationToEnd:
    timeout: 2000

- swipe:
    direction: UP
    duration: 600
- waitForAnimationToEnd:
    timeout: 2000

- swipe:
    direction: UP
    duration: 600
- waitForAnimationToEnd:
    timeout: 2000

- swipe:
    direction: UP
    duration: 600
- waitForAnimationToEnd:
    timeout: 2000

- swipe:
    direction: UP
    duration: 600
- waitForAnimationToEnd:
    timeout: 3000

# If the app hasn't crashed by here: FlatList is stable under upward scroll.

# --- Scroll BACK DOWN to latest message ---
# Simulate user tapping "scroll to bottom" or dragging down rapidly.
- swipe:
    direction: DOWN
    duration: 300
- swipe:
    direction: DOWN
    duration: 300
- swipe:
    direction: DOWN
    duration: 300
- swipe:
    direction: DOWN
    duration: 300
- waitForAnimationToEnd:
    timeout: 3000

# --- Assert the input is still accessible after scroll ---
# If the app ANR'd or crashed, this will fail.
# If the FlatList lost keyboard/input state, this will fail.
- assertVisible:
    text: "Nachricht schreiben…"

# --- Send a message after scroll to verify input still works ---
- tapOn:
    text: "Nachricht schreiben…"
- inputText: "[E2E-STRESS] Scroll-Test abgeschlossen"
- pressKey: Return
- waitForAnimationToEnd:
    timeout: 8000

# Message bubble appeared = send path survived after heavy scroll
- assertVisible:
    text: "[E2E-STRESS] Scroll-Test abgeschlossen"
