*** 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 use the contacts app
    Given I am logged in as the user alice_lindstrom
    Then I can go to the application    Contacts
    And I can see the contact in the sidebar    HR
    And I can see the contact in the sidebar    All users
    And I cannot see the contact in the sidebar    Alice Lindström
    And I can see the group page for    All users
    And Group contains the user    Alice Lindström
    When I filter the contacts that match    al
    Then I cannot see the contact in the sidebar    HR
    And I cannot see the contact in the sidebar    All users
    And I can see the contact in the sidebar    Alice Lindström
    And I can see the contact in the sidebar    Allan Neece
    And I can see the profile for    Alice Lindström
    When I filter the contacts that match    hr
    Then I cannot see the contact in the sidebar    Production
    And I cannot see the contact in the sidebar    All users
    And I can see the group page for    HR
    And Group contains the user    Alice Lindström

Dollie can manage groups with the contacts app
    Given I am logged in as the user dollie_nocera
    Then I can go to the application    Contacts
    And I can create a group with three users
    And I can edit the group description and members


*** Keywords ***
# See lib/keywords.robot in the section "case related keywords"
I filter the contacts that match
    [Arguments]    ${query}
    Input text    jquery=#user-selector [name=SearchableText]    ${query}
    Wait for injection to be finished

I can see the contact in the sidebar
    [Arguments]    ${fullname}
    Page Should Contain Element    jquery=#user-selector-items strong:contains('${fullname}')

I cannot see the contact in the sidebar
    [Arguments]    ${fullname}
    Page Should Not Contain Element    jquery=#user-selector-items strong:contains('${fullname}')

I can see the profile for
    [Arguments]    ${fullname}
    Click Element    jquery=#user-selector-items strong:contains('${fullname}')
    Wait for injection to be finished
    Page should contain element    jquery=figure.contact-info-header figcaption:contains('${fullname}')

I can see the group page for
    [Arguments]    ${groupname}
    Click Element    jquery=#user-selector-items strong:contains('${groupname}')
    Wait for injection to be finished
    Page Should Contain Element    jquery=h1.group-title:contains('${groupname}')

Group contains the user
    [Arguments]    ${name}
    Page should contain element    jquery=#document-content #autoload-users figcaption:contains('${name}')

I can create a group with three users
    Click Link    jquery=#sidebar a:contains(Create an emergency service, group or division)
    Wait for injection to be finished
    Input text    jquery=.pat-modal .panel-content [name=title]    Three users group
    Input text    jquery=.pat-modal .panel-content [name=canonical]    The Musketeers
    I look for and select Alice in autosuggest multiselect field label.members
    I look for and select Fernando in autosuggest multiselect field label.members
    I look for and select Allan in autosuggest multiselect field label.members
    Click the modal create button no notification    \#sheet-user-group
    Wait until page contains element    jquery=#document-content h1:contains('Three users group')
    Group contains the user    Alice
    Group contains the user    Allan
    Group contains the user    Fernando

I can edit the group description and members
    Page should not contain element    jquery=#document-content #autoload-users figcaption:contains('Esmeralda')
    Click Element    jquery=#user-group-toolbar a:contains(Edit)
    Wait for injection to be finished
    Input text
    ...    jquery=#document-content [name=description]
    ...    An extended description for the test group Dollie created
    I look for and select Esmeralda in autosuggest multiselect field label:contains('Users in this group')
    Click Button    jquery=#document-content button:contains('Save')
    Wait for injection to be finished
    Group contains the user    Alice
    Group contains the user    Allan
    Group contains the user    Fernando
    Group contains the user    Esmeralda
