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_001_invite_using_invite_code_test"

onFlowComplete:
  - runScript:
      file: "scripts/teardown.js"

---

#  A) Admin add new class
- runFlow: "subflows/school_admin_login_flow.yaml"
- assertVisible:
    id: "app_title"
    text: "Apps"
- tapOn: "Classes"
- assertVisible:
    id: "app_title"
    text: "Classes"
- tapOn:
    id: "floating_action_button"   #  +Class button
- assertVisible:
    id: "app_title"
    text: "Add class"
- tapOn: "Save"
- assertVisible: "Required field"
- tapOn: "Name*"
- inputText: "New Class"
- tapOn: "Description"
- inputText: "New Course"
- tapOn: "Save"
- assertVisible:
    id: "app_title"
    text: "New Class"

# B) Admin copy invite code to the teacher
- tapOn: "Add Teacher"
- copyTextFrom:
    id: "invite_code"

# C) Teacher sign-up via invite code to the class
- 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: "I have an invite code"
- tapOn: "Invite code"
- pasteText
- tapOn: "Next"
- assertVisible:
    id: "app_title"
    text: "Invitation"
- assertVisible: "New Class"
- tapOn: "Next"
- assertVisible:
    id: "app_title"
    text: "Terms and conditions"
- tapOn: "Accept"
- assertVisible:
    id: "app_title"
    text: "Your profile"
- tapOn: "Next"
- assertVisible: "Required field" # Name is mandatory field
- tapOn: "Your name*"
- inputText: "Teacher User"
- tapOn: "Next"
- assertVisible: "Required field" # Gender is mandatory field
- tapOn: "Gender*"
- tapOn: "Female"
- tapOn: "Next"
- assertVisible: "Required field" # DOB is mandatory field
- tapOn: "Your date of birth*"
- runScript:
    file: "scripts/setDate.js"
- inputText: ${output.futureDate}
- tapOn: "Next"
- assertVisible: "Date of Birth cannot be in the future."
- eraseText
- tapOn: "Your date of birth*"
- runScript:
    file: "scripts/setDate.js"
- inputText: ${output.pastYearDateP}
- tapOn: "Next"
- assertVisible:
    id: "app_title"
    text: "Create account"
- extendedWaitUntil:
    visible: "teacheruser" #username
    timeout: 10000      # Timeout in milliseconds
- tapOn: "Next"
# passkeys are not supported on the school domain being used for end to end test so signup flow is bit different
- assertVisible: "Password*"
- tapOn: "Sign-up"
- assertVisible: "Required field" # Password is mandatory field
- tapOn: "Password*"
- inputText: "testt1"
- tapOn: "Sign-up"
- assertVisible:
    id: "app_title"
    text: "Waiting for approval"
- assertVisible: "Please wait"

# D) Admin approve teacher's request to join the class
- clearState: world.respect.app
- runFlow: "subflows/school_admin_login_flow.yaml"
- tapOn: "Classes"
- assertVisible:
    id: "app_title"
    text: "Classes"
- tapOn: "New Class"
- assertVisible: "Pending requests.*"
- assertVisible: "Teacher User.*"
- tapOn: "Accept Invite"

# E) Teacher login to the class and share invite code to Student
- 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: "teacheruser"
- tapOn:
    id : "password"
- inputText: "testt1"
- tapOn: "Login"
- assertVisible: "Apps"
- tapOn: "Classes"
- assertVisible:
    id: "app_title"
    text: "Classes"
- assertVisible: "New Class"
- tapOn: "New Class"
- assertVisible: "Teacher User.*"
- tapOn: "Add Student"
- copyTextFrom:
    id: "invite_code"

# G) Student sign-up via invite code to the class
- 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: "I have an invite code"
- tapOn: "Invite code"
- pasteText
- tapOn: "Next"
- assertVisible:
    id: "app_title"
- tapOn: "I’m a Student"
- assertVisible:
    id: "app_title"
    text: "Your profile"
