*** 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 ***
Library shows sections and subsections
    Given I browse to the library
    Page should contain    Human Resources
    Page should contain    Information from the HR department
    Page should contain    Leave policies

Library section shows subsections and sub-subsections
    Given I browse to a section
    Page should contain    Leave policies
    Page should contain    Holidays and sick leave
    Page should contain    Pregnancy

Library folder shows documents
    Given I browse to a folder
    Page should contain    Holidays

Library document shows navigation
    Given I browse to a document
    Element should be visible    jquery=a.ueber-back-button:contains("Leave policies")

Library tag view is enabled
    Given I browse to the library
    When I switch to the by-tags listing
    Wait until page contains    I ♥ UTF-8

Guy cannot see the library options menu
    I am logged in as the user guy_hackey
    Go To    ${PLONE_URL}/library/human-resources/view
    Wait for injection to be finished
    Page Should Contain Element    jquery=#page-functions .canvas-toolbar-search-field
    Page Should Not Contain Element    jquery=#page-functions .icon.more

Alice can see the library options menu
    I am logged in as the user alice_lindstrom
    Go To    ${PLONE_URL}/library/human-resources/view
    Wait for injection to be finished
    Page Should Contain Element    jquery=#page-functions .canvas-toolbar-search-field
    Page Should Contain Element    jquery=#page-functions .icon.more

Verify library sharing through the sharing panel
    I am logged in as the user alice_lindstrom
    Go To    ${PLONE_URL}/library/human-resources/view
    Wait for injection to be finished
    # Share the folder to the HR group
    Click Element    jquery=#page-functions .icon.more
    Wait for injection to be finished
    Click Element    jquery=.tippy-content .icon-pencil
    Wait for injection to be finished
    Select from autocomplete    maintainer_group_list    HR
    Click Button    Save
    # Verify a member of the HR group has now the power to further assign maintainer to a subfolder
    I am logged in as the user guy_hackey
    Go To    ${PLONE_URL}/library/human-resources/leave-policies/view
    Page Should Contain Element    jquery=#page-functions .icon.more
    Click Element    jquery=#page-functions .icon.more
    Wait for injection to be finished
    Click Element    jquery=.tippy-content .icon-pencil
    Wait for injection to be finished
    # Verify we also have the pill marked as disabled that shows "inherited" groups
    Page Should Contain Element    jquery=.select2-search-choice.disabled div:contains('HR')
    Select from autocomplete    maintainer_group_list    Calendar
    Click Button    Save


*** Keywords ***
I browse to the library
    I am logged in as the user allan_neece
    Go To    ${PLONE_URL}
    Click Link    jquery=#portal-tabs a:contains("Library")
    Wait for injection to be finished

I browse to a section
    I browse to the library
    Click Link    Human Resources
    Wait for injection to be finished

I browse to a folder
    I browse to the library
    Click Link    Leave policies
    Wait for injection to be finished

I browse to a document
    I browse to a section
    Click Link    Holidays
    Wait for injection to be finished

I switch to the by-tags listing
    Click element    css=select[name=groupby]
    Click element    css=option[value=tag]
    Wait for injection to be finished
