appId: ${APP_ID}
---
# Precondition: KudosTabs screen is visible (Feed/Muro tab)
# Env: KUDOS_TITLE, PEER_1_NAME, PEER_2_NAME, CATEGORY_NAME
# Text matchers are bilingual (English|Spanish) so the flow works regardless of
# the E2E community's configured language.

# Open the acknowledgement creation form
- tapOn:
    text: '.*(Give a recognition|Dar reconocimiento).*'
- assertVisible:
    text: '.*(Select a category|Seleccione una categoría).*'

# --- Select peers to acknowledge ---
# Open the collaborator picker
- tapOn:
    text: '.*(Search collaborators|Buscar colaboradores).*'

# Select both peers directly from the list (each row is a Pressable that toggles its
# checkbox). We intentionally do NOT type in the search box: the search input would hold
# the same name text and Maestro would tap the input instead of the list row, leaving
# nothing selected. The picker already lists the test users, so we scroll + tap each row.
- scrollUntilVisible:
    element:
      text: '.*${PEER_1_NAME}.*'
- tapOn:
    text: '.*${PEER_1_NAME}.*'
- scrollUntilVisible:
    element:
      text: '.*${PEER_2_NAME}.*'
- tapOn:
    text: '.*${PEER_2_NAME}.*'

# Save selection (the Save button is enabled only once at least one peer is selected).
# Note: the search field does not auto-focus and we never tap it, so no keyboard is
# shown and the bottom-anchored Save button is fully visible.
- tapOn:
    text: '.*(Save|Guardar).*'
- assertVisible:
    text: '.*(Select a category|Seleccione una categoría).*'

# --- Select category ---
# "Select a category" appears twice on the form: the section label (index 0, not pressable)
# and the selector button (index 1). Tap the button (index 1) to open the category screen.
- tapOn:
    text: '.*(Select a category|Seleccione una categoría).*'
    index: 1
# On the SelectCategory screen, scroll to and tap the desired category
- scrollUntilVisible:
    element:
      text: '.*${CATEGORY_NAME}.*'
- tapOn:
    text: '.*${CATEGORY_NAME}.*'

# --- Write the acknowledgement message ---
# Tapping the message box opens a full-screen dialog with an auto-focused TextInput (focus
# fires after a ~500ms delay) plus a "Done" button in the footer. We wait for the dialog
# (its "Done" button) to appear, let autofocus settle, type, then tap "Done" to close it
# and return to the form. inputText alone does NOT close the dialog.
- tapOn:
    text: '.*(Tell them why they made a difference|Diles por qué marcaron la diferencia).*'
- extendedWaitUntil:
    visible:
      text: '.*(Done|Listo).*'
    timeout: 5000
- waitForAnimationToEnd:
    timeout: 1000
- inputText: ${KUDOS_TITLE}
- tapOn:
    text: '.*(Done|Listo).*'

# --- Publish ---
- tapOn:
    text: '.*(Publish|Publicar).*'

# Assert the acknowledgement was created. It appears at the top of the feed showing the
# selected recipients. We key off a recipient name (a stable, non-typed value) rather than
# the exact typed message, because Maestro inputText can occasionally drop a character.
- extendedWaitUntil:
    visible:
      text: '.*${PEER_1_NAME}.*'
    timeout: 8000

# React with 👍 to the newly created acknowledgement (topmost card in the feed).
# The reaction button renders the emoji + count as one pressable, so its merged label is
# like "👍 0" — we match '.*👍.*' (a bare '👍' is a full-match and would miss the count).
- tapOn:
    text: '.*👍.*'
    index: 0
