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: "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: "Gender*"
- tapOn: "Female"
- tapOn:
    id: "role"
- tapOn: "Parent"
- 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."
- eraseText
- 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"
- eraseText
- inputText: "21255543268"
- runFlow:
    when:
      notVisible: "Save"
    commands:
      - hideKeyboard
- tapOn: "Save"
- assertVisible: "Invalid"
- eraseText
- inputText: "2125554326"
- tapOn: "Email"
- inputText: "ParentAuser@gm"
- runFlow:
    when:
      notVisible: "Save"
    commands:
      - hideKeyboard
- tapOn: "Save"
- assertVisible: "Enter valid email address."
- eraseText
- 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: "Gender*"
- 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: "People"
- assertVisible:
    id: "app_title"
    text: "People"
- tapOn:
    id: "floating_action_button"   #  +Person button
- assertVisible:
    id: "app_title"
    text: "Add person"
- tapOn: "First names*"
- inputText: "Test"
- tapOn: "Last name*"
- inputText: "User"
- tapOn: "Gender*"
- tapOn: "Female"
- tapOn:
    id: "role"
- tapOn: "Teacher"
- assertNotVisible: "Family member"
- tapOn:
    id: "role"
- tapOn: "Student"
- tapOn: "Family member"
- assertVisible:
    id: "app_title"
    text: "Select person"
- tapOn: "ParentA User"
- assertVisible:
    id: "app_title"
    text: "Add person"
- assertVisible: "ParentA User"
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "Test User"
- assertVisible: "ParentA User"
- tapOn: "ParentA User"
- tapOn: "Create account"
- tapOn: "Username"
- inputText: "2t"
- tapOn: "Password"  # Password validations needs to be added
- inputText: "test234"
- tapOn: "Save"
- assertVisible: "Username must be at least 3 characters"
- tapOn: "Username"
- inputText: "2est"
- tapOn: "Save"
- assertVisible: "Username cannot start with a number"  # 2est not a valid username
- eraseText
- inputText: "parenta@user"
- assertVisible: "parentauser"    # @ symbol won't get added to the username field - so "parentauser" is expected result
- tapOn: "Save"
- tapOn: "Child User"
- tapOn: "Create account"
- tapOn: "Username"
- inputText: "childuser"
- tapOn: "Password"
- inputText: "test123"
- tapOn: "Save"
- assertVisible: "Manage account"

# 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: "parentauser"
- tapOn:
    id : "password"
- inputText: "test234"
- hideKeyboard
- tapOn: "Login"
- runFlow:
    when:
      visible: "Save password for Respect?"
    file: "subflows/save_password_prompt_cancel.yaml"
- assertVisible: "Apps"
- tapOn: "People"
- tapOn: "ParentA User"
- assertVisible: "Test User"
- assertVisible: "Child User"

# Verify simplified child mode
- 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: "childuser"
- tapOn:
    id : "password"
- inputText: "test123"
- hideKeyboard
- tapOn: "Login"
- runFlow:
    when:
      visible: "Save password for Respect?"
    file: "subflows/save_password_prompt_cancel.yaml"
- assertVisible: "Assignments"
- assertVisible:
    id: "app_title"
    text: "Assignments"
- assertVisible: "Apps"
- assertNotVisible: "Classes"
- assertNotVisible: "People"