*** Settings ***

Library  Remote  ${PLONE_URL}/RobotRemote

Variables  plone/app/contenttypes/tests/robot/variables.py

*** Keywords ***

I am logged in as site owner
  Enable autologin as  Site Administrator

Click Edit
  Click Link  xpath=//a[contains(., "Edit")]

# ----------------------------------------------------------------------------
# Content
# ----------------------------------------------------------------------------

a collection
  [Arguments]  ${title}
  [Return]  ${uid}
  ${uid} =  Create content  type=Collection  title=${title}

a document
  [Arguments]  ${title}
  [Return]  ${uid}
  ${uid} =  Create content  type=Document  title=${title}

a event
  [Arguments]  ${title}
  [Return]  ${uid}
  ${uid} =  Create content  type=Event  title=${title}

a file
  [Arguments]  ${title}
  Go to  ${PLONE_URL}/++add++File
  Wait until page contains  Add File
  Input text  name=form.widgets.title  ${title}
  Choose File  name=form.widgets.file  ${PATH_TO_TEST_FILES}/file.pdf
  Click Button  Save
  Wait until page contains  Item created

a folder
  [Arguments]  ${title}
  [Return]  ${uid}
  ${uid} =  Create content  type=Folder  title=${title}

a image
  [Arguments]  ${title}
  Go to  ${PLONE_URL}/++add++Image
  Wait until page contains  Add Image
  Input text  name=form.widgets.title  ${title}
  Choose File  name=form.widgets.image  ${PATH_TO_TEST_FILES}/image.png
  Click Button  Save
  Wait until page contains  Item created  error=Image could not be created.

a link
  [Arguments]  ${title}
  [Return]  ${uid}
  ${uid} =  Create content  type=Link  title=${title}


a news item
  [Arguments]  ${title}
  Go to  ${PLONE_URL}/++add++News Item
  Wait until page contains  Add News Item
  Input text  name=form.widgets.IDublinCore.title  ${title}
  Click Button  Save
  Wait until page contains  Item created


# ----------------------------------------------------------------------------
# Collection
# ----------------------------------------------------------------------------

the content area should contain
  [Arguments]  ${text}
  Element Should Contain  id=content  ${text}

the content area should not contain
  [Arguments]  ${text}
  Element Should Not Contain  id=content  ${text}

the collection should contain
  [Arguments]  ${title}
  Wait until page contains element  xpath=//*[@id='content-core']
  xpath should match x times  //*[@id='content-core']//*[@class='entry']//a[contains(text(), '${title}')]  1


the collection should not contain
  [Arguments]  ${title}
  The content area should not contain  ${title}

fill date field
  [Arguments]  ${fieldid}  ${year}=2012  ${month}=January  ${day}=10
  [Documentation]  Fill in the specified date field (such as effective/expiration date in the "dates" metadata tab) with the specified date.
  ...  Month must be specified by name.
  Click Element  xpath=//div[@data-fieldname="${fieldid}"]//input[contains(@class,"pattern-pickadate-date")]
  Select from list  css=div[data-fieldname="${fieldid}"] .picker__select--month  ${month}
  Select from list  css=div[data-fieldname="${fieldid}"] select.picker__select--year  ${year}
  Click Element  xpath=//div[@data-fieldname="${fieldid}"]//div[contains(@class, 'picker__day')][contains(text(), "${day}")]

I set the criteria ${type} in row ${number} to the option '${label}'
  [Documentation]  A couple of times we shift the focus so the input sticks, and wait a bit,
  ...              to make the test more stable.
  ${criteria_row} =  Convert to String  .querystring-criteria-wrapper:nth-child(${number})
  Wait until page contains element  css=${criteria_row} .querystring-criteria-${type} .select2-choice
  Click Element  css=${criteria_row} .querystring-criteria-${type} .select2-choice
  Sleep  1.5
  Set Focus To Element  css=body
  Wait until element is visible  css=#select2-drop input
  Input Text  css=#select2-drop input  ${label}
  Sleep  1.5
  Set Focus To Element  css=body
  Wait until element is visible  css=#select2-drop .select2-match
  Click Element  css=#select2-drop .select2-match
  Sleep  1.5
  Set Focus To Element  css=body

I set the criteria ${type} in row ${number} to the options '${label}'
  ${criteria_row} =  Convert to String  .querystring-criteria-wrapper:nth-child(${number})
  Wait until page contains element  css=${criteria_row} .querystring-criteria-${type} .select2-choices
  Click Element  css=${criteria_row} .querystring-criteria-${type} .select2-choices
  Wait until page contains element  css=.select2-input.select2-focused
  Input text  css=.select2-input.select2-focused  ${label}\n
# Click Element  xpath=//div[@class='select2-result-label']/descendant-or-self::*[contains(text(), '${label}')]

I set the criteria ${type} in row ${number} to the text '${label}'
  ${criteria_row} =  Convert to String  .querystring-criteria-wrapper:nth-child(${number})
  Input text  css=${criteria_row} .querystring-criteria-value input  ${label}\t
  [Documentation]  Shift the focus so the input sticks, and wait a bit
  Sleep  1.5
  Set Focus To Element  css=.querystring-sortreverse
  Sleep  1.5
