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}
- runFlow:
    when:
      notVisible: "Save"
    commands:
      - 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"
- runFlow:
    when:
      notVisible: "Save"
    commands:
      - hideKeyboard
- tapOn: "Save"
- assertVisible: "Invalid"
- 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"

# Create account for Parent user  -- only username and password fields available for parent user
- tapOn: "ParentA User"
- tapOn: "Create account"
- assertVisible:
    id: "app_title"
    text: "Create account"
- tapOn: "Save"
- assertVisible: "Require field"  # username is mandatory field
- tapOn: "Username"
- inputText: "pa"
- tapOn: "Save"
- assertVisible: "Username must be at least 3 characters"
- tapOn: "Username"
- inputText: "parentauser"
- tapOn: "Save"
- assertVisible: "Required field" # Password is mandatory field
- tapOn: "Password*"
- inputText: "test"
- tapOn: "Save"
- assertVisible: "Password should be at least 6 characters"
- eraseText
- inputText: "test123"
- tapOn: "Save"
- assertVisible: "Manage account"


# Create account for Child user
- tapOn: "Child User"
- tapOn: "Create account"
- tapOn: "Username"
- inputText: "childuser"
 # Assign QR code badge for the user
- tapOn: "Assign QR code badge"
- assertVisible:
          id: "app_title"
          text: "Scan QR code badge"
- tapOn: "More Info"
- tapOn: "Paste URL"
- tapOn: "Url"
- inputText:  ${output.SCHOOL_URL} #Invalid url
- tapOn: "OK"
- assertVisible: "Invalid url, please try again"
- eraseText
- inputText:  ${output.SCHOOL_URL}respect_qr_badge/id/123121
- tapOn: "Ok"
- assertVisible:
    id: "app_title"
    text: "Manage account"
- assertVisible: "QR code badge"
- assertVisible: "Badge.*"
- tapOn:
    id: "qr_change_btn"
- assertVisible: "Assign new badge (replace)"
- assertVisible: "Revoke badge"
# Verify the button Assign new badge (replace) takes user to Scan QR code screen
- 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"
# Verify the button - Revoke badge, it should remove the assigned badge
- tapOn:
    id: "qr_change_btn"
- tapOn: "Revoke badge"
- assertVisible:
    id: "app_title"
    text: "Manage account"
- assertVisible: "Assign QR code badge"
- tapOn: "Assign QR code badge"
- assertVisible:
    id: "app_title"
    text: "Scan QR code badge"
- tapOn: "More Info"
- tapOn: "Paste URL"
- tapOn: "Url"
- inputText:  ${output.SCHOOL_URL}respect_qr_badge/id/123121
- tapOn: "OK"
- assertVisible:
    id: "app_title"
    text: "Manage account"
- assertVisible: "QR code badge"
- assertVisible: "Badge.*"
- back
- tapOn: "People"
- tapOn: "Test User"
# Create account for Test User
- tapOn: "Create account"
- tapOn: "Username"
- inputText: "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
- tapOn: "Assign QR code badge"
- assertVisible:
    id: "app_title"
    text: "Scan QR code badge"
- tapOn: "More Info"
- tapOn: "Paste URL"
- tapOn: "Url"
- inputText:  ${output.SCHOOL_URL}respect_qr_badge/id/123121     #Validations needs to implement
- tapOn: "Ok"
- assertVisible: "QR already in use, try again"
- eraseText
- inputText:  ${output.SCHOOL_URL}respect_qr_badge/id/983123 #Unique QR
- tapOn: "Ok"
- assertVisible: "QR code badge"
- assertVisible: "Badge.*"
- tapOn: "Save"

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

# Validate Child User QR Login using Scan QR/badge
- 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 Info"
- tapOn: "Paste URL"
- tapOn: "Url"
- inputText:  ${output.SCHOOL_URL}respect_qr_badge/id/123121
- tapOn: "OK"
- assertVisible: "Apps"
- assertVisible: "Assignments"

