*** Settings ***
Variables           variables.py
Resource            plone/app/robotframework/selenium.robot
Resource            plone/app/robotframework/keywords.robot
Resource            ../lib/keywords.robot
Library             Remote    ${PLONE_URL}/RobotRemote
Library             DebugLibrary

Test Setup          Prepare test browser
Test Teardown       Close all browsers


*** Test Cases ***
Alice can view her own profile
    Given I am logged in as the user alice_lindstrom
    Then I can open the personal tools menu
    And I can follow the link to my profile
    And I can see details for Alice Lindström

Alice can logout
    Given I am logged in as the user alice_lindstrom
    Then I can open the personal tools menu
    Then I can follow the link to logout

Alice cannot view her personal preferences
    Given I am logged in as the user alice_lindstrom
    When I open the personal preferences page
    Then The page is not found

Alice can view her documents
    Given I am logged in as the user alice_lindstrom
    Then I can view the profile for user alice_lindstrom
    And I open the profile tab    Documents
    Then Click Link    Pregnancy

Alice can view her documents sorted by date
    Given I am logged in as the user alice_lindstrom
    Then I can view the profile for user alice_lindstrom
    Then I open the profile tab    Documents
    Then I can see my documents grouped by    date

Alice can search her documents
    Given I am logged in as the user alice_lindstrom
    Then I can view the profile for user alice_lindstrom
    And I open the profile tab    Documents
    Then I can search in my documents for    Holidays

Alice cannot force the password reset form
    Given I am logged in as the user alice_lindstrom
    When I open the password reset form
    Then I cannot reset my password with an illegal request posing as    alice_lindstrom

Allan can view Alice's profile
    Given I am logged in as the user allan_neece
    Then I can view the profile for user alice_lindstrom
    And I can see details for Alice Lindström

Allan can follow Christian
    Given I am logged in as the user allan_neece
    Then I can view the profile for user christian_stoney
    And I can follow Christian Stoney
    Then I can open the personal tools menu
    And I can follow the link to my profile
    And I can see Christian Stoney in the list of users being followed

Dollie can unfollow Guy
    Given I am logged in as the user dollie_nocera
    Then I can view the profile for user guy_hackey
    And I can unfollow Guy Hackey
    Then I can open the personal tools menu
    And I can follow the link to my profile
    And I cannot see Guy Hackey in the list of users being followed

Dollie can change her details
    Given I am logged in as the user dollie_nocera
    And I can view the profile for user dollie_nocera
    Then I can change my name to Mickey
    And I can view the profile for user dollie_nocera
    Then I can see my name is Mickey Nocera

Dollie can hide her email
    Given I am logged in as the user dollie_nocera
    And I can view the profile for user dollie_nocera
    Then The email is visible on the profile
    When I hide my email address
    And I can view the profile for user dollie_nocera
    Then The email is not visible on the profile
    When I am logged in as the user alice_lindstrom
    And I can view the profile for user dollie_nocera
    Then The email is not visible on the profile

Dollie cannot change Guy's details
    Given I am logged in as the user dollie_nocera
    And I can view the profile for user guy_hackey
    Then I cannot edit personal details

Dollie can change her password
    Given I am logged in as the user dollie_nocera
    And I open the change password form
    Then I change my password to    new_password
    And I can log in with the new password    dollie_nocera    new_password
    Then I see the avatar of    Dollie Nocera

Dollie can change her avatar from her profile page
    Given I am logged in as the user dollie_nocera
    And I can view the profile for user dollie_nocera
    Then I can upload a new avatar from my profile


*** Keywords ***
I can open the personal tools menu
    Click Element    css=header #user-avatar
    Wait Until Element Is Visible    css=.tooltip-container .menu

I open the personal preferences page
    Go To    ${PLONE_URL}/@@personal-preferences

I can follow the link to my profile
    Click Element    css=.tooltip-container .menu a.icon-user

I can see my documents grouped by
    [Arguments]    ${VALUE}
    Select from List By Value    group-by    date
    Wait until element is visible    jquery=.group:last a:contains("Holidays")

I can search in my documents for
    [Arguments]    ${VALUE}
    Input Text    jquery=#person-documents [name=SearchableText]    ${VALUE}
    Wait Until Page Does Not Contain Element    css=.injecting-content
    Click Element    jquery=#search-result a:contains("${VALUE}")

I open the profile tab
    [Arguments]    ${title}
    Wait until element is visible    jquery=nav a:contains('${title}')
    Click Element    jquery=nav a:contains('${title}')
    Wait Until Page Does Not Contain Element    css=.injecting-content

