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:
  - runScript:
      file: "scripts/teardown.js"
---
- runFlow: "subflows/school_admin_login_flow.yaml"

- tapOn: "People"
- assertVisible:
    id: "app_title"
    text: "People"
- tapOn:
    id: "floating_action_button"   #  +Person button
- assertVisible:
    id: "app_title"
    text: "Add person"
- tapOn: "Save"
- assertVisible: "Required field"   # First names* field is mandatory
- tapOn: "First names*"
- inputText: "Test"
- 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: "Gender*"
- tapOn: "Female"
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "Test 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."
- eraseText
- tapOn: "Date of birth"
- runScript:
    file: "scripts/setDate.js"
- inputText: ${output.pastYearDateC}
- hideKeyboard

# Validate Phone number
- tapOn:
     id: "phone_countrycode"
- eraseText
- inputText: "+1"
- tapOn: "Phone number"
- inputText: "23"
- hideKeyboard
- tapOn: "Save"
- assertVisible: "Invalid"
- tapOn: "Phone number"
- eraseText
- inputText: "21255543268"
- hideKeyboard
- tapOn: "Save"
- assertVisible: "Invalid"
- eraseText
- inputText: "2125554326"
- tapOn: "Email"
- inputText: "Testuser@gm"
- hideKeyboard
- scrollUntilVisible:
    element:
      text: "Save" # or any other selector
    direction: UP
    timeout: 1000
- tapOn: "Save"
- assertVisible: "Enter valid email address."
- eraseText
- inputText: "Testuser@gmail.com"
- assertVisible: "Testuser@gmail.com"
- hideKeyboard
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "Test User"
- tapOn: "Create account"
- tapOn: "Username"
- inputText: "testuser"
- tapOn: "Password"  # Password validations needs to be added
- inputText: "test234"
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "Test User"

# Validate User login
- 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: "testuser"
- tapOn:
    id : "password"
- inputText: "test234"
- tapOn: "Login"
- runFlow:
    when:
      visible: "Save password for Respect?"
    file: "subflows/save_password_prompt_cancel.yaml"
- assertVisible: "Home"
- tapOn: "People"
- tapOn: "Test User"
- tapOn: "Manage account"
- assertVisible: "testuser"
- tapOn: "Change"
- tapOn: "Old password*"
- inputText: "test234"
- tapOn: "New password*"
- inputText: "t2"
- tapOn: "Save"
- assertVisible: "Password must be at least 6 characters"
- tapOn: "New password*"
- eraseText
- inputText: "test123"
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "Manage account"


# Validate User login after changing password
- 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: "testuser"
- tapOn:
    id : "password"
- inputText: "test123"
- tapOn: "Login"
- runFlow:
    when:
      visible: "Save password for Respect?"
    file: "subflows/save_password_prompt_cancel.yaml"
- assertVisible: "Home"