appId: ${APP_ID}
---
# Precondition: KudosTabs with Ranking tab active
# Env: CATEGORY_NAME (used to filter by category)

# Assert we are on the Ranking screen
- assertVisible: 'Ranking'

# Open the filters panel. The filter button is an icon with no visible text; it exposes
# accessibilityLabel = general.filters ("Filters"/"Filtros").
- tapOn:
    text: '.*(Filters|Filtros).*'
- extendedWaitUntil:
    visible:
      text: '.*(Filters|Filtros).*'
    timeout: 3000

# Open the Categories selector. On the Filters screen this is a row that opens a modal
# containing the category list, a search box, and a "Select" confirm button.
- tapOn:
    text: '.*(Categories|Categorías).*'

# In the modal, scroll to the desired category and tap it to toggle its selection.
- scrollUntilVisible:
    element:
      text: '.*${CATEGORY_NAME}.*'
    timeout: 5000
- tapOn:
    text: '.*${CATEGORY_NAME}.*'

# Confirm the selection. Match "Select"/"Seleccionar" EXACTLY (no .*) so it targets the
# confirm button and not the "Select all"/"Seleccionar todo" list item.
- tapOn:
    text: 'Select|Seleccionar'

# Apply the selected filters (the Apply button enables once a filter is selected).
- tapOn:
    text: '.*(Apply|Aplicar).*'

# Assert we are back on the Ranking screen with filters applied
- assertVisible: 'Ranking'
