appId: world.respect.app
onFlowStart:
  - clearState: world.respect.app
  - runScript:
      file: "scripts/school_init.js"
      env:
        TESTCONTROLLER_URL: ${TESTCONTROLLER_URL}
        SCHOOL_ADMIN_PASSWORD: ${SCHOOL_ADMIN_PASSWORD}
        DIR_ADMIN_AUTH_HEADER: ${DIR_ADMIN_AUTH_HEADER}
        SCHOOL_URL: ${SCHOOL_URL}
        SCHOOL_NAME: ${SCHOOL_NAME}
        URL_SUBSTITUTION: ${URL_SUBSTITUTION}
        NAME: "001_002_add_user_direct_test"

onFlowComplete:
  - runFlow:
      file: "subflows/teardown.yaml"
      env:
        NAME: "db-final"
        TESTCONTROLLER_URL: ${TESTCONTROLLER_URL}
---
- launchApp:
    arguments:
      respect_directory: ${output.SCHOOL_URL}
- tapOn: "Get Started"
- runFlow:
    file: "subflows/get_started_select_school_by_name.yaml"
    env:
      SCHOOL_NAME: ${SCHOOL_NAME}
- tapOn:
    id: "username"
- inputText: "admin"
- tapOn:
    id : "password"
- inputText: ${SCHOOL_ADMIN_PASSWORD}
- tapOn: "Login"
- runFlow:
    when:
      visible: "Save password for Respect?"
    file: "subflows/save_password_prompt_cancel.yaml"
- tapOn: "People"
- assertVisible:
    id: "app_title"
    text: "People"
- tapOn:
    id: "ExpandableFab"   #  +Person button
- tapOn: "Add new person"
- assertVisible:
    id: "app_title"
    text: "Add person"
- tapOn: "Save"
- assertVisible: "Required field"   # First names* field is mandatory
- tapOn: "First names*"
- inputText: "ParentA"
- tapOn: "Save"
- assertVisible: "Required field"   # Last name* field is mandatory
- tapOn: "Last name*"
- inputText: "User"
- tapOn: "Save"
- assertVisible: "Required field"   # Gender field is mandatory
- tapOn:
    text: "Gender*"
    retryTapIfNoChange: true
- tapOn: "Female"
- tapOn:
    id: "role"
- tapOn: "Teacher"
- assertNotVisible: "Family member"
- tapOn:
    id: "role"
- tapOn: "Parent"
- assertVisible: "Family member"
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "ParentA User"
- tapOn:
    id: "floating_action_button"   # Edit button
- assertVisible:
    id: "app_title"
    text: "Edit person"
# Validate DOB field
- tapOn: "Date of birth"
- runScript:
    file: "scripts/setDate.js"
- inputText: ${output.futureDate}
- hideKeyboard
- tapOn: "Save"
- assertVisible: "Date of Birth cannot be in the future."
- runFlow:
    file: "subflows/erase_text.yaml"
    env:
      TEXT: "Date of birth"
- tapOn: "Date of birth"
- runScript:
    file: "scripts/setDate.js"
- inputText: ${output.pastYearDateC}
- runFlow:
    when:
      notVisible:
           id: "phone_countrycode"
    commands:
        - hideKeyboard
# Validate Phone number
- tapOn:
     id: "phone_countrycode"
- eraseText
- inputText: "+1"
- tapOn: "Phone number"
- inputText: "23"
- runFlow:
    when:
      notVisible: "Save"
    commands:
      - hideKeyboard
- tapOn: "Save"
- assertVisible: "Invalid"
- tapOn: "Phone number"
- runFlow:
    file: "subflows/erase_text.yaml"
    env:
      TEXT: "Phone number"
- inputText: "21255543268"
- runFlow:
    when:
      notVisible: "Save"
    commands:
      - hideKeyboard
- tapOn: "Save"
- assertVisible: "Invalid"
- runFlow:
    file: "subflows/erase_text.yaml"
    env:
      TEXT: "Phone number"
