*** Keywords ***

Suite Setup
    Open browser  ${front-page}

Suite Teardown
    Close All Browsers

Create Collection
    [Arguments]  ${title}
    Go to  ${test-folder}/++add++Collection
    Input text  name=form.widgets.IBasic.title  ${title}
    Click Button  Save

Live Preview number of results should be
    [Arguments]  ${number}
    Wait Until Page Contains  ${number} items matching your search terms.

Live Preview should contain
    [Arguments]  ${title}
    Page should contain  ${title}

Set Review state Criterion
    Wait Until Page Contains Element  xpath=//select[@name="addindex"]
    Select From List  xpath=//select[@name="addindex"]  Review state
    Wait Until Page Contains Element  xpath=//select[@class='queryoperator']
    Click Element  xpath=//div[@class='criteria']/dl
    Select Checkbox  published
    Live Preview number of results should be  1
    Live Preview should contain  Published Document
    Click Button  Save

Set Creator Criterion To
    [Arguments]  ${creator_criterion}
    Wait Until Page Contains Element  xpath=//select[@name="addindex"]
    Select From List  xpath=//select[@name="addindex"]  Creator
    Wait Until Page Contains Element  xpath=//select[@class='queryoperator']
    Select From List  xpath=//select[@class='queryoperator']  Is
    Input Text  name=form.widgets.query.v:records  ${creator_criterion}
    Wait Until Page Contains  2 items matching your search terms.
    Live Preview should contain  Test user document
    Click Button  Save

Set Relative Location Criterion To
    [Arguments]  ${relative_path_criterion}
    Wait Until Page Contains Element  xpath=//select[@name="addindex"]
    Select From List  xpath=//select[@name="addindex"]  Location
    Wait Until Page Contains Element  xpath=//select[@class='queryoperator']
    Select From List  xpath=//select[@class='queryoperator']  Relative path
    Input Text  name=form.widgets.query.v:records  ${relative_path_criterion}
    Click Button  Save

Set Short name (id) Criterion
    Wait Until Page Contains Element  xpath=//select[@name="addindex"]
    Select From List  xpath=//select[@name="addindex"]  Short name (id)
    Wait Until Page Contains Element  xpath=//select[@class='queryoperator']
    Input Text  name=form.widgets.query.v:records  first-document
    Wait Until Page Contains  1 items matching your search terms.
    Page should contain  First Document
    Click Button  Save

Set Type Criterion
    Wait Until Page Contains Element  xpath=//select[@name="addindex"]
    Select From List  xpath=//select[@name="addindex"]  Type
    Wait Until Page Contains Element  xpath=//select[@class='queryoperator']
    Click Element  xpath=//div[@class='criteria']/dl
    Select Checkbox  Document
    Wait Until Page Contains  1 items matching your search terms.
    Page should contain  My Document
    Click Button  Save

Add collection
    Go to  ${test-folder}/my-collection/edit
    Click Link  xpath=//input[@name='form.widgets.query.v:records:list']
    Click Link  collection
    Page should contain  Add Collection
    Page should contain  Description
    Page should contain  Search terms

    Input text  form.widgets.IBasic.title  My Collection
    Wait Until Page Contains Element  xpath=//select[@name="addindex"]
    Select From List  xpath=//select[@name="addindex"]  Description
    Input text  form.widgets.query.v:records  Plone

    Click Button  Save
    Page should contain  My Collection
