Feature: Sign In user

    Background:
        Given visit "Home" page
        # clear input fields persistence mechanism (just speeds up the test)
        Given clear browser storages
        When press "Sign In" button at "Page content"
        Then modal of "Sign in the restricted area" dialog opened


    # Path of success

    Scenario: Fulfill user Sign In form with Remember me set
        When enter "test@example.com" in "Email" input at "Sign In form"
        * enter "password1234" in "Password" input at "Sign In form"
        * set "Remember me" checkbox at "Sign In form"
        Then button "Sign In" at "Sign In form" is enabled
        When press "Sign In" button at "Sign In form"
        Then modal of "Sign in the restricted area" 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 "remember_me" contains "true"


    Scenario: Fulfill user Sign In form with Remember me unset

        When enter "test@example.com" in "Email" input at "Sign In form"
        * enter "password1234" in "Password" input at "Sign In form"
        * unset "Remember me" checkbox at "Sign In form"
        Then button "Sign In" at "Sign In form" is enabled
        When press "Sign In" button at "Sign In form"
        Then modal of "Sign in the restricted area" 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 "remember_me" contains "false"


    Scenario: Switch to Register new user dialogue

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


    Scenario: Switch to Forgotten password recovery dialogue

        When click "Forgot password?" link at "Sign In form"
        Then modal of "Sign in the restricted area" dialog closed
        * modal of "Forgotten password recovery" dialog opened


    # Validations testing

    Scenario: Sign In form validations

        # prepare state of success
        Given enter "test@example.com" in "Email" input at "Sign In form"
        * enter "password1234" in "Password" input at "Sign In form"
        * button "Sign In" at "Sign In form" is enabled

        Then not see "Required" at "Error message"
        * not see "Must be a valid email address" at "Error message"

        When enter "" in "Email" input at "Sign In form"
        Then see "Required" at "Error message"
        * button "Sign In" at "Sign In form" is disabled

        When enter "test" in "Email" input at "Sign In form"
        Then see "Must be a valid email address" at "Error message"
        * button "Sign In" at "Sign In form" is disabled

        When enter "test@example.com" in "Email" input at "Sign In form"
        Then not see "Must be a valid email address" at "Error message"
        * button "Sign In" at "Sign In form" is enabled

        When enter "" in "Password" input at "Sign In form"
        Then see "Required" at "Error message"
        * button "Sign In" at "Sign In form" is disabled
        When enter "password1234" in "Password" input at "Sign In form"
        Then not see "Required" at "Error message"
        * button "Sign In" at "Sign In form" is enabled
