*** Settings ***

Library  plone.act.PloneLibrary
Library  Selenium2Library  run_on_failure=Capture Page Screenshot
Variables  plone/app/testing/interfaces.py
Resource  plone/act/keywords.txt

Suite Setup  Open Plone Root

Suite Teardown  Close All Browsers

*** Test cases ***

Anonymous shouldn't see toolbar
    Log out
    Page Should Not Contain Element  id=plone-toolbar

Logged in should see toolbar
    Log in as site owner
    Page Should Contain Element  id=plone-toolbar

Toolbar should contain content action tabs
    Log in as site owner
    Go to  ${PLONE_URL}

    Wait Until Page Contains Element  id=toolbar

    Frame Should Contain  id=toolbar  Contents
    Frame Should Contain  id=toolbar  View
    # The 'Edit' button is not present, as we are viewing a Plone Site, not
    #   a default front page for a Plone Site.
    Frame Should Contain  id=toolbar  Rules
    Frame Should Contain  id=toolbar  Sharing

Toolbar should contain document actions menus
    Log in as site owner
    Go to  ${PLONE_URL}

    Wait Until Page Contains Element  id=toolbar

    Frame Should Contain  id=toolbar  Display
    Frame Should Contain  id=toolbar  Add new

Contents tab should open folder listing
    Log in as site owner
    Go to  ${PLONE_URL}

    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  Contents
    Click Link  Contents

    Location Should Contain  folder_contents

Edit tab should open edit view
    Log in as site owner
    Go to  ${TEST_FOLDER}

    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  Edit
    Click Link  Edit

    Location Should Be  ${TEST_FOLDER}/edit

View tab should return to view
    Log in as site owner
    Go to  ${TEST_FOLDER}/edit

    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  View
    Click Link  View

    Location Should Be  ${TEST_FOLDER}

Rules tab should open rules view
    Log in as site owner
    Go to  ${PLONE_URL}

    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  Rules
    Click Link  Rules

    Location Should Be  ${PLONE_URL}/@@manage-content-rules

Sharing tab should open sharing view
    Log in as site owner
    Go to  ${PLONE_URL}

    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  Sharing
    Click Link  Sharing

    Location Should Be  ${PLONE_URL}/@@sharing

Actions menu dropdown should open on click
    Log in as site owner
    Go to  ${TEST_FOLDER}
    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  Actions

    Element Should Not Be Visible  id=cut
    Click Element  xpath=id('plone-contentmenu-actions')/a

    Element Should Be Visible  id=cut

Display menu dropdown should open on click
    Log in as site owner
    Go to  ${TEST_FOLDER}
    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  Display

    Element Should Not Be Visible  id=contextSetDefaultPage
    Click Element  xpath=id('plone-contentmenu-display')/a

    Element Should Be Visible  id=contextSetDefaultPage

Factories menu dropdown should open on click
    Log in as site owner
    Go to  ${TEST_FOLDER}
    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  Add new…

    Element Should Not Be Visible  id=document
    Click Element  xpath=id('plone-contentmenu-factories')/a

    Element Should Be Visible  id=document

Workflow menu dropdown should open on click
    Log in as site owner
    Go to  ${TEST_FOLDER}
    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  State:

    Element Should Not Be Visible  id=advanced
    Click Element  xpath=id('plone-contentmenu-workflow')/a

    Element Should Be Visible  id=advanced

Personal actions dropdown should open on click
    Log in as site owner
    Go to  ${TEST_FOLDER}
    Wait Until Page Contains Element  id=toolbar
    Select Frame  id=toolbar
    Wait Until Keyword Succeeds  3  5  Current Frame Contains  State:

    Element Should Not Be Visible  id=plone-personal-actions-logout
    Click Element  xpath=id('plone-personal-actions')/a

    Element Should Be Visible  id=plone-personal-actions-logout