- inputText: "2125554326"
- tapOn: "Email"
- inputText: "ParentAuser@gm"
- runFlow:
    when:
      notVisible: "Save"
    commands:
      - hideKeyboard
- tapOn: "Save"
- assertVisible: "Enter valid email address."
- runFlow:
    file: "subflows/erase_text.yaml"
    env:
      TEXT: "Email"
- inputText: "ParentAuser@gmail.com"
- runFlow:
    when:
      notVisible: "Save"
    commands:
      - hideKeyboard
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "ParentA User"
# Add Family member - as new person
- tapOn:
    id: "floating_action_button"   # Edit button
- assertVisible:
    id: "app_title"
    text: "Edit person"
- tapOn: "Family member"
- tapOn: "Add person"
- tapOn: "First names*"
- inputText: "Child"
- tapOn: "Last name*"
- inputText: "User"
- tapOn:
    text: "Gender*"
    retryTapIfNoChange: true
- tapOn: "Female"
- assertVisible:
    id: "app_title"
    text: "Add person"
- tapOn: "Save"
- assertVisible: "Child User"
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "ParentA User"
- tapOn: "Child User"
- assertVisible:
    id: "app_title"
    text: "Child User"
- assertVisible: "Student"
- assertVisible: "ParentA User"
- tapOn: "ParentA User"
# Create account for Parent user  -- only username and password fields available for parent user
- tapOn: "Create account"
- assertVisible:
    id: "app_title"
    text: "Create account"
- assertVisible:
    id: "Username"
    text: "parentauser"
- tapOn: "Password*"
- inputText: "test"
- tapOn: "Save"
- assertVisible: "Password too short"
- runFlow:
    file: "subflows/erase_text.yaml"
    env:
      TEXT: "Password*"
- inputText: "test123"
- tapOn: "Save"
- tapOn: "Child User"
- tapOn: "Create account"
- assertVisible:
    id: "Username"
    text: "childuser"
- runFlow:
    file: "subflows/assign_qr_badge_flow.yaml"
    env:
      QR_BADGE_LINK: ${output.SCHOOL_URL}respect_school_link/personqrbadge/id/12312
# DISABLED temporarily 21/Jan/2026 by Mike - how this is handled is being changed
#- assertVisible: "Invalid QR code scanned"
#- tapOn: "Try again"
#- assertVisible:
#    id: "app_title"
#    text: "Scan QR code badge"
#- tapOn: "More Options"
#- tapOn: "Paste URL"
#- tapOn: "Url"
#- inputText:  ${output.SCHOOL_URL}respect_school_link/personqrbadge/id/12312
#- tapOn: "Ok"
- assertVisible:
    id: "app_title"
    text: "Manage account"
- assertVisible: "QR code badge"
- assertVisible: "Badge.*"
- back

# Create a student user for QR code validation
- tapOn: "People"
- assertVisible:
    id: "app_title"
    text: "People"
- tapOn:
    id: "ExpandableFab"   #  +Person button
- tapOn: "Add new person"
- assertVisible:
    id: "app_title"
    text: "Add person"
- tapOn: "First names*"
- inputText: "Test"
- tapOn: "Last name*"
- inputText: "User"
- tapOn:
    text: "Gender*"
    retryTapIfNoChange: true
- tapOn: "Female"
- tapOn:
    id: "role"
- tapOn: "Student"
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "Test User"
- tapOn: "Create account"
- assertVisible:
         id: "Username"
         text: "testuser"
- tapOn: "Set password"
- tapOn: "Password*"
- inputText: "test123"
- tapOn: "Save"
- assertVisible:
    id: "password_change_btn"  # Change password button
- assertVisible: "Last updated:.*"
# Assign QR code badge for the user
- runFlow:
    file: "subflows/assign_qr_badge_flow.yaml"
    env:
      QR_BADGE_LINK: ${output.SCHOOL_URL}respect_school_link/personqrbadge/id/12312    #Validation to ensure that one QR badge is assigned to one, and only one, student.
- assertVisible:
    id: "app_title"
    text: "Manage account"
