Feature: Register new user

    Background:
        Given visit "Home" page
        # clear input fields persistence mechanism (just speeds up the test)
        Given clear browser storages
        When press "Registration" button at "Page content"
        Then modal of "New user registration" dialog opened


    # Path of success

    # Scenario: Fulfill user registration form (simple)

    #     # For cases where we have no selector collisions in the DOM

    #     When enter "test@example.com" in "Email" input
    #     * enter "password1234" in "Password" input
    #     * enter "password1234" in "Confirm password" input
    #     * set "Accept Service Policy" checkbox
    #     Then button "Register" is enabled
    #     When press "Register" button
    #     Then modal of "New user registration" dialog closed
    #     * modal of "Data submitted from the form" dialog opened
    #     # technical field names are used
    #     * jsonView field "Email" contains "test@example.com"
    #     * jsonView field "Password" contains "password1234"
    #     * jsonView field "Confirm password" contains "password1234"
    #     * jsonView field "Accept Service Policy" contains "true"


    Scenario: Fulfill user registration form

        When enter "test@example.com" in "Email" input at "User registration form"
        * enter "password1234" in "Password" input at "User registration form"
        * enter "password1234" in "Confirm password" input at "User registration form"
        * set "Accept Service Policy" checkbox at "User registration form"
        Then button "Register" at "User registration form" is enabled
        When press "Register" button at "User registration form"
        Then modal of "New user registration" dialog closed
        * modal of "Data submitted from the form" dialog opened
        # technical field names are used
        * jsonView field "email" contains "test@example.com"
        * jsonView field "password" contains "password1234"
        * jsonView field "password_confirm" contains "password1234"
        * jsonView field "userconsent" contains "true"


    Scenario: Switch to Sign In dialogue

        When press "Have account? - Sign In" button at "User registration form"
        Then modal of "New user registration" dialog closed
        * modal of "Sign in the restricted area" dialog opened


    Scenario: Switch to Service Policy dialogue... and back

        When click "Service Policy" link at "User registration form"
        Then modal of "New user registration" dialog closed
        * modal of "Service Policy" dialog opened
        Then button "Go to Registration" at "Service Policy form" is enabled
        When press "Go to Registration" button at "Service Policy form"
        Then modal of "Service Policy" dialog closed
        * modal of "New user registration" dialog opened


    # Validations testing

    Scenario: Registration form validations

        # prepare state of success
        Given enter "test@example.com" in "Email" input at "User registration form"
        * enter "password1234" in "Password" input at "User registration form"
        * enter "password1234" in "Confirm password" input at "User registration form"
        * set "Accept Service Policy" checkbox at "User registration form"
        * button "Register" at "User registration form" is enabled

        # do not see any error message
        Then not see "Required" at "Error message"
        * not see "Must be a valid email address" at "Error message"
        * not see "Minimum 8 symbols" at "Error message"
        * not see "Not matching with password" at "Error message"

        # Email
        When enter "" in "Email" input at "User registration form"
        Then see "Required" at "Error message"
        * button "Register" at "User registration form" is disabled
        When enter "test" in "Email" input at "User registration form"
        Then see "Must be a valid email address" at "Error message"
        * button "Register" at "User registration form" is disabled
        When enter "test@example.com" in "Email" input at "User registration form"
        Then not see "Must be a valid email address" at "Error message"
        * button "Register" at "User registration form" is enabled

        # Password
        When enter "" in "Password" input at "User registration form"
        Then see "Required" at "Error message"
        * button "Register" at "User registration form" is disabled
        When enter "test" in "Password" input at "User registration form"
        Then see "Minimum 8 symbols" at "Error message"
        * button "Register" at "User registration form" is disabled
        When enter "password1234" in "Password" input at "User registration form"
        Then not see "Minimum 8 symbols" at "Error message"
        * button "Register" at "User registration form" is enabled

        # Confirm password
        When enter "" in "Confirm password" input at "User registration form"
        Then see "Required" at "Error message"
        * button "Register" at "User registration form" is disabled
        When enter "test" in "Confirm password" input at "User registration form"
        Then see "Not matching with password" at "Error message"
        * button "Register" at "User registration form" is disabled
        When enter "password1234" in "Confirm password" input at "User registration form"
        Then not see "Not matching with password" at "Error message"
        * button "Register" at "User registration form" is enabled

        # Accept Service Policy
        When unset "Accept Service Policy" checkbox at "User registration form"
        Then see "Required" at "Error message"
        * button "Register" at "User registration form" is disabled
        When set "Accept Service Policy" checkbox at "User registration form"
        Then not see "Required" at "Error message"
        * button "Register" at "User registration form" is enabled
