# stress/rapid-post-submit.yaml
#
# Stress scenario: Submit multiple community posts in rapid succession.
# Designed to catch race conditions in the post submission pipeline:
#   - Duplicate optimistic inserts
#   - ComposeCard not resetting between posts
#   - React Query invalidation firing before previous request resolves
#   - "Post konnte nicht veröffentlicht werden" error appearing incorrectly
#
# Samsung A50 note: The submit → reset cycle takes ~1–3s on A50 due to:
#   - API round-trip to staging (network)
#   - React Query invalidation → re-render
#   - ComposeCard animation (expand/collapse)
# Each post is given 8s timeout. 3 posts = ~24s total on A50.
#
# Pre-requisite: Test-user exists on staging. Posts created are real (staging DB).
# Cleanup: Delete [E2E-STRESS] posts from staging DB manually or via Service-Role.
# Env-Vars: E2E_TEST_USER, E2E_TEST_PASSWORD

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

- 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"
- waitForAnimationToEnd:
    timeout: 15000

- assertVisible:
    text: "ReBreak"

# --- Scroll to ComposeCard at top ---
- scrollUntilVisible:
    element:
      text: "Was bewegt dich gerade?"
    direction: UP
    timeout: 5000

# === POST 1 ===
- tapOn:
    text: "Was bewegt dich gerade?"
- waitForAnimationToEnd:
    timeout: 1000
- inputText: "[E2E-STRESS] Post 1 — Rapid-Submit-Test"
- assertVisible:
    text: "Teilen"
- tapOn:
    text: "Teilen"
- waitForAnimationToEnd:
    timeout: 8000

# ComposeCard must reset after submit — placeholder visible again
- assertVisible:
    text: "Was bewegt dich gerade?"

# === POST 2 ===
- tapOn:
    text: "Was bewegt dich gerade?"
- waitForAnimationToEnd:
    timeout: 1000
- inputText: "[E2E-STRESS] Post 2 — Rapid-Submit-Test"
- assertVisible:
    text: "Teilen"
- tapOn:
    text: "Teilen"
- waitForAnimationToEnd:
    timeout: 8000

- assertVisible:
    text: "Was bewegt dich gerade?"

# === POST 3 ===
- tapOn:
    text: "Was bewegt dich gerade?"
- waitForAnimationToEnd:
    timeout: 1000
- inputText: "[E2E-STRESS] Post 3 — Rapid-Submit-Test"
- assertVisible:
    text: "Teilen"
- tapOn:
    text: "Teilen"
- waitForAnimationToEnd:
    timeout: 8000

- assertVisible:
    text: "Was bewegt dich gerade?"

# --- Verify no error state ---
# community.post_failed = "Post konnte nicht veröffentlicht werden."
# If any of the 3 posts failed with this error, the flow failed.
- assertNotVisible:
    text: "Post konnte nicht veröffentlicht werden."