- assertVisible: "Assign QR code badge"
- assertVisible: "This QR code is already assigned to another student"
- runFlow:
    file: "subflows/assign_qr_badge_flow.yaml"
    env:
      QR_BADGE_LINK: ${output.SCHOOL_URL}respect_school_link/personqrbadge/id/12345 #Unique QR
- assertVisible: "QR code badge"
- assertVisible: "Badge.*"
- tapOn:
    id: "qr_change_btn"
- assertVisible: "Assign new badge (replace)"
- assertVisible: "Revoke badge"
# Verify the button - Revoke badge, it should remove the assigned badge
- tapOn: "Revoke badge"
- assertVisible:
    id: "app_title"
    text: "Manage account"
- assertVisible: "Assign QR code badge"
- runFlow:
    file: "subflows/assign_qr_badge_flow.yaml"
    env:
      QR_BADGE_LINK: ${output.SCHOOL_URL}respect_school_link/personqrbadge/id/12345
- assertVisible:
    id: "app_title"
    text: "Manage account"
- assertVisible: "QR code badge"
- assertVisible: "Badge.*"
# Verify the button Assign new badge (replace) takes user to Scan QR code screen
- tapOn:
    id: "qr_change_btn"
- tapOn: "Assign new badge (replace)"
- assertVisible:
    id: "app_title"
    text: "Scan QR code badge"
- back
- assertVisible:
    id: "app_title"
    text: "Manage account"
- assertVisible: "QR code badge"

# Validate Parent User login
- runFlow:
    file: "subflows/e2e_artifact_upload.yaml"
    env:
      NAME: "db-admin-added-users"
- clearState: world.respect.app
- launchApp:
    arguments:
      respect_directory: ${output.SCHOOL_URL}
- tapOn: "Get Started"
- runFlow:
    file: "subflows/get_started_select_school_by_name.yaml"
    env:
      SCHOOL_NAME: ${SCHOOL_NAME}
- tapOn:
    id: "username"
- inputText: "parentauser"
- tapOn:
    id : "password"
- inputText: "test123"
- hideKeyboard
- tapOn: "Login"
- runFlow:
    when:
      visible: "Save password for Respect?"
    file: "subflows/save_password_prompt_cancel.yaml"
- assertVisible: "Apps"
- tapOn: "People"
- tapOn: "ParentA User"
- tapOn: "Manage account"
- assertVisible: "parentauser"
- tapOn:
    id: "password_change_btn"  # Change password button
- tapOn: "Old password*"
- inputText: "test123"
- tapOn: "New password*"
- inputText: "t2"
- tapOn: "Save"
- assertVisible: "Password must be at least 6 characters"
- tapOn: "New password*"
- eraseText
- inputText: "test234"
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "Manage account"
- back
- tapOn:
    id: "user_account_icon"
- assertVisible: "Profile"
- assertVisible: "Logout"
- assertVisible: "Family members"
- tapOn: "Child User"
# Verify simplified child mode
- assertVisible: "Assignments"
- assertVisible:
    id: "app_title"
    text: "Assignments"
- assertVisible:
       id: "nav_home"
- assertNotVisible: "Classes"
- assertNotVisible: "People"

# Validate Child User QR Login using Scan QR/badge
- runFlow:
    file: "subflows/e2e_artifact_upload.yaml"
    env:
      NAME: "db-parent-logged-in"
- clearState: world.respect.app
- launchApp:
    arguments:
      respect_directory: ${output.SCHOOL_URL}
- tapOn: "Get Started"
- tapOn: "Scan QR code/badge"
- assertVisible:
    id: "app_title"
    text: "Scan QR code badge"
- tapOn: "More Options"
- tapOn: "Paste URL"
- tapOn: "Url"
- inputText:  ${output.SCHOOL_URL}respect_school_link/personqrbadge/id/12312
- tapOn: "OK"
- assertVisible:
        id: "nav_home"
- assertVisible:
    id: "app_title"
    text: "Home"
- assertVisible: "Assignments"
- assertVisible: "Classes"
- assertVisible: "People"