appId: ${APP_ID}
---
# Assumes Libraries home screen is visible with LIBRARY_NAME in the list.
# Opens the library, verifies content (body, attachments, sub-library).

# === OPEN LIBRARY ===
- tapOn:
    text: '.*${LIBRARY_NAME}.*'

# Library header shows the title
- assertVisible:
    text: '.*${LIBRARY_NAME}.*'

# === BODY CONTENT VERIFICATION ===
# When a library has both body content AND sub-libraries, two content tabs
# appear: "General" (body + attachments) and "Subarticles" (sub-pages only).
# Their presence confirms the library has both text/media content and children.
- runFlow:
    when:
      visible: 'General'
    commands:
      - assertVisible: 'General'
      - assertVisible: 'Subarticles'
      - tapOn: 'General'

# === ATTACHMENTS VERIFICATION + PREVIEW ===
# "Downloadable content" section header appears when the library has file attachments.
# The "Test E2E" library contains, in order: Image, Video (.mp4), PDF.
# Each Attachment card renders a "Preview" button (t('general.preview')).
# Tapping Preview downloads the file and opens iOS QuickLook, which always
# exposes a "Done" button in the navigation bar — that is our assertion target.
- scrollUntilVisible:
    element: 'Downloadable content'
    direction: DOWN
- assertVisible: 'Downloadable content'

# Preview Image (first attachment, index 0)
- tapOn:
    text: 'Preview'
    index: 0
- extendedWaitUntil:
    visible: 'Done'
    timeout: 30000
- assertVisible: 'Done'
- tapOn: 'Done'

# Preview Video (second attachment, index 1 — 15 MB, allow extra download time)
- tapOn:
    text: 'Preview'
    index: 1
- extendedWaitUntil:
    visible: 'Done'
    timeout: 60000
- assertVisible: 'Done'
- tapOn: 'Done'

# Preview PDF (third attachment, index 2)
- tapOn:
    text: 'Preview'
    index: 2
- extendedWaitUntil:
    visible: 'Done'
    timeout: 30000
- assertVisible: 'Done'
- tapOn: 'Done'

# === SUB-LIBRARY VERIFICATION ===
# Sub-pages section and the "Sub test E2E" child entry are always rendered
# on the General tab (not hidden behind the Subarticles chip).
- scrollUntilVisible:
    element: '.*${SUB_LIBRARY_NAME}.*'
    direction: DOWN
- assertVisible:
    text: '.*${SUB_LIBRARY_NAME}.*'

# Navigate into the sub-library
- tapOn:
    text: '.*${SUB_LIBRARY_NAME}.*'

# Sub-library header shows its title
- assertVisible:
    text: '.*${SUB_LIBRARY_NAME}.*'

# Return to parent library
- tapOn: Back
- assertVisible:
    text: '.*${LIBRARY_NAME}.*'

# Return to Libraries home (nav header not in iOS a11y tree; assert the list item instead)
- tapOn: Back
- assertVisible: 'Test E2E'