I can follow the link to logout
    Click Element    css=.tooltip-container .menu a.icon-exit
    Wait until page contains element    css=#login-panel #submit-button

I can view the profile for user ${USERID}
    Go To    ${PLONE_URL}/profiles/${USERID}

I can see details for ${NAME}
    Element should contain    css=#document-content .contact-info-header figcaption    ${NAME}

The email is visible on the profile
    Element should be visible    css=div#user-data-content dt.icon-mail
    Click Element    link=Information
    Wait for injection to be finished
    Element should be visible    css=div#user-data-view dt.icon-mail

The email is not visible on the profile
    Element should not be visible    css=div#user-data-content dt.icon-mail
    Click Element    link=Information
    Wait for injection to be finished
    Element should not be visible    css=div#user-data-view dt.icon-mail

I can follow ${NAME}
    Wait Until Page Contains Element    jquery=#follow-button-contacts:contains("Follow")
    Click Element    jquery=#follow-button-contacts:contains("Follow")
    Wait Until Page Contains Element    jquery=#follow-button-contacts:contains("Unfollow")

I can unfollow ${NAME}
    Wait Until Page Contains Element    jquery=#follow-button-contacts:contains("Unfollow")
    Click Element    jquery=#follow-button-contacts:contains("Unfollow")
    Wait Until Page Contains Element    jquery=#follow-button-contacts:contains("Follow")

I can see ${NAME} in the list of users being followed
    I open the profile tab    Following
    Page should contain Element    jquery=#autoload-users a figcaption:contains("${NAME}")

I cannot see ${NAME} in the list of users being followed
    I open the profile tab    Following
    Page should not contain Element    jquery=#autoload-users a figcaption:contains("${NAME}")

I can change my name to ${NAME}
    Click Element    link=Information
    Wait for injection to be finished
    Click Element    jquery=#user-data-view .functions .icon-pencil
    Wait for injection to be finished
    Wait Until Page Contains Element    jquery=[name='form.widgets.first_name']
    Input Text    name=form.widgets.first_name    ${NAME}
    Click Element    jquery=#user-data-view .pat-button:contains('Save')
    Wait until page contains element    jquery=#user-data-view .functions .icon-pencil

I hide my email address
    Click Element    jquery=#user-data-view .functions .icon-pencil
    Wait for injection to be finished
    Wait Until Page Contains Element    jquery=[name='form.widgets.hide_email:list']
    Select checkbox    name=form.widgets.hide_email:list
    Click Element    jquery=#user-data-view .pat-button:contains('Save')
    Wait until page contains element    jquery=#user-data-view .functions .icon-pencil

I can see my name is ${NAME}
    Wait until page contains element    jquery=figcaption:contains("${NAME}")

I cannot edit personal details
    I open the profile tab    Info
    Page Should Not Contain Element    jquery=a.pat-button:contains("Edit")

I can upload a new avatar from the menu
    Choose File    xpath=(//input[@name='portrait'])[1]    ${UPLOADS}/new-profile.jpg
    Wait until page contains    Personal image updated

I open the change password form
    I can open the personal tools menu
    Click Element    css=.tooltip-container .menu a.icon-key
    Wait until page contains element    xpath=//h1[text()="Change password"]

I change my password to
    [Arguments]    ${pwd}
    Input text for sure    name=form.widgets.current_password    secret
    Input text for sure    name=form.widgets.new_password    ${pwd}
    Input text for sure    name=form.widgets.new_password_ctl    ${pwd}
    Click button    Change password
    Wait until page contains    Password changed
    Close notification

I can log in with the new password
    [Arguments]    ${userid}    ${pwd}
    I can open the personal tools menu
    I can follow the link to logout
    Enter the Credentials    ${userid}    ${pwd}

I see the avatar of
    [Arguments]    ${fullname}
    Wait Until Page Contains Element    jquery=#user-avatar > img[alt="${fullname}"]

I can upload a new avatar from my profile
    # Make the file input visible otherwise "Choose file will not work"
    Execute Javascript
    ...    jQuery('#change-personal-image > label.icon-pencil').removeClass('edit').removeClass('iconified').css({'font-size': '0.5em'})
    Wait for injection to be finished
    Choose File    css=#change-personal-image [name=portrait]    ${UPLOADS}/new-profile.jpg
    Submit form    css=#change-personal-image
    Wait Until Page Contains Element    css=.injecting-content
    Wait for injection to be finished