- tapOn: "Your name*"
- inputText: "Student User"
- tapOn: "Gender*"
- tapOn: "Female"
- tapOn: "Your date of birth*"
- runScript:
    file: "scripts/setDate.js"
- inputText: ${output.pastYearDateC}
- tapOn: "Next"
- assertVisible:
    id: "app_title"
    text: "Create account"
- assertVisible: "studentuser"  #username
- tapOn: "Next"
- tapOn: "Password*"
- inputText: "tests1"
- tapOn: "Sign-up"
- assertVisible:
    id: "app_title"
    text: "Waiting for approval"
- assertVisible: "Please wait"

# H) Teacher approve student's request to join the class
- 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: "teacheruser"
- tapOn:
    id : "password"
- inputText: "testt1"
- tapOn: "Login"
- assertVisible: "Apps"
- tapOn: "Classes"
- assertVisible:
    id: "app_title"
    text: "Classes"
- tapOn: "New Class"
- assertVisible: "Pending requests.*"
- assertVisible: "Student User.*"
- tapOn: "Accept Invite"
- tapOn: "Add Student"
- copyTextFrom:
    id: "invite_code"

# I) Student login to the class
- 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: "studentuser"
- tapOn:
    id : "password"
- inputText: "tests1"
- tapOn: "Login"
- assertVisible: "Apps"
- tapOn: "Classes"
- assertVisible:
    id: "app_title"
    text: "Classes"
- assertVisible: "New Class"
- tapOn: "New Class"
- assertVisible: "Student User.*"

# G) Parent sign-up their child to the class using invite code
- 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: "I have an invite code"
- tapOn: "Invite code"
- pasteText
- tapOn: "Next"
- assertVisible:
    id: "app_title"
    text: "Invitation"
- tapOn: "I’m a parent"
- assertVisible:
    id: "app_title"
    text: "Terms and conditions"
- tapOn: "Accept"
- assertVisible:
    id: "app_title"
    text: "Your profile"
- tapOn: "Your name*"
- inputText: "Parent User"
- tapOn: "Gender*"
- tapOn: "Female"
- tapOn: "Your date of birth*"
- runScript:
    file: "scripts/setDate.js"
- inputText: ${output.pastYearDateP}
- tapOn: "Next"
- assertVisible:
    id: "app_title"
    text: "Create account"
- extendedWaitUntil:
    visible: "parentuser" #username
    timeout: 10000
- tapOn: "Next"
# passkeys are not supported on the school domain being used for end to end test so signup flow is bit different
- tapOn: "Password*"
- inputText: "testp1"
- tapOn: "Sign-up"
- assertVisible:
    id: "app_title"
    text: "Child Profile"
- tapOn: "Child's name*"
- inputText: "Child User"
- tapOn: "Gender*"
- tapOn: "Male"
- tapOn: "Child's date of birth*"
- runScript:
    file: "scripts/setDate.js"
- inputText: ${output.pastYearDateC}
- hideKeyboard
- tapOn: "Done"
- assertVisible:
    id: "app_title"
    text: "Waiting for approval"
- assertVisible: "Please wait"

# H) Teacher approve student's request to join the class
- 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: "teacheruser"
- tapOn:
    id : "password"
- inputText: "testt1"
- tapOn: "Login"
- assertVisible: "Apps"
- tapOn: "People"
- assertVisible: "Parent User"
- assertVisible: "Child User"
- tapOn: "Classes"
- assertVisible:
    id: "app_title"
    text: "Classes"
- tapOn: "New Class"
- assertVisible: "Pending requests.*"
- assertVisible: "Child User.*"
- tapOn: "Accept Invite"

# I) Parent login to the class
- 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: "parentuser"
- tapOn:
    id : "password"
- inputText: "testp1"
- tapOn: "Login"
- assertVisible: "Apps"
- tapOn: "Classes"
- assertVisible:
    id: "app_title"
    text: "Classes"
- assertVisible: "New Class"
- tapOn: "New Class"
- assertVisible: "Child User"