*** 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 ***
Allan can see the news front page
    Given I am logged in as the user allan_neece
    Then I can see the company news in the front page

Alice can add news
    Given I am logged in as the user alice_lindstrom
    Then I can go to the application    News publisher
    And I can create the section    Robot news
    And I can delete the Robot news section
    And I can create the news    Robots are great
    Then I can visit the news    Robots are great
    And I can upload the news hero image    new-profile.jpg
    And I can change the news description    Hello world
    And I can delete the news    Robots are great

Lance can add news
    Given I am logged in as the user lance_stockstill
    Then I can go to the application    News publisher
    And I can create the section    Lance's news
    And I can create the news    Robots are dangerous
    Then I can visit the news    Robots are dangerous
    And I can upload the news hero image    new-profile.jpg
    And I can change the news description    Hello world
    And I can delete the news    Robots are dangerous

Alice can add a Trending section
    Given I am logged in as the user alice_lindstrom
    Then I can go to the application    News publisher
    And I can create the smart section    Trending news items    Robot news
    # TODO: Check that trending items are actually shown
    And I can delete the Robot news section

Alice can add an Events section
    Given I am logged in as the user alice_lindstrom
    Then I can go to the application    News publisher
    And I can create the smart section    Events    Robot news
    # TODO: Check that events are actually shown
    And I can delete the Robot news section


*** Keywords ***
I can see the company news in the front page
    Wait for injection to be finished
    Click Link    jquery=#portal-tabs a:contains("News")
    Wait for injection to be finished
    Page Should Contain Element    jquery=nav a:contains('Front page')
    Page Should Contain Element    jquery=nav a:contains('Company News')
    Page Should Contain Element    jquery=.item.item-1 strong.category:contains('Company News')

I can create the news
    [Arguments]    ${title}
    Click Element    jquery=[title="Create news item or section"]
    Wait for injection to be finished
    Input text    css=#sheet-article input[name=title]    ${title}
    Click the modal create button no notification    \#sheet-article

I can visit the news
    [Arguments]    ${title}
    # FIXME: this should be already open
    Click Element    css=#listing-company-news h4
    Wait for injection to be finished
    Click Element    jquery=h4.title:contains('${title}')
    Wait for injection to be finished

I can upload the news hero image
    [Arguments]    ${filename}
    Choose File    jquery=div.summary-hero [name='image']    ${UPLOADS}/${filename}
    Wait for injection to be finished
    Element should be visible    css=div.summary-hero .upload-button.pat-button

I can change the news description
    [Arguments]    ${text}
    Input Text    css=div.summary-hero [name='description']    ${text}
    Click button    css=#metadata-toolbar #save-button
    Wait for injection to be finished
    Close notification

I can delete the news
    [Arguments]    ${title}
    Click Element    jquery=h4:contains("${title}")
    Wait for injection to be finished
    Click Element    css=.quick-functions .icon.more
    Wait Until Element Is Visible    css=.tippy-content .menu .icon-trash
    Click Element    css=.tippy-content .menu .icon-trash
    Wait for injection to be finished
    Click Button    I am sure, delete now

I can create the section
    [Arguments]    ${title}
    Click Element    jquery=[title="Create news item or section"]
    Wait for injection to be finished
    Click Element    css=.canvas-toolbar a.icon-squares
    Input text    css=#sheet-section input[name=title]    ${title}
    Click the modal create button no notification    \#sheet-section

I can create the smart section
    [Arguments]    ${type}    ${title}
    Click Element    jquery=[title="Create news item or section"]
    Wait for injection to be finished
    Click Element    css=.canvas-toolbar a.icon-brain
    Input text    css=#sheet-smartsection input[name=title]    ${title}
    Select From List By Label    view_name    ${type}
    # TODO: select calendar if it's an Events section
    Click the modal create button no notification    \#sheet-smartsection

I can delete the Robot news section
    # FIXME: this should be already open
    Click Element    css=#listing-robot-news h4
    Wait for injection to be finished
    Click Element    css=#listing-robot-news .icon-cog
    Wait for injection to be finished
    Click Element    css=.tooltip-container .menu .icon-trash
    Wait for injection to be finished
    Click Button    I am sure, delete now
    Wait for injection to be finished
