*** Keywords ***
# first responsive breakpoint is already at 1292px
Prepare test browser
    Open browser    ${START_URL}/login_form    ${BROWSER}
    Set testing viewport

Set testing viewport
    Set window size    1300    1024

I am logged in as site administrator
    Element should be visible    css=body.userrole-manager

I am logged in as the user ${userid}
    ${IN_LOGIN_FORM} =    Get Element Count    //form[@id='login-panel']
    IF    ${IN_LOGIN_FORM} == 0    Logout And Go To Login
    Enter the Credentials    ${userid}    secret
    Wait until page contains element    id=portal

Logout And Go To Login
    Go To    ${PLONE_URL}/logout
    Go To    ${PLONE_URL}/login_form

Enter the Credentials
    [Arguments]    ${username}    ${password}
    Input text for sure    name=__ac_name    ${username}
    Input text for sure    name=__ac_password    ${password}
    Click Button    Log in

Wait for injection to be finished
    Wait Until Page Does Not Contain Element    css=.injecting-content

Wait for injection to be finished in the dashboard
    Wait Until Page Does Not Contain Element    //a[contains(@class, 'portlet')][contains(@data-pat-inject,'autoload')]
    Wait for injection to be finished

# Generic statement to close the self-healing pat-notification

Close notification
    Wait for injection to be finished
    ${notification} =    Get element count    xpath=//div[contains(@class, "pat-notification-panel")]
    IF    ${notification}
        Click button    css=.pat-notification-container button.close-panel
    END

# add content keyword that supports
# both dexterity and archetypes

Add content item
    [Arguments]    ${content_type}    ${title}
    Open add new menu
    Click link    link=${content_type}
    Fill text field    Title    ${title}
    Click button    name=form.buttons.save
    Page should contain    Item created
    Page should contain    ${title}
    ${location} =    Get Location
    RETURN    ${location}

# Field is matched via a preceding <label>
# Fill a text field

Fill text field
    [Arguments]    ${field_label}    ${text}
    Input Text    xpath=//form//div/input[preceding-sibling::label[contains(text(), '${field_label}')]]    ${text}

Add workspace
    [Arguments]    ${title}
    Go to    ${PLONE_URL}/workspaces/++add++ploneintranet.workspace.workspacefolder
    Wait Until Element Is Visible    jquery=input[name='form.widgets.IBasic.title']
    Input text    name=form.widgets.IBasic.title    ${title}
    # Ignore the MoveTargetOutOfBoundsException error, the browser is actually properly scrolling
    Run Keyword And Ignore Error    Scroll Element Into View    css=#form-buttons-save
    Click Button    Save
    Page Should Contain    Item created

Maneuver to
    [Arguments]    ${title}
    Wait until element is visible    jquery=a:contains("${title}")
    Click link    jquery=a:contains("${title}")

I can reload the page
    Reload Page

I open the Dashboard
    Go to    ${PLONE_URL}/dashboard.html
    Wait for injection to be finished in the dashboard

I scroll the Dashboard
    Execute Javascript    jQuery('.activities .infinite-scrolling-trigger').focus()
    Wait for injection to be finished

I scroll the Dashboard to
    [Arguments]    ${LOCATOR}
    FOR    ${cnt}    IN RANGE    1    100
        LOG TO CONSOLE    Scrolling the dashboard
        I scroll the Dashboard
        ${LOCATOR_SHOWN} =    Get Element count    css:${LOCATOR}
        LOG TO CONSOLE    Number of results: ${LOCATOR_SHOWN}
        IF    ${LOCATOR_SHOWN} > 0    BREAK
    END
    Execute Javascript    document.querySelector('${LOCATOR}').scrollIntoView({block: "center"})

I am in a workspace as a workspace member
    I am logged in as the user allan_neece
    I go to the Open Market Committee Workspace

I am in a Producers workspace as a workspace member
    I am logged in as the user allan_neece
    I go to the Open Parliamentary Papers Guidance Workspace

I am in a Producers workspace as a workspace admin
    I am logged in as the user christian_stoney
    I go to the Open Parliamentary Papers Guidance Workspace

I am in a Consumers workspace as a workspace member
    I am logged in as the user allan_neece
    I go to the Shareholder Information Workspace

I am in a Consumers workspace as a workspace admin
    I am logged in as the user christian_stoney
    I go to the Shareholder Information Workspace

I am in a workspace as a workspace admin
    I am logged in as the user christian_stoney
    I go to the Open Market Committee Workspace

I am in an open workspace as a workspace member
    I am logged in as the user allan_neece
    I go to the Service Announcements Workspace

I am in an open workspace as a non-member
    I am logged in as the user alice_lindstrom
    I go to the Service Announcements Workspace

I go to the Open Market Committee Workspace
    Go To    ${PLONE_URL}/workspaces/open-market-committee
    Wait Until Element Is Visible    css=h1#workspace-name
    Wait Until Page Contains    Open Market Committee
    Wait for injection to be finished

I go to the Example Case
    Go To    ${PLONE_URL}/workspaces/example-case
    Wait Until Element Is Visible    css=h1#workspace-name
    Wait Until Page Contains    Example Case

I go to the Open Parliamentary Papers Guidance Workspace
    Go To    ${PLONE_URL}/workspaces/parliamentary-papers-guidance
    Wait Until Element Is Visible    css=h1#workspace-name
    Wait Until Page Contains    Parliamentary papers guidance

I go to the Shareholder Information Workspace
    Go To    ${PLONE_URL}/workspaces/shareholder-information
    Wait Until Element Is Visible    css=h1#workspace-name
    Wait Until Page Contains    Shareholder information

I can file a request access for the workspace
    [Arguments]    ${title}
    Go to    ${PLONE_URL}/workspaces
    Click Element    jquery=h3:contains('${title}')
    Wait for injection to be finished
    Input Text    body    Please, let me in!
    Click Button    Request access
    Wait until page contains
    ...    A request for access for workspace ${title} has been issued to the workspace administrators

I can decline the request access of
    [Arguments]    ${userid}
    Go to    ${PLONE_URL}/workspaces/shareholder-information/@@panel-request-access-manage/${userid}
    Click Button    Decline
    Wait until page contains    was declined

I can accept the request access of
    [Arguments]    ${userid}
    Go to    ${PLONE_URL}/workspaces/shareholder-information/@@panel-request-access-manage/${userid}
    Click Button    Accept
    Wait until page contains    has now access to workspace

I go to the Service Announcements Workspace
    Go To    ${PLONE_URL}/workspaces/service-announcements
    Wait Until Element Is Visible    css=h1#workspace-name
    Wait Until Page Contains    Service announcements

I go to the Archived Workspace
    Go To    ${PLONE_URL}/workspaces/archived-workspace
    Wait for injection to be finished

I go to the Terms and Conditions Document
    Go To    ${PLONE_URL}/workspaces/service-announcements/terms-and-conditions
    Wait for injection to be finished

I can go to the Open Market Committee Workspace
    Go To    ${PLONE_URL}/workspaces/open-market-committee

I can go to the Example Case
    Go To    ${PLONE_URL}/workspaces/example-case

I cannot see any workspaces
    Go To    ${PLONE_URL}/workspaces
    Element should not be visible    css=div.tile-workspaces

I am redirected to the login page
    Location Should Contain    require_login

I do not have sufficient privileges
    Wait Until Page Contains    Insufficient Privileges

I open the password reset form
    Go To    ${PLONE_URL}/passwordreset

The page is not found
    Page should contain    This page does not seem to exist

I cannot reset my password with an illegal request posing as
    [Arguments]    ${user_name}
    Wait until page contains    Error setting password

# *** Posting and stream related keywords ***

I can see updates by
    [Arguments]    ${user_fullname}
    Element should be visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//div[@class='post-header']//h4[text()='${user_fullname}']/..

I cannot see updates by
    [Arguments]    ${user_fullname}
    Element should not be visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//div[@class='post-header']//h4[text()='${user_fullname}']/..

I can see an attachment
    [Arguments]    ${filename}
    Page Should Contain Link    ${filename}

I can see a content attachment
    [Arguments]    ${filename}
    Page Should Contain Link    ${filename}

I cannot see a content attachment
    [Arguments]    ${filename}
    Page Should Not Contain Link    ${filename}

I can follow the profile link for user
    [Arguments]    ${user_fullname}
    Click Element    jquery=#activity-stream .post.item h4:contains('Christian Stoney')

I can see updates tagged
    [Arguments]    ${tag}
    Page Should Contain Link    \#${tag}

I cannot see updates tagged
    [Arguments]    ${tag}
    Page Should Not Contain Link    \#${tag}

I cannot see updates at all
    Element should not be visible    xpath=//div[@id='activity-stream']//div[@class='post item']

I click the tag link
    [Arguments]    ${tag}
    Wait Until Element Is Visible    jquery=a:contains(#${tag})
    # Ignore the MoveTargetOutOfBoundsException error, the browser is actually properly scrolling
    Run Keyword and Ignore Error    Scroll Element Into View    jquery=a:contains(#${tag})
    # We need to scroll down a bit more to have the link clickable
    Press Keys    css=body    ARROW_DOWN
    Wait Until Keyword Succeeds    10x    100ms    Click Link    jquery=a:contains(#${tag})
    Wait for injection to be finished

I can toggle following the tag
    Click Element    css=#follow-function button
    Wait for injection to be finished

I am following the tag
    Page Should Contain Element    css=#follow-function button.active

I am not following the tag
    Page Should Not Contain Element    css=#follow-function button.active

I can toggle following the user
    Wait for injection to be finished
    Click Element    css=#follow-button-contacts
    Wait for injection to be finished

I filter the stream as
    [Arguments]    ${stream_filter}
    Wait for injection to be finished
    Click element    xpath=//select[@name='stream_filter']//option[@value='${stream_filter}']
    Wait until page contains element
    ...    xpath=//select[@name='stream_filter']//option[@value='${stream_filter}'][@selected]
    Wait for injection to be finished

The message is visible as new status update
    [Arguments]    ${message}
    Wait Until Element Is visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p[contains(text(), '${message}')][1]

The reply is visible
    [Arguments]    ${message}
    Wait Until Element Is visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='comment-content']//p[contains(text(), '${message}')][1]

The message is not visible
    [Arguments]    ${message}
    Element should not be visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p[contains(text(), '${message}')][1]

The message is visible as new status update that mentions the user
    [Arguments]    ${message}    ${username}
    Wait Until Element Is visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p[contains(text(), '${message}')][1]
    Wait Until Element Is visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p//a[contains(text(), '@${username}')][1]

The message is visible as new status update and includes the tag
    [Arguments]    ${message}    ${tag}
    Wait Until Element Is visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p[contains(text(), '${message}')][1]
    Wait Until Element Is visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p//a[contains(text(), '#${tag}')][1]

The status update only appears once
    [Arguments]    ${message}
    Element should be visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p[contains(text(), '${message}')][1]
    Element should not be visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p[contains(text(), '${message}')][2]

The message is visible after a reload
    [Arguments]    ${message}
    ${location} =    Get Location
    Go to    ${location}
    The message is visible as new status update    ${message}

The reply is visible as a comment
    [Arguments]    ${message}    ${reply_message}
    Wait Until Element Is visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p[contains(text(), '${message}')][1]//..//..//..//div[@class='comments']//section[@class='comment-content']//p[contains(text(), '${reply_message}')]

I post a reply on a status update
    [Arguments]    ${message}    ${reply_message}
    Wait Until Element Is visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p[contains(text(), '${message}')]
    ${POST_ID} =    Get Element Attribute
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//p[contains(text(), '${message}')]//..//..
    ...    id
    ${STATUS_UPDATE_ID} =    Get Substring    ${POST_ID}    5
    Scroll Element Into View    css=#microblog-${STATUS_UPDATE_ID} [contenteditable]
    Press Keys    css=#microblog-${STATUS_UPDATE_ID}    ARROW_DOWN
    Click Element    css=#microblog-${STATUS_UPDATE_ID} [contenteditable]
    Wait Until Element Is visible    jquery=#microblog-${STATUS_UPDATE_ID} [name='form.buttons.statusupdate']
    Input Text    css=#microblog-${STATUS_UPDATE_ID} [contenteditable]    ${reply_message}
    Scroll Element Into View    jquery=#microblog-${STATUS_UPDATE_ID} [name='form.buttons.statusupdate']
    Press Keys    css=#microblog-${STATUS_UPDATE_ID}    ARROW_DOWN
    Click button    jquery=#microblog-${STATUS_UPDATE_ID} [name='form.buttons.statusupdate']
    The reply is visible as a comment    ${message}    ${reply_message}

The reply is not visible
    [Arguments]    ${message}
    Wait for injection to be finished
    Element should not be visible
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//div[@class='comments']//section[@class='comment-content']//p[contains(text(), '${message}')]

The reply is visible after a reload
    [Arguments]    ${message}    ${reply_message}
    ${location} =    Get Location
    Go to    ${location}
    The reply is visible as a comment    ${message}    ${reply_message}

Both replies are visible
    [Arguments]    ${message}    ${reply_message1}    ${reply_message2}
    The reply is visible as a comment    ${message}    ${reply_message1}
    The reply is visible as a comment    ${message}    ${reply_message2}

Both replies are visible after a reload
    [Arguments]    ${message}    ${reply_message1}    ${reply_message2}
    ${location} =    Get Location
    Go to    ${location}
    The reply is visible as a comment    ${message}    ${reply_message1}
    The reply is visible as a comment    ${message}    ${reply_message2}

I scroll to post number
    [Arguments]    ${post_number}
    # Ignore the MoveTargetOutOfBoundsException error, the browser is actually properly scrolling
    Run Keyword and Ignore Error    Scroll Element Into View    jquery=#stream-items > .tile:nth-child(${post_number})
    Wait for injection to be finished

I can read the comment
    [Arguments]    ${text}
    Page Should Contain Element    jquery= .comment-content :contains(${text})

I cannot read the comment
    [Arguments]    ${text}
    Page Should Not Contain Element    jquery= .comment-content :contains(${text})

I expand the older comments
    Click Element    jquery=.post .older-comments > a
    Wait for injection to be finished

Select text end in ProseMirror
    # Select the end of line1 of the text in the ProseMirror contenteditable
    Execute Javascript    const editor = document.querySelector(".post-box .ProseMirror");
    ...    const range = document.createRange();
    ...    const sel = window.getSelection();
    ...    const text = editor.childNodes[0].childNodes[0];
    ...    range.setStart(text, text.length);
    ...    sel.removeAllRanges();
    ...    sel.addRange(range);

I can add a tag
    [Arguments]    ${tag}
    Wait Until Element Is visible    css=.post-box .ProseMirror
    # Add a tag
    ${text} =    Get Text    css:.post-box .ProseMirror
    Input Text    css=.post-box .ProseMirror    ${text} #${tag}
    # Google Chrome fix to show filtered results.
    # Setting selection for the first time closes the context menu.
    Select text end in ProseMirror
    # Setting the selection for the second time opens it and adds the filter.
    Select text end in ProseMirror
    # Check for filtered results.
    Wait Until Element Is visible    css=.tiptap-tags .tiptap-items div[data-tiptap-value="${tag}"]
    Click link    css=.tiptap-item.active a
    Wait Until Element Is visible    css=.post-box .ProseMirror a[data-tag=${tag}]
    # Finally
    Click element    css=div.activity-stream

I can mention the user
    [Arguments]    ${username_search}    ${username_full}
    Wait Until Element Is visible    css=.post-box .ProseMirror
    ${text} =    Get Text    css:.post-box .ProseMirror
    # Typing in the username already searches for it.
    Input Text    css=.post-box .ProseMirror    ${text} @${username_search}
    # Google Chrome fix to show filtered results.
    # Setting selection for the first time closes the context menu.
    Select text end in ProseMirror
    # Setting the selection for the second time opens it and adds the filter.
    Select text end in ProseMirror
    # Check for filtered results.
    Wait Until Element Is visible    css=div.tiptap-item.active[data-tiptap-value="${username_full}"]
    Click link    css=.tiptap-item.active a
    Wait Until Element Is visible    css=.post-box .ProseMirror a[data-title="${username_full}"]
    # Finally
    Click element    css=div.activity-stream

The content stream is visible
    Wait until element is visible    css=#comments-document-comments

Click notification close button
    Execute javascript    jQuery(".pat-notification-panel button.close-panel").click()
    Page should not Contain Element    jquery=.pat-notification-panel button.close-panel

I see the changes have been saved
    Wait Until Page Contains    Your changes have been saved
    Close notification
    Wait Until Page Does Not Contain    Your changes have been saved

I save the task
    [Documentation]    might fail with the message: stale element reference: element is not attached to the page document
    Wait for injection to be finished
    Page should contain element    css=#document-body #metadata-toolbar .quick-functions button#save-button
    Wait Until Keyword Succeeds
    ...    10x
    ...    100ms
    ...    Click Element
    ...    css=#document-body #metadata-toolbar .quick-functions button#save-button
    I see the changes have been saved

I save the event
    [Documentation]    might fail with the message: stale element reference: element is not attached to the page document
    Wait for injection to be finished
    Page should contain element
    ...    css=#document-body .workspaces-event-toolbar-functions-area-workspaces .quick-functions button#save-button
    Wait Until Keyword Succeeds
    ...    10x
    ...    100ms
    ...    Click Element
    ...    css=#document-body .workspaces-event-toolbar-functions-area-workspaces .quick-functions button#save-button
    I see the changes have been saved

The stream contains
    [Arguments]    ${text}
    Wait until page contains    ${text}

The stream links to the document
    [Arguments]    ${text}
    Wait until page contains element    link=${text}

The stream does not link to the document
    [Arguments]    ${text}
    Page should not contain    link=${text}

# *** Workspace related keywords ***

Click the modal create button
    [Arguments]    ${containerselector}=.wizard-box
    # trigger validation
    Execute Javascript    jQuery("${containerselector} .is-invalid").change()
    Click Button    jquery=${containerselector} button[name='form.buttons.create']
    Close notification
    Wait for injection to be finished

Click the modal create button no notification
    [Arguments]    ${containerselector}=.wizard-box
    # trigger validation
    Execute Javascript    jQuery("${containerselector} .is-invalid").change()
    Click Button    jquery=${containerselector} button[name='form.buttons.create']
    Wait for injection to be finished

I can create a new workspace
    [Arguments]    ${title}
    Go To    ${PLONE_URL}/workspaces
    Click Link    link=Create workspace
    Wait Until Element Is visible    xpath=//input[@name='title']
    Input Text    xpath=//input[@name='title']    text=${title}
    Input Text    xpath=//textarea[@name='description']    text=Random description
    Press Keys    xpath=//input[@name='title']    ENTER
    Wait Until Page Contains    Item created
    Close notification

I can create a new secret workspace
    [Arguments]    ${title}
    Go To    ${PLONE_URL}/workspaces
    Click Link    link=Create workspace
    Wait Until Element Is visible    xpath=//div[@id='pat-modal']//input[@name='title']
    Input Text    xpath=//input[@name='title']    text=${title}
    Input Text    xpath=//textarea[@name='description']    text=Random description
    select from list By Label    css=select[name=workspace-type]    Locked down, secret workspace
    Press Keys    xpath=//input[@name='title']    ENTER
    Wait Until Page Contains    Item created
    Close notification

I can create a new superspace
    [Arguments]    ${title}
    Go To    ${PLONE_URL}/workspaces
    Click Link    link=Create workspace
    Wait Until Element Is visible    xpath=//div[@id='pat-modal']//input[@name='title']
    Input Text    xpath=//input[@name='title']    text=${title}
    Input Text    xpath=//textarea[@name='description']    text=Random description
    Select From List By Label    workspace-type    Super space
    Press Keys    xpath=//input[@name='title']    ENTER
    Wait Until Page Contains    Item created
    Close notification

I can set the superspace
    [Arguments]    ${title}
    I can open the workspace advanced settings tab
    Select From List By Label    superspace    ${title}
    Wait until page contains    Attributes changed
    Close notification

I enter the double nested subspace
    [Arguments]    ${title}
    Wait Until Element Is visible    jquery=.tiles .tile .tiles > .tile .tiles > .tile a h3:contains('${title}')
    Click element    jquery=.tiles .tile .tiles > .tile .tiles > .tile a h3:contains('${title}')
    Wait for injection to be finished

I open the superspace tile
    [Arguments]    ${title}
    Wait until element is visible    jquery=.tile a h3:contains('${title}')
    CLick Element    jquery=.tile a h3:contains('${title}')
    Wait for injection to be finished
    Comment    jQuery effects and css transitions are disabled in the robot tests, hacks needed
    Execute JavaScript    jQuery('.pat-masonry .grid-sizer').remove()
    Execute JavaScript    jQuery('.pat-masonry .tile').attr({style: ''})
    Execute JavaScript    jQuery('.pat-masonry').trigger('pat-update')
    Sleep    1

I can see the listed workspace
    [Arguments]    ${title}
    Wait until page contains Element    jquery=.tiles .tile h3:contains("${title}")

I can see the first listed workspace is
    [Arguments]    ${title}
    Wait until page contains Element    jquery=.tiles .tile:first h3:contains("${title}")

I can see the last listed workspace is
    [Arguments]    ${title}
    Wait until page contains Element    jquery=.tiles .tile:last h3:contains("${title}")

I can set workspace listing order
    [Arguments]    ${value}
    Select From List By Label    css=select[name=sort]    ${value}

I Click only my workspaces
    Click Element    css=#filters-menu
    Click Element    css=#filter-option-my-workspaces
    # Click element again to close it
    Click Element    css=#filters-menu
    Wait for injection to be finished

I can create a new template workspace
    [Arguments]    ${title}
    Go To    ${PLONE_URL}/templates/++add++ploneintranet.workspace.workspacefolder
    Wait Until Element Is Visible    jquery=input[name='form.widgets.IBasic.title']
    Input Text for sure    form.widgets.IBasic.title    New template
    # Ignore the MoveTargetOutOfBoundsException error, the browser is actually properly scrolling
    Run Keyword and Ignore Error    Scroll Element Into View    css=#form-buttons-save
    Click Button    Save
    Wait Until Page Contains    Item created
    Wait for injection to be finished
    Go To    ${PLONE_URL}/workspaces

I can create a new workspace for the division
    [Arguments]    ${title}    ${division}
    Go To    ${PLONE_URL}/workspaces
    Click Link    link=Create workspace
    Wait Until Element Is visible    css=div#pat-modal
    Input Text    xpath=//input[@name='title']    text=${title}
    Input Text    xpath=//textarea[@name='description']    text=Random description
    Select From List By Label    division    ${division}
    Click Button    Create workspace
    Wait Until Page Contains    Item created
    Close notification

I can see the workspace belongs to division
    [Arguments]    ${division}
    Wait Until Element Is Visible    xpath=//select//option[@selected='selected'][text()='${division}']

I can create a new workspace from a template
    [Arguments]    ${template}    ${title}
    Go To    ${PLONE_URL}/workspaces
    Click Link    link=Create workspace
    Wait Until Element Is visible    jquery=div#pat-modal input[name=title]
    Input Text    name=title    text=${title}
    Input Text    name=description    text=Something completely different
    Select From List By Value    workspace-type    new-template
    Wait Until Page Contains    New template
    Click Button    Create workspace
    Wait Until Page Contains    Item created

I select a file to upload
    [Documentation]    We can't drag and drop from outside the browser so it gets a little hacky here
    Element Should Contain    css=.pat-upload .dz-message p    Drop files here
    Execute JavaScript    jQuery('.pat-upload .accessibility-options').show()
    Execute JavaScript    jQuery('.pat-upload').siblings('button').show()
    Choose File    css=input[name=file]    ${UPLOADS}/bärtige_flößer.odt
    Click Element    xpath=//button[text()='Upload']

I open the sidebar documents tile
    Click Link    css=a.documents
    Wait Until Page Contains Element    css=div#workspace-documents
    Wait for injection to be finished

I can go to the sidebar info tile
    Click Link    link=Settings
    Wait Until Page Contains    General
    Wait Until Page Contains    Workspace title
    Wait Until Page Contains    Workspace description

I can go to the sidebar events tile
    Click Link    link=Events
    Wait Until Element Is visible    xpath=//div[@id='event-list-upcoming']
    Wait for injection to be finished

I open the sidebar event
    [Arguments]    ${title}
    Click Element    jquery=#event-list-upcoming .item :contains('${title}'):parent:parent
    Wait for injection to be finished

I open the sharing menu
    Wait for injection to be finished
    I open the document context menu
    Click Element    jquery=#extra-options a.icon-share
    Wait Until Element Is Visible    jquery=.tippy-content #share-panel-menu

I open the document context menu
    Click Element    css=div.quick-functions a.icon-ellipsis
    Wait for injection to be finished
    Wait until page contains Element    css=.tooltip-container

I close the document context menu
    Click Element    css=div.quick-functions a.icon-ellipsis
    Wait until page does not contain Element    css=.tooltip-container

I open the sidebar context menu for
    [Arguments]    ${title}
    Wait until page contains element    jquery=label[title="${title}"]
    Mouse Over    jquery=label[title="${title}"]
    Execute javascript    jQuery.fx.off=false
    Click Element    jquery=label[title="${title}"] > .item-info > .icon-ellipsis
    Execute javascript    jQuery.fx.off=true
    Wait for injection to be finished

I close all the tooltips
    Execute Javascript    jQuery('.tooltip-container').remove()

The menu contains the link to download the PDF
    Wait until page contains element    jquery=.menu .icon-file-pdf

I trash or delete through the sidebar
    [Arguments]    ${title}    ${action}
    I open the sidebar context menu for    ${title}
    Wait until page contains element    jquery=.tooltip-container[style*="visible"] .icon-trash
    Click Element    jquery=.tooltip-container[style*="visible"] .icon-trash
    Wait until page contains    You are about to ${action} this Document
    Click Button    jquery=.pat-modal .buttons .icon-ok-circle
    Wait for injection to be finished

I trash through the sidebar
    [Arguments]    ${title}
    I trash or delete through the sidebar    ${title}    trash

I delete through the sidebar
    [Arguments]    ${title}
    I trash or delete through the sidebar    ${title}    delete

I set the new title through the already open context menu
    [Arguments]    ${title}
    Wait until page contains element    jquery=.tooltip-container[style*="visible"] .icon-rename
    Click element    jquery=.tooltip-container[style*="visible"] .icon-rename
    Wait for injection to be finished
    Input Text    css=#pat-modal [name=title]    ${title}
    Press Keys    css=#pat-modal [name=title]    ENTER
    Wait for injection to be finished
    Close notification

I copy through the already open context menu
    Wait until page contains element    jquery=.tooltip-container[style*="visible"] .icon-copy
    Click element    jquery=.tooltip-container[style*="visible"] .icon-copy
    Wait until page contains    1 Files were copied to your cloud clipboard.

I cut through the already open context menu
    Wait until page contains element    jquery=.tooltip-container[style*="visible"] .icon-cut
    Click element    jquery=.tooltip-container[style*="visible"] .icon-cut
    Wait until page contains    1 Files were cut and moved to your cloud clipboard.

I copy through the sidebar
    [Arguments]    ${title}
    I open the sidebar context menu for    ${title}
    I copy through the already open context menu
    I close all the tooltips

I cut through the sidebar
    [Arguments]    ${title}
    I open the sidebar context menu for    ${title}
    I cut through the already open context menu
    I close all the tooltips

The cut action in the sidebar is not available for
    [Arguments]    ${title}
    I open the sidebar context menu for    ${title}
    Wait until page contains element    jquery=.tooltip-container[style*="visible"] ul.menu
    Page should not contain element    jquery=.tooltip-container[style*="visible"] .icon-cut

I can paste my clipboard contents
    I open the sidebar more menu
    Click link    Paste
    Wait until page contains    Item(s) pasted

I can go the trash bin
    Click Element    jquery=label.type-trash
    Wait for injection to be finished

I can see in the trash bin
    [Arguments]    ${title}
    I can go the trash bin
    Wait until page contains element    jquery=label.trashed[title="${title}"]

I can untrash this document
    Click element    jquery=a:contains(Untrash)
    Wait for injection to be finished

The workspace admin can empty the trash
    I am in a workspace as a workspace admin
    I open the sidebar documents tile
    I can go the trash bin
    Click element    jquery=#items .pat-button[href*='@@empty-trash']
    Wait for injection to be finished
    Click Button    I am sure, empty trash now
    Wait for injection to be finished
    Page should contain    No items to display

Scroll to the Add agenda item button
    Wait Until Keyword Succeeds    10x    100ms    Scroll Element Into View    jquery=.agenda #add-agenda-item

I see that the last event agenda item is
    [Arguments]    ${title}
    Scroll to the Add agenda item button
    Page should contain element    jquery=.sortable-item:last [value="${title}"]

I see in the event agenda a link to
    [Arguments]    ${title}
    Scroll to the Add agenda item button
    Page should contain element    jquery=.event-details .agenda a:contains(${title})

I add to the event agenda the item
    [Arguments]    ${title}
    Scroll to the Add agenda item button
    Click Element    jquery=.agenda #add-agenda-item
    Wait until page contains element    xpath=//fieldset[contains(@class, 'agenda')]/ol/li/input[@value='']
    Input Text    jquery=.sortable-item.sortable:last input    ${title}
    Wait until page contains element
    ...    xpath=//fieldset[contains(@class, 'agenda')]/ol/li/input[contains(@data-value, '${title}')]
    I save the event
    I see that the last event agenda item is    ${title}

I remove from the event agenda the last item
    Input Text    jquery=.sortable-item:last input    \n
    Press Keys    jquery=.sortable-item:last input    ENTER
    Wait for injection to be finished

I can open the documents tab
    Wait Until Page Contains Element    css=#workspace-tabs a.documents
    Click link    Documents
    Wait Until Page Contains Element    css=fieldset.docs label.type-trash
    Wait for injection to be finished

I can open the workspace advanced settings tab
    Click Link    link=Settings
    Wait for injection to be finished
    ${extra_tabs} =    Get element count    xpath=//div[@id="workspace-settings"]//span[@class="extra-tabs"]
    IF    ${extra_tabs}
        Click element    xpath=//div[@id="workspace-settings"]//span[@class="extra-tabs"]
    END
    Wait until page contains    Advanced
    Click link    link=Advanced
    Wait for injection to be finished
    Wait until page contains    Workspace e-mail address

Click the workspace settings security tab
    Wait until element is visible    jquery=#workspace-settings a:contains("Security")
    Click link    jquery=#workspace-settings a:contains("Security")
    Wait for injection to be finished

I can open the workspace security settings tab
    Click Link    link=Settings
    Click the workspace settings security tab
    Wait until page contains    Workspace visibility and accessibility

I can open the workspace member settings tab
    Click Link    link=Settings
    Click link    link=Members
    Wait for injection to be finished
    Wait until page contains element    css=#member-list

I can turn the workspace into a division
    Click element    xpath=//input[@name='is_division']/../..
    Wait for injection to be finished
    Wait until page contains    Attributes changed
    Wait until element is visible
    ...    xpath=//input[@name='is_division' and @value='selected' and @checked='checked']/../..
    Close notification

I can tag the workspace as
    [Arguments]    ${tag}
    Input text    xpath=//label[@data-placeholder='Enter a tag']//input[contains(@class,'select2-input')]    ${tag},
    Wait for injection to be finished
    Wait until page contains    Attributes changed
    Close notification

I can see the tag in the workspace header
    [Arguments]    ${tag}
    Reload Page
    Wait until page contains    \#${tag}

I can archive the workspace
    Select checkbox    xpath=//input[@name='archival_date']
    Wait for injection to be finished

I can unarchive the workspace
    Unselect checkbox    xpath=//input[@name='archival_date']
    Wait for injection to be finished

I can list the workspaces grouped by division
    [Documentation]    Wait until the temporary class 'injecting' has been removed, to be sure injection has completed
    Go To    ${PLONE_URL}/workspaces
    Click element    xpath=//select[@name='grouping']
    Click element    xpath=//option[@value='division']
    Wait until page does not contain element
    ...    xpath=//span[@id='workspaces' and contains(@class, 'tabs-content injecting')]

I can list the workspaces grouped by tags
    [Documentation]    Wait until the temporary class 'injecting' has been removed, to be sure injection has completed
    Go To    ${PLONE_URL}/workspaces
    Click element    xpath=//option[@value='tag']
    Wait until page does not contain element
    ...    xpath=//span[@id='workspaces' and contains(@class, 'tabs-content injecting')]

I can list the workspaces
    Go To    ${PLONE_URL}/workspaces
    Click element    xpath=//select[@name='grouping']
    Click element    xpath=//option[@value='division']
    Wait for injection to be finished

I can see the division
    [Arguments]    ${title}
    Wait Until Element Is Visible    xpath=//h1[text()='${title}']

I can see the tag
    [Arguments]    ${tag}
    Wait for injection to be finished
    Wait Until Element Is Visible    xpath=//span[@class='tag'][text()='${tag}']

I can see the tag group
    [Arguments]    ${tag}
    Wait Until Element Is Visible    xpath=//h1[text()='${tag}']

I can see the workspace grouped under tag
    [Arguments]    ${workspace}    ${tag}
    Wait Until Element Is Visible    xpath=//h1[text()='${tag}']/../..//h3[text()='${workspace}']

I can filter workspaces by tag
    [Arguments]    ${tag}    ${untagged_item}
    Input Text    xpath=//input[@data-placeholder="Search workspaces"]    ${tag}
    Wait for injection to be finished
    Page should contain    ${tag}
    Page should not contain    xpath=//h3[text()='${untagged_item}']

I can see the workspace
    [Arguments]    ${title}
    Page should contain    ${title}

I can't see the workspace
    [Arguments]    ${title}
    Page should not contain    ${title}

I can list the archived workspaces
    [Documentation]    Wait until the temporary class 'injecting' has been removed, to be sure injection has completed
    I can list the workspaces
    Click Element    css=#filters-menu
    Click Element    css=#filter-option-archived
    # Click element again to close it
    Click Element    css=#filters-menu
    Wait for injection to be finished

I can set the external visibility to Open
    Click element    jquery=#workspace-settings input[name="visible_to_intranet_users"]
    Wait for injection to be finished
    Click element    jquery=#workspace-settings input[name="accessible_to_intranet_users"]
    Wait for injection to be finished
    Click the workspace settings security tab
    Page should contain element
    ...    jquery=#workspace-settings input[name="accessible_to_intranet_users"][value="1"]:checked()

I can set the join policy to Admin-Managed
    Click element    jquery=#workspace-settings input[name="join_policy"][value="admin"]
    Wait for injection to be finished
    Click the workspace settings security tab
    Page should contain element    jquery=#workspace-settings input[name="join_policy"][value="admin"]:checked()

Check and ensure checked participant_policy
    [Arguments]    ${value}
    Click Element    jquery=#workspace-settings input[name="participant_policy"][value="${value}"]
    Wait for injection to be finished
    Click the workspace settings security tab
    Page should contain element
    ...    jquery=#workspace-settings input[name="participant_policy"][value="${value}"]:checked()

I can set the participant policy to Moderate
    Check and ensure checked participant_policy    moderators

I can set the participant policy to Consume
    Check and ensure checked participant_policy    consumers

I can open Esmeralda's profile
    Click Element    css=a[href$='/profiles/esmeralda_claassen']
    Wait Until Element Is visible    css=#user-data-content

I can follow Esmeralda
    Element should contain    css=#follow-button-contacts    Follow
    Click Element    css=#follow-button-contacts
    Wait Until Page contains element    jquery=#follow-button-contacts:contains("Unfollow")

I can see upcoming events
    Page Should Contain Element    xpath=//div[@id='event-list-upcoming']//a//h3[text()[contains(.,'Plone Conf')]]

Older events are hidden
    Element should be visible    jquery=div#older-events a

I can go to the sidebar tasks tile
    Go To    ${PLONE_URL}/workspaces/open-market-committee
    Click Link    link=Tasks
    Wait Until Element Is visible    xpath=//p[.='No tasks created yet']

I look for and select ${name} in autosuggest multiselect field ${field}
    Click Element    jquery=${field} .select2-choices
    Input Text    jquery=ul.select2-choices input.select2-focused    ${name}
    Wait Until Element Is visible    xpath=//span[@class='select2-match'][text()='${name}']
    Click Element    xpath=//span[@class='select2-match'][text()='${name}']

I look for and select ${name} in autosuggest field ${field}
    Click Element    jquery=${field} .select2-container
    Input Text    jquery=div.select2-search input.select2-focused    ${name}
    Wait Until Element Is visible    xpath=//span[@class='select2-match'][text()='${name}']
    Click Element    xpath=//span[@class='select2-match'][text()='${name}']

I create a task for
    [Arguments]    ${name}
    Go To    ${PLONE_URL}/workspaces/open-market-committee
    I can go to the sidebar tasks tile of my case
    Wait Until Page Contains Element    css=[title="Create task"]
    Click Element    css=[title="Create task"]
    Wait Until Page Contains Element    css=.panel-body
    Input date into date picker    '.panel-body input[name=due]'    2020-12-31
    # Click into the title field again to remove focus from the date fields
    Click element    css=.panel-content input[name=title]
    Input Text for sure    css=.panel-body input[name=title]    Ciao ${name}
    Input Text    css=.panel-body textarea[name=description]    This is for you ${name}
    I look for and select ${name} in autosuggest field label.assignee
    Click the modal create button    .panel-body
    Wait Until Page Contains Element    css=a[title="Ciao ${name}"]

Task is editable for user
    [Arguments]    ${name}
    Go To    ${PLONE_URL}/workspaces/open-market-committee
    I can go to the sidebar tasks tile of my case
    Click Element    jquery=#workspace-tickets a[title="Ciao ${name}"]
    Wait for injection to be finished
    Select From List By Label    css=select[name=priority]    High priority
    I save the task

# workspace member sidebar

I can enable user selection
    Wait Until Page Contains Element    jquery=.quick-functions a.toggle-select
    Click Element    jquery=div.tabs-content .quick-functions > a.toggle-select

I select all members
    Wait until element is not visible    jquery=#existing_users .select-buttons button.select-all:disabled
    Click Element    css=#existing_users .select-buttons .select-all

I deselect all members
    Wait until element is not visible    jquery=#existing_users .select-buttons button.deselect-all:disabled
    Click Element    css=#existing_users .select-buttons .deselect-all

I can add a new member
    [Arguments]    ${name}
    Click Link    Settings
    Click Link    Members
    Wait for injection to be finished
    Execute Javascript    document.querySelector('#member-list-functions div.quick-functions a.create').click()
    Wait for injection to be finished
    Click Link    xpath=//ul[@class='menu']//a[.='Add user']
    Wait Until Page Contains Element    css=li.select2-search-field input
    Input Text    css=li.select2-search-field input    ${name}
    Wait Until Element Is Visible    css=span.select2-match
    Click Element    css=span.select2-match
    Click Button    Ok
    Wait Until Page Contains    ${name}
    Close notification

The batch action buttons are disabled
    Wait Until Page Contains Element    jquery=button.disabled:contains("Change role")
    Wait Until Page Contains Element    jquery=button.disabled:contains("Remove")

The batch action buttons are enabled
    Wait Until Page Contains Element    jquery=button:not('[disabled]'):contains("Change role")
    Wait Until Page Contains Element    jquery=button:not('[disabled]'):contains("Remove")

I toggle the selection of the first user
    Click Element    jquery=#member-list-items label.item.user:first

I can invite Alice to join the workspace from the menu
    Wait Until Page Contains Element    css=#member-list-functions
    Execute Javascript    document.querySelector('#member-list-functions div.quick-functions a.create').click()
    Wait for injection to be finished
    Click Link    xpath=//ul[@class='menu']//a[.='Add user']
    I can invite Alice to the workspace

I can invite Alice to the workspace
    Wait for injection to be finished
    Input Text    css=li.select2-search-field input    alice
    Wait Until Element Is visible    css=span.select2-match
    Click Element    css=span.select2-match
    Click Button    Ok

I give the Consumer role to Allan
    I can open the workspace member settings tab
    Click element    css=div#member-list-functions div.quick-functions a.toggle-select
    Click Element    xpath=//input[@value='allan_neece']/..
    Click Button    Change role
    Wait until page contains element    //div[@class='panel-content']//select[@name='role']
    Select From List By Value    css=select[name=role]    Consumers
    Click Button    xpath=//div[@id='document-content']//div[contains(@class, 'panel-footer')]/button[@type='submit']
    Wait until page contains element    xpath=//input[@value='allan_neece']/../a[text()='Consume']

I give the Producer role to Allan
    I can open the workspace member settings tab
    Click element    css=div#member-list-functions div.quick-functions a.toggle-select
    Wait until element is visible    xpath=//div[contains(@class, 'batch-functions')]//button[@value='role']
    Click Element    xpath=//input[@value='allan_neece']/..
    Click Button    Change role
    Wait until page contains element    //div[@class='panel-content']//select[@name='role']
    Select From List By Value    css=select[name=role]    Producers
    Click Button    xpath=//div[@id='document-content']//div[contains(@class, 'panel-footer')]/button[@type='submit']
    Wait until page contains    Role updated
    Close notification
    Page Should Contain Element    xpath=//input[@value='allan_neece']/../a[text()='Produce']

I give the Moderator role to Allan
    I can open the workspace member settings tab
    Click element    css=div#member-list-functions div.quick-functions a.toggle-select
    Wait until element is visible    xpath=//div[contains(@class, 'batch-functions')]//button[@value='role']
    Click Element    xpath=//input[@value='allan_neece']/..
    Click Button    Change role
    Wait until page contains element    //div[@class='panel-content']//select[@name='role']
    Select From List By Value    css=select[name=role]    Moderators
    Click Button    xpath=//div[@id='document-content']//div[contains(@class, 'panel-footer')]/button[@type='submit']
    Wait until page contains    Role updated
    Close notification
    Page Should Contain Element    xpath=//input[@value='allan_neece']/../a[text()='Moderate']

I give the Admin role to Allan
    Sleep    0.5
    I can open the workspace member settings tab
    Click element    css=div#member-list-functions div.quick-functions a.toggle-select
    Wait until element is visible    xpath=//div[contains(@class, 'batch-functions')]//button[@value='role']
    Click Element    xpath=//input[@value='allan_neece']/..
    Click Button    Change role
    Wait until page contains element    //div[@class='panel-content']//select[@name='role']
    Select From List By Value    css=select[name=role]    Admins
    Click Button    xpath=//div[@id='document-content']//div[contains(@class, 'panel-footer')]/button[@type='submit']
    Wait until page contains    Role updated
    Close notification
    Page Should Contain Element    xpath=//input[@value='allan_neece']/../a[text()='Admin']

I can remove the Producer role from Allan
    I can open the workspace member settings tab
    Click element    xpath=//input[@value='allan_neece']/../a[text()='Produce']
    Wait until page contains    Remove special role
    Click Link    Remove special role
    Wait until element is visible    xpath=//div[@class='panel-content']//button[@value='role']
    Click Button    I am sure, remove role now
    Wait until page contains    Role updated
    Close notification
    Page Should Not Contain Element    xpath=//input[@value='allan_neece']/../a[text()='Produce']

I can remove the Moderator role from Allan
    I can open the workspace member settings tab
    Click element    xpath=//input[@value='allan_neece']/../a[text()='Moderate']
    Wait until page contains    Remove special role
    Click Link    Remove special role
    Wait until element is visible    xpath=//div[@class='panel-content']//button[@value='role']
    Click Button    I am sure, remove role now
    Wait until page contains    Role updated
    Close notification
    Page Should Not Contain Element    xpath=//input[@value='allan_neece']/../a[text()='Moderate']

I can change Allan's role to Moderator
    I can open the workspace member settings tab
    Wait until page contains element    xpath=//input[@value='allan_neece']/../a[text()='Produce']
    Click element    xpath=//input[@value='allan_neece']/../a[text()='Produce']
    Wait until page contains element    xpath=//*[contains(@class, 'tooltip-container')]//a[text()='Change role']
    Click Link    xpath=//*[contains(@class, 'tooltip-container')]//a[text()='Change role']
    Select From List By Value    css=select[name=role]    Moderators
    Click Button    xpath=//div[@id='document-content']//div[contains(@class, 'panel-footer')]/button[@type='submit']
    Wait until page contains element    xpath=//input[@value='allan_neece']/../a[text()='Moderate']

I can remove ${name} from the workspace members
    I can open the workspace member settings tab
    Click element    css=div#member-list-functions div.quick-functions a.toggle-select
    Wait until element is visible    css=button[value='remove']
    Click Element    jquery=#member-list input[value='${name}']
    Click Button    Remove
    Wait until element is visible
    ...    xpath=//div[@id='document-content']//div[contains(@class, 'panel-footer')]/button[@type='submit']
    Click Button    Ok
    Close notification
    Page Should Not Contain Element    jquery=#member-list input[value='${name}']

The breadcrumbs show the name of the workspace
    Page Should Contain Element    xpath=//a[@id='breadcrumbs-1' and text()='Open Market Committee']

I can enter the Manage Information Folder
    Click Link    link=Documents
    Wait for injection to be finished
    Page Should Contain    Manage Information
    Click Element
    ...    xpath=//form[@id='items']/fieldset/label/a[contains(@href, 'open-market-committee/manage-information')]
    Wait Until Page Contains    Preparation of Records
    Wait Until Page Contains    How to prepare records

I can enter the Projection Materials Folder
    Click Link    link=Documents
    Wait for injection to be finished
    Page Should Contain    Projection Materials
    Click Element
    ...    xpath=//form[@id='items']/fieldset/label/a[contains(@href, 'open-market-committee/projection-materials')]
    Wait Until Page Contains    Projection Material
    Wait Until Page Contains    Projection Materials
    Wait Until Page Contains    Open Market Committee

I view a document
    Click Link    Documents
    Wait for injection to be finished
    Click Element    css=label.group:nth-child(2)
    Wait for injection to be finished
    Click Element    css=label.type-word
    Wait for injection to be finished

I view a rich-text document
    Click Link    Documents
    Wait for injection to be finished
    Click Element    css=label.group:nth-child(2)
    Wait for injection to be finished
    Click Element    css=label.type-rich
    Wait for injection to be finished

Go back to the workspace by clicking the parent button
    Page Should Contain Element    xpath=//div[@class='toolbar-functions-area']/a[text()='Open Market Committee']
    Click Element    css=a#button-folder-up
    Wait Until Page Contains    Projection Materials

I can search for items
    Page Should Not Contain Element
    ...    xpath=//form[@id='items']/fieldset/label/a/strong[text()[contains(., 'Public bodies reform')]]
    Page Should Contain Element
    ...    xpath=//form[@id='items']/fieldset/label/a/strong[text()[contains(., 'Manage Information')]]
    Page Should Contain Element
    ...    xpath=//form[@id='items']/fieldset/label/a/strong[text()[contains(., 'Projection Materials')]]
    Input Text    xpath=//input[@name='sidebar-search']    Info
    Wait Until Page Contains Element
    ...    xpath=//form[@id='items']/fieldset/label/a/strong[text()[contains(., 'Public bodies reform')]]
    Page Should Contain Element
    ...    xpath=//form[@id='items']/fieldset/label/a/strong[text()[contains(., 'Manage Information')]]
    Page Should Not Contain Element
    ...    xpath=//form[@id='items']/fieldset/label/a/strong[text()[contains(., 'Projection Materials')]]

I can see that the workspace is archived
    [Arguments]    ${title}
    Wait until page contains element    xpath=//a/strong[text()='Archived']

I can archive the current context
    I open the document context menu
    Wait until page contains element    jquery=#extra-options [title="Archive this document"]
    Click Element    jquery=#extra-options [title="Archive this document"]
    Close notification
    I open the document context menu
    Page should contain element    jquery=#extra-options [title="Unarchive this document"]
    I close the document context menu

I can unarchive the current context
    I open the document context menu
    Wait until page contains element    jquery=#extra-options [title="Unarchive this document"]
    Click Element    jquery=#extra-options [title="Unarchive this document"]
    Close notification
    I open the document context menu
    Page should contain element    jquery=#extra-options [title="Archive this document"]
    I close the document context menu

I open the sidebar more menu
    Execute Javascript    document.querySelector(".quick-functions a.more").click()
    Wait for injection to be finished

I open the sidebar create content menu
    Execute Javascript    document.querySelector('.quick-functions a.create').click()
    Wait for injection to be finished

I open the create document panel
    Click link    Documents
    I open the sidebar create content menu
    Execute Javascript    document.querySelectorAll('.tippy-box a.icon-document.create-document')[0].click()
    Wait Until Page Contains Element    css=.panel-content input[name=title]

I open the create folder panel
    Click link    Documents
    I open the sidebar create content menu
    Execute Javascript    document.querySelectorAll('.tippy-box a.create-folder')[0].click()
    Wait Until Page Contains Element    css=.panel-content input[name=title]

I open the create link panel
    Click link    Documents
    I open the sidebar create content menu
    Execute Javascript    document.querySelectorAll('.tippy-box a.icon-link.create-document')[0].click()
    Wait Until Page Contains Element    css=.panel-content input[name=title]

I can show only my documents
    I open the sidebar more menu
    Select checkbox    xpath=//input[@name='show_my_documents']
    Wait for injection to be finished

I can see that the first item displayed in the navigation is
    [Arguments]    ${title}
    Page Should Contain Element    jquery=#items .item:first:contains(${title})

I can see that the last item displayed in the navigation is
    [Arguments]    ${title}
    Page Should Contain Element    jquery=#items .item:last:contains(${title})

I can see that the only item displayed in the navigation is
    [Arguments]    ${title}
    I can see that the first item displayed in the navigation is    ${title}
    I can see that the last item displayed in the navigation is    ${title}

I can create a new document
    [Arguments]    ${title}
    I open the create document panel
    Input Text    css=.panel-content input[name=title]    text=${title}
    Press Keys    css=.panel-content input[name=title]    ENTER
    Wait for injection to be finished
    Wait Until Page Contains Element    xpath=//*[@id="items"]//strong[@class="title" and contains(text(),'${title}')]

I can create a new link
    [Arguments]    ${title}    ${url}
    I open the create link panel
    Input Text    css=.panel-content input[name=title]    text=${title}
    Input Text    css=.panel-content input[name=remoteUrl]    text=${url}
    Press Keys    css=.panel-content input[name=remoteUrl]    ENTER
    Wait for injection to be finished
    Wait Until Page Contains Element    jquery=.type-link a:contains('${title}')

I can edit the link
    [Arguments]    ${title}    ${newurl}
    Click Link    jquery=.type-link a:contains('${title}')
    Wait for injection to be finished
    I change the remoteUrl    ${newurl}

I can publish the new link
    [Arguments]    ${title}
    Click Link    jquery=.type-link a:contains('${title}')
    Wait for injection to be finished
    Click element    xpath=//label[@id='workflow-state']
    Click Element    xpath=//label[@id='workflow-state']//select/option[contains(text(), 'Published')]
    Wait Until Element Is Visible
    ...    xpath=//label[@id='workflow-state']//select/option[@selected='selected' and contains(text(), 'Published')]

# TODO Update the link widget so it shows the title

I can see the link
    [Arguments]    ${title}    ${url}
    Click link    Documents
    Wait Until Page Contains Element    jquery=.type-link a:contains('${title}')
    Click Link    jquery=.type-link a:contains('${title}')
    Wait for injection to be finished
    Page Should Contain Element    xpath=//div[@id="document-content"]//a[@href="${url}"]

I cannot create a new document
    Click link    Documents
    Wait until page contains    Expand sidebar
    Page Should Not Contain Element    css=.quick-functions a.create

I can create a new folder
    I open the create folder panel
    Input Text    css=.panel-content input[name=title]    text=My Humble Folder
    Input Text    css=.panel-content textarea[name=description]    text=The description of my humble folder
    Click the modal create button no notification
    # We cannot jet test the folders existence without reloading
    Go To    ${PLONE_URL}/workspaces/open-market-committee
    # On reload the navbar is closed by default - open it
    Click link    Documents
    Wait until page contains element
    ...    css=a.pat-inject[href$='/open-market-committee/my-humble-folder/@@sidebar.documents']

I can edit the new folder
    Click Element    jquery=.item .title:contains(My Humble Folder)
    Wait for injection to be finished
    I open the sidebar more menu
    Execute Javascript    document.querySelector(".tippy-box .menu .icon-pencil").click()
    Wait until element is visible    jquery=.panel-body [name=title]
    Input Text    jquery=.panel-body [name=title]    My Superpowered Folder
    Input Text    jquery=.panel-body [name=description]    The description of my superpowered folder
    Click Element    jquery=.button-bar #form-buttons-edit
    Wait until element is visible    jquery=.folder-title:contains(My Superpowered Folder)

I can create a new image
    I open the create document panel
    Click Element    css=.canvas-toolbar a.icon-file-image
    Wait Until Page Contains Element    css=.panel-content form
    Wait Until Page Contains Element    css=.panel-content input[name=title]
    Input Text    css=#sheet-image input[name=title]    text=My Image
    Input Text    css=#sheet-image textarea[name=description]    text=The description of my humble image
    Click the modal create button no notification    \#sheet-image
    Wait Until Page Contains Element    xpath=//*[@id="items"]//strong[@class="title" and contains(text(),'My Image')]

I can create a structure
    I open the create folder panel
    Input Text    css=.panel-content input[name=title]    text=Another Folder
    Click the modal create button no notification
    Go To    ${PLONE_URL}/workspaces/open-market-committee
    Wait Until Page Contains Element    css=#workspace-tabs a.current.landing
    Click link    Documents
    Wait Until Page Contains Element
    ...    css=a.pat-inject[href$='/open-market-committee/another-folder/@@sidebar.documents']
    Click Element    css=a.pat-inject[href$='/open-market-committee/another-folder/@@sidebar.documents']
    Wait Until Page Contains Element    css=#selector a.pat-inject[href$='/open-market-committee/@@sidebar.documents']
    I open the create document panel
    Input Text    css=.panel-content input[name=title]    text=Document in subfolder
    Click the modal create button no notification    \#sheet-text
    # This must actually test for the document content of the rendered view
    Wait Until Page Contains Element
    ...    xpath=//*[@id="items"]//strong[@class="title" and contains(text(),'Document in subfolder')]
    Wait for injection to be finished
    Click Button    Save
    Wait for injection to be finished
    Go To    ${PLONE_URL}/workspaces/open-market-committee
    Wait Until Page Contains Element    css=#workspace-tabs a.current.landing
    Click link    Documents
    Wait for injection to be finished
    Click element    xpath=//a/strong[contains(text(), 'Another Folder')]
    Wait Until Page Contains Element
    ...    xpath=//a[@class='pat-inject follow pat-switch'][contains(@href, '/document-in-subfolder')]

Input date into date picker
    [Arguments]    ${selector}    ${date}
    # We are deliberately cheating here by writing the date value via Javascript directly into the hidden input field. We might want to change this later, but for the moment, this allows us to keep our current tests
    Execute javascript    document.querySelector(${selector}).value = '${date}'
    Execute javascript    document.querySelector(${selector}).dispatchEvent(new Event('change'))

I can create a new event
    [Arguments]    ${title}    ${start}    ${end}
    Click link    Events
    Wait for injection to be finished
    Click Link    Create event
    Wait Until Page Contains Element    css=.panel-content .panel-body form
    Input Text    css=.panel-content input[name=title]    text=${title}
    Input date into date picker    '.panel-content input[name=end]'    ${end}
    Input date into date picker    '.panel-content input[name=start]'    ${start}
    # Click into the title field again to remove focus from the date fields
    Click element    css=.panel-content input[name=title]
    Click the modal create button    .panel-content
    Wait until page contains element    jquery=.event-details input[name="title"][value="${title}"]

I can create a new event for today
    [Arguments]    ${title}    ${organizer}=Allan Neece    ${invitees}=Dollie Nocera
    Click link    Events
    Wait for injection to be finished
    Click Link    Create event
    Wait Until Page Contains Element    css=.panel-content .panel-body form
    Input Text    css=.panel-content form#sheet-event input[name=title]    text=${title}
    Click the modal create button    .panel-content

Select from autocomplete
    [Arguments]    ${name}    ${value}
    Wait Until Keyword Succeeds    10x    100ms    Scroll Element Into View    xpath=//input[@name='${name}']/..
    Click Element    xpath=//input[@name='${name}']/..
    Wait Until Element Is Visible    css=.select2-input.select2-focused
    Input text    css=.select2-input.select2-focused    ${value}
    Wait Until Element Is Visible    xpath=//span[@class='select2-match'][text()='${value}']
    Click Element    xpath=//span[@class='select2-match'][text()='${value}']

I cannot create a new event
    [Arguments]    ${title}    ${start}    ${end}
    Click link    Events
    Wait for injection to be finished
    Click Link    Create event
    Wait Until Page Contains Element    css=.panel-content .panel-body form
    Input Text    css=.panel-content input[name=title]    text=${title}
    Input date into date picker    '.panel-content input[name=end]'    ${end}
    Input date into date picker    '.panel-content input[name=start]'    ${start}
    # Circumvent the JS convenience method that automatically sets the end date to start if too early by setting it again.
    Input date into date picker    '.panel-content input[name=end]'    ${end}
    Wait Until Element Is Visible    jquery=button[name='form.buttons.create']:disabled

I can edit an event
    [Arguments]    ${start}    ${end}    ${timezone}    ${organizer}=Allan Neece    ${invitees}=Dollie Nocera
    Wait Until Page Contains Element    xpath=//h3[text()='Older events']
    Click Element    xpath=//h3[text()='Older events']
    Wait until element is visible    jquery=.event-list a:contains("Christmas")
    Execute javascript    jQuery('.event-list a:contains("Christmas")').first().click()
    Wait for injection to be finished
    Input Text    css=#document-content-workspaces .event-details input[name=title]    text=Christmas (updated)
    Input date into date picker    '#document-content-workspaces .event-details input[name=start]'    ${start}
    Input date into date picker    '#document-content-workspaces .event-details input[name=end]'    ${end}
    # Ignore the MoveTargetOutOfBoundsException error, the browser is actually properly scrolling
    Run Keyword And Ignore Error
    ...    Scroll Element into view
    ...    css=#document-content-workspaces .event-details input[name='title']
    Click Element    css=#document-content-workspaces .event-details input[name='title']
    Click Element    css=#document-content-workspaces .event-details input[name='location']
    Select From List By Label    timezone    ${timezone}
    Select from autocomplete    organizer    ${organizer}
    Select from autocomplete    invitees    ${invitees}
    I save the event
    Wait Until Page Contains Element    jquery=#workspace-events a:contains(updated)
    Page should contain element    css=input[name='start'][value='${start}']
    Page should contain element    jquery=label.organiser .select2-chosen:contains("${organizer}")
    Page should contain element    jquery=label.invitees .select2-choices:contains("${invitees}")
    List selection should be    timezone    ${timezone}
    Element should contain
    ...    css=#workspace-events [href$="open-market-committee/christmas-updated#document-body"] h3.title
    ...    CHRISTMAS (UPDATED)

I cannot edit an event because of validation
    [Arguments]    ${title}    ${start}    ${end}    ${timezone}
    Reload Page
    Click link    Events
    Wait for injection to be finished
    Click Element    xpath=//h3[text()='Older events']
    Wait until element is visible    jquery=.event-list a:contains("${title}")
    Click link    jquery=a:contains("${title}")
    Wait Until Page Contains Element    css=div.event-details
    Input Text    css=#document-content-workspaces .event-details input[name=title]    text=${title} (updated)
    Input date into date picker    '#document-content-workspaces .event-details input[name=start]'    ${start}
    Input date into date picker    '#document-content-workspaces .event-details input[name=end]'    ${end}
    Select From List By Label    timezone    ${timezone}
    Wait until element is visible    jquery=#save-button:disabled

I can delete an event
    [Arguments]    ${title}
    Click link    jquery=a:contains("${title}")
    Wait for injection to be finished
    I open the document context menu
    Click Element    jquery=.tooltip-container .icon-trash:contains("Delete")
    Wait until page contains element    xpath=//div[@class='panel-content']//button[@name='form.buttons.Delete']
    Click Button    I am sure, delete now
    Wait Until Page Contains    has been deleted
    Element should not be visible    jquery=a:contains("${title}")

I can create a central calendar
    [Arguments]    ${title}    ${visibility}=none    ${maintenance}=none    ${reader_group}=    ${maintainer_group}=
    Click Link    Create event or calendar
    Wait Until Page Contains Element    css=.panel-content .panel-body form
    Click Element    jquery=.canvas-toolbar a:contains("Calendar")
    Input Text    css=.panel-content form#sheet-calendar input[name=title]    text=${title}
    Click Element    css=input[name=allow_contributions]
    Select Radio Button    maintenance    ${maintenance}
    IF    '${maintenance}'=='groups'
        I look for and select ${maintainer_group} in autosuggest multiselect field #maintainer_group_list
    END
    Select Radio Button    visibility    ${visibility}
    IF    '${visibility}'=='groups'
        I look for and select ${reader_group} in autosuggest multiselect field #reader_group_list
    END
    # Click into the description field to remove focus from the picker field
    Click element    css=.panel-content textarea[name=description]
    # Because of a stupid scrolling out of bounds bullshit issue, we click the fracking button via Javascript
    Execute Javascript    jQuery("button:contains('Create calendar')").click()
    Wait for injection to be finished
    Wait until page contains element    jquery=div#calendar-central-calendars label:contains("${title}")

I can delete a central calendar
    [Arguments]    ${title}
    Click Element
    ...    xpath=//span[@class="calendar-name" and text()[contains(., '${title}')]]/../a[contains(@class, 'pat-tooltip')]
    Wait until page contains    Edit calendar properties
    Click Link    Delete calendar '${title}'
    Wait for injection to be finished
    Click Button    I am sure, delete now
    Close notification

I can share the event to a central calendar
    [Arguments]    ${calendar}
    Select From List By Label    css=select[name='shared_calendar']    ${calendar}
    I save the event

I cannot share the event to a central calendar
    [Arguments]    ${calendar}
    Page should contain element    jquery=[name='shared_calendar'] option:contains('Not shared')
    Page should not contain element    jquery=[name='shared_calendar'] option:contains('${calendar}')

I see the event in the calendar
    [Arguments]    ${title}
    Wait Until Page Contains Element    jquery=div.fc-event-title:contains("${title}")

I see the central calendar in the sidebar
    [Arguments]    ${title}
    Wait Until Page Contains Element    jquery=#calendar-central-calendars .calendar-central:contains("${title}")

I do not see the central calendar in the sidebar
    [Arguments]    ${title}
    Wait for injection to be finished
    Page Should Not Contain Element    jquery=#calendar-central-calendars .calendar-central:contains("${title}")

I can change the description of the calendar
    [Arguments]    ${title}
    Click Element
    ...    xpath=//span[@class="calendar-name" and text()[contains(., '${title}')]]/../a[contains(@class, 'pat-tooltip')]
    Wait until page contains    Edit calendar properties
    Click Link    Edit calendar properties
    Wait for injection to be finished
    Input Text    css=textarea[name=description]    Changed
    Click Button    Save and close
    Close notification

I can change the visibility of the calendar
    [Arguments]    ${title}    ${visibility}=none
    Click Element
    ...    xpath=//span[@class="calendar-name" and text()[contains(., '${title}')]]/../a[contains(@class, 'pat-tooltip')]
    Wait until page contains    Edit calendar properties
    Click Link    Edit calendar properties
    Wait for injection to be finished
    Select Radio Button    visibility    ${visibility}
    Click Button    Save and close
    Close notification

I see the event as part of a central calendar
    [Arguments]    ${title}
    Wait Until Page Contains Element    jquery=.cal-cat-central-calendar div.fc-event-title:contains("${title}")

I do not see the event as part of a central calendar
    [Arguments]    ${title}
    Page Should Not Contain Element    jquery=.cal-cat-central-calendar div.fc-event-title:contains("${title}")

The file appears in the sidebar
    Wait until Page contains Element    xpath=//fieldset/label/a/strong[text()[contains(., 'bärtige_flößer.odt')]]

I open the file detail view
    Click link    bärtige_flößer.odt
    Wait for injection to be finished

The upload appears in the stream
    Wait until Page contains Element
    ...    xpath=//a[@href='activity-stream']//section[contains(@class, 'preview')]//img[contains(@src, 'bärtige_flößer.odt')]

# The self-healing Close messages below are a source of Heisenbugs in the test

I Click the Workflow Submit Button
    Wait for injection to be finished
    Click element    xpath=//label[@id='workflow-state']

I submit the content item
    Wait for injection to be finished
    Click element    xpath=//select[@id='workflow_action']
    Click Element    xpath=//select[@id='workflow_action']//option[contains(text(), 'Pending')]
    Wait for injection to be finished
    Wait until page contains element
    ...    xpath=//select[@id='workflow_action']/option[@title='Pending' and @selected='selected']
    Close notification
    Wait until page does not contain    The workflow state has been changed

I retract the content item
    Wait until element is visible    xpath=//label[@id='workflow-state']
    Click element    xpath=//label[@id='workflow-state']
    Click Element    xpath=//label[@id='workflow-state']//select/option[contains(text(), 'Draft')]
    Close notification
    Wait until page does not contain    The workflow state has been changed

I can publish the content item
    Wait for injection to be finished
    Click element    xpath=//select[@id='workflow_action']
    Click Element    xpath=//select[@id='workflow_action']/option[@value='publish']
    Wait Until Element Is Visible
    ...    xpath=//select[@id='workflow_action']/option[@selected='selected' and @value='published']
    Close notification
    Wait until page does not contain    The workflow state has been changed

I cannot publish the content item
    Wait for injection to be finished
    Click element    xpath=//label[@id='workflow-state']
    Element should be visible    xpath=//label[@id='workflow-state']//select/option[contains(text(), 'Draft')]
    Element should not be visible    xpath=//label[@id='workflow-state']//select/option[contains(text(), 'Published')]

I can edit the document
    Click element    css=#document-content .tiptap-container
    Element should be visible    xpath=//div[@id='document-body']//div[@id='texteditor-toolbar-text']
    Element should be visible    xpath=//div[@id='document-body']//button[@id='save-button']

I cannot edit the document
    Click element    css=#document-content .tiptap-container
    Element should not be visible    xpath=//div[@id='document-body']//div[@id='texteditor-toolbar-text']
    Element should not be visible    xpath=//div[@id='document-body']//button[@id='save-button']

I cannot edit the link
    Click link    Documents

I can see the document
    [Arguments]    ${title}
    Click link    Documents
    Page should contain    ${title}

I cannot see the document
    [Arguments]    ${title}
    Click link    Documents
    Page should not contain    ${title}

Allan has the option to create a document
    I am logged in as the user allan_neece
    I go to the Shareholder Information Workspace
    I open the create document panel

I can click the security icon in the header
    Click element    xpath=//p[@class="security-setting"]/a
    Wait for injection to be finished

# *** workspace and case content related keywords ***

I browse to a workspace
    Go To    ${PLONE_URL}/workspaces/open-market-committee
    Click Link    link=Documents
    Wait for injection to be finished
    Click Link    link=Manage Information
    Wait for injection to be finished

I browse to the workspace
    [Arguments]    ${title}
    Go To    ${PLONE_URL}/workspaces
    Wait for injection to be finished
    Click element    xpath=//span[@id='workspaces']//h3[text()="${title}"]
    Wait for injection to be finished

I cannot access the document
    [Arguments]    ${path}
    Go To    ${PLONE_URL}/workspaces/${path}
    Element should not be visible    xpath=//h1[@id="document-title"]

I browse to a Consumer workspace
    Go To    ${PLONE_URL}/workspaces/service-announcements
    Click Link    link=Documents

I browse to a document
    I browse to a workspace
    Wait for injection to be finished
    Click Link    xpath=//label[contains(@class, 'item')]/a[contains(@href, 'repurchase-agreements')][1]
    Wait for injection to be finished

I list the documents with the tag
    [Arguments]    ${tag}
    I open the sidebar documents tile
    Wait Until Page Contains Element    jquery=#selector-functions form.view-options option:contains(Tags)
    Select from List By Value    grouping    label
    Wait for injection to be finished
    Click Element    jquery=.group.type-tag > a >strong:contains('${tag}')
    Wait for injection to be finished

I view the document
    Go To    ${PLONE_URL}/workspaces/open-market-committee/manage-information/repurchase-agreements

I open the document
    [Arguments]    ${title}
    Wait Until Page Contains Element    jquery=#sidebar-content .item a :contains("${title}")
    Click Element    jquery=#sidebar-content .item a :contains("${title}")
    Wait for injection to be finished

I can see the item is in state
    [Arguments]    ${state}
    Wait until element is visible
    ...    xpath=//select[@id="workflow_action"]/option[@selected="selected"][text()="${state}"]

I browse to an image
    I browse to a workspace
    Wait for injection to be finished
    Click Element    xpath=//label[contains(@class, 'item')]/a[contains(@href, 'budget-proposal')][1]
    Wait for injection to be finished

I view the image
    Go To    ${PLONE_URL}/workspaces/open-market-committee/manage-information/budget-proposal/view
    Wait until element is visible    xpath=//label[contains(@class, 'item')]/a[contains(@href, 'budget-proposal')]

I expand the new version fieldset
    I open the metadata panel
    Click Element    xpath=//input[@id="cmfeditions_save_new_version"]

I upload a new image
    I expand the new version fieldset
    Choose File    css=input[name=image]    ${UPLOADS}/vision-to-product.png
    I close the metadata panel with save

I browse to a file
    I browse to a workspace
    Wait Until Page Contains Element    jquery=#sidebar-content #workspace-documents .type-word :contains(Minutes)
    Click Element    jquery=#sidebar-content #workspace-documents .type-word :contains(Minutes)
    Wait for injection to be finished

I view the file
    Go To    ${PLONE_URL}/workspaces/open-market-committee/manage-information/minutes/view

I upload a new file
    I expand the new version fieldset
    Choose File    css=input[name=file]    ${UPLOADS}/bärtige_flößer.odt
    I close the metadata panel with save

I view the folder
    Go To    ${PLONE_URL}/workspaces/open-market-committee/manage-information/projection-materials/view

I view the task
    Go To    ${PLONE_URL}/workspaces/example-case/populate-metadata

I change the title
    I open the document context menu
    I set the new title through the already open context menu    New title ♥

The document has the new title
    Wait Until Page Contains Element
    ...    xpath=//*[@id="items"]//strong[@class="title" and contains(text(),'New title ♥')]

I open the metadata panel
    Wait until element is visible    css=.quick-functions a.icon-ellipsis
    Click Link    css=.quick-functions a.icon-ellipsis
    Wait until page contains    Metadata
    Click Link    Metadata
    Wait until element is visible    css=#pat-modal-panel

I close the metadata panel with save
    Click Element    xpath=//dialog[@id="pat-modal-panel"]//button[text()='Save']
    Wait for injection to be finished
    Close Notification

I see the document title
    [Arguments]    ${title}
    Element should be visible    xpath=//div[@class="modal-panel-body"]//input[@name="title"][@value="${title}"]

I cannot edit the document title
    Element should be visible    xpath=//div[@class="modal-panel-body"]//input[@name="title"][@disabled="disabled"]

I change the description
    I open the metadata panel
    Input Text    xpath=//div[@class="modal-panel-body"]//textarea[@name="description"]    New description ☀
    I close the metadata panel with save

The document has the new description
    I open the metadata panel
    Page Should Contain    New description ☀

I tag the item
    [Arguments]    ${tag}
    I open the metadata panel
    Input Text    xpath=//div[@class="modal-panel-body"]//input[contains(@class, 'select2-input')]    ${tag},
    Press Keys    xpath=//div[@class="modal-panel-body"]//input[contains(@class, 'select2-input')]    ESCAPE
    I close the metadata panel with save

I tag the item with a suggestion
    [Arguments]    ${search_for}    ${selection}
    I open the metadata panel
    Input Text    xpath=//div[@class="modal-panel-body"]//input[contains(@class, 'select2-input')]    ${search_for}
    Wait until element is visible    xpath=//div[@class='select2-result-label'][contains(text(), '${selection}')]
    Click Element    xpath=//div[@class='select2-result-label'][contains(text(), '${selection}')]
    Press Keys    xpath=//div[@class="modal-panel-body"]//input[contains(@class, 'select2-input')]    ESCAPE
    I close the metadata panel with save

I clear the tag for an item
    I open the metadata panel
    Click Link    css=.select2-search-choice-close
    I close the metadata panel with save

The metadata has the new tag
    I open the metadata panel
    Page Should Contain    NewTag☃

I change the remoteUrl
    [Arguments]    ${url}
    I open the metadata panel
    Input Text    xpath=//div[@class="modal-panel-body"]//input[@name="remoteUrl"]    ${url}
    I close the metadata panel with save

# *** case related keywords ***

I am in a case workspace as a workspace member
    I am logged in as the user allan_neece
    I go to the Example Case

I am in a case workspace as a workspace admin
    I am logged in as the user christian_stoney
    I go to the Example Case

I move the example workspace to state prepare
    I can go to the Example Case
    I can go to the sidebar tasks tile of my case
    I can open a milestone task panel    prepare
    I select the task check box    Draft proposal
    I select the task check box    Budget
    I select the task check box    Stakeholder feedback

I move the example workspace to state complete
    I move the example workspace to state prepare
    I can close a milestone    Prepare
    I can open a milestone task panel    complete
    I select the task check box    Quality check

Admin moves the example workspace to state complete
    I am in a case workspace as a workspace admin
    I move the example workspace to state complete

I can create a new case
    [Arguments]    ${title}
    Go To    ${PLONE_URL}/workspaces
    Click Link    link=Create workspace
    Wait for injection to be finished
    Input Text    name=title    text=${title}
    Input Text    name=description    text=Let's get organized
    Select From List By Value    workspace-type    case-template
    Wait Until Page Contains    Case Template
    Click Button    Create workspace
    Wait for injection to be finished
    Wait Until Page Contains    Item created

I can create a new template case
    [Arguments]    ${title}
    Go To    ${PLONE_URL}/templates/++add++ploneintranet.workspace.case
    Wait Until Element Is Visible    jquery=input[name='form.widgets.IBasic.title']
    Input Text for sure    form.widgets.IBasic.title    New template
    # Ignore the MoveTargetOutOfBoundsException error, the browser is actually properly scrolling
    Run Keyword And Ignore Error    Scroll Element into view    css=#form-buttons-save
    Click Button    Save
    Wait Until Page Contains    Item created
    Go To    ${PLONE_URL}/workspaces

I can create a new case from a template
    [Arguments]    ${template}    ${title}
    Go To    ${PLONE_URL}/workspaces
    Click Link    link=Create workspace
    Wait for injection to be finished
    Input Text    name=title    text=${title}
    Input Text    name=description    text=Something completely different
    Select From List By Value    workspace-type    case-template
    Wait Until Page Contains    Case Template
    Click Button    Create workspace
    Wait Until Page Contains    Item created
    Wait for injection to be finished

I can delete a case
    [Arguments]    ${case_id}
    Go To    ${PLONE_URL}/workspaces/${case_id}/delete_confirmation
    Wait until page contains element
    ...    xpath=//div[@class='buttons button-bar pat-bumper']//button[@name='form.buttons.Delete']
    Click Button    I am sure, delete now
    Wait Until Page Contains    has been deleted

I can delete a template case
    [Arguments]    ${case_id}
    Go To    ${PLONE_URL}/templates/${case_id}/delete_confirmation
    Wait until page contains element
    ...    xpath=//div[@class='buttons button-bar pat-bumper']//button[@name='form.buttons.Delete']
    Click Button    I am sure, delete now
    Wait Until Page Contains    has been deleted

I go to the dashboard
    Click link    Dashboard
    Wait for injection to be finished

I reload the dashboard
    # Ignore the MoveTargetOutOfBoundsException error, the browser is actually properly scrolling
    Run Keyword And Ignore Error    Scroll Element into view    jquery=select[name="dashboard"]
    Click Element    css= .tab.section-dashboard
    Wait Until Page Contains    Dashboard

I select the task centric view
    Wait Until Page Contains    Dashboard
    Select From List By Label    dashboard    Task centric view
    Wait for injection to be finished

I mark a new task complete
    # make sure that the Todo portlet is really present on the screen by forcing the autoload-visible-injection
    Execute Javascript    jQuery('.portlet.app-todo .discrete-injection').focus()
    Wait until element is visible    css=div.app-todo.portlet label.show-more
    Click Element    css=div.app-todo.portlet label.show-more
    Wait until element is visible    xpath=(//a[@title='Todo soon'])
    Run Keyword And Ignore Error    Scroll Element into view    xpath=(//a[@title='Todo soon'])
    Select Checkbox    xpath=(//a[@title='Todo soon'])[1]/preceding-sibling::input[@name="active-tasks:list"]
    Wait until Page Contains    Task state changed

I select the task check box
    [Arguments]    ${title}
    I see a task is open    ${title}
    Click Element    xpath=//a[contains(@title, '${title}')]/../..//input[@name='task_action']
    Wait for injection to be finished
    I see a task is complete    ${title}

I unselect the task check box
    [Arguments]    ${title}
    I see a task is complete    ${title}
    Click Element    xpath=//a[contains(@title, '${title}')]/../..//input[@name='task_action']
    Wait for injection to be finished
    I see a task is open    ${title}

I see a task is complete
    [Arguments]    ${title}
    Page Should Contain Element    jquery=label.checked a[title='${title}']

I see a task is open
    [Arguments]    ${title}
    Page Should Contain Element    jquery=label.unchecked a[title='${title}']

I see the task quality check has state
    [Arguments]    ${state}
    Go To    ${PLONE_URL}/workspaces/example-case/quality-check
    Wait for injection to be finished
    Element should be visible    xpath=//label[@id='workflow-state' and @data-option='${state}']

I do not see the completed task is not listed
    Page Should Not Contain Element    xpath=(//a[title='Todo soon'])

I can go to the sidebar tasks tile of my case
    Click Link    link=Tasks
    Wait for injection to be finished

I can add a new task
    [Arguments]    ${title}    ${username}    ${milestone}=new    ${initiator}=Allan Neece
    Click Link    Create task
    Wait Until Page Contains Element    css=.panel-body
    Input Text    xpath=//div[@class='panel-body']//input[@name='title']    text=${title}
    Input Text    xpath=//div[@class='panel-body']//textarea[@name='description']    text=Plan for success
    Element Should Contain    css=label.initiator div.select2-container a span    ${initiator}
    Execute Javascript    jQuery('label.assignee div.select2-container input').removeClass('select2-offscreen')
    Input Text    css=label.assignee div.select2-container input    ${username}
    Wait Until Element Is visible    xpath=//span[@class='select2-match'][text()='${username}']
    Click Element    xpath=//span[@class='select2-match'][text()='${username}']
    Select From List By Value    milestone    ${milestone}
    Press Keys    xpath=//div[@class='panel-body']//input[@name='title']    ENTER
    Wait for injection to be finished
    Wait Until Page Contains    ${title}

I can close a milestone
    [Arguments]    ${milestone}
    I can open a milestone task panel    ${milestone}
    I can go to the sidebar tasks tile of my case
    Click Link    xpath=//fieldset/h4[contains(text(), '${milestone}')]/parent::fieldset//a[text()='Close']
    Wait for injection to be finished
    # auto-closes current, reopen
    I can open a milestone task panel    ${milestone}
    Wait until element is visible
    ...    xpath=//fieldset/h4[contains(text(), '${milestone}')]/parent::fieldset//a[contains(text(), 'Reopen')]

I cannot close a milestone
    [Arguments]    ${milestone}
    I can open a milestone task panel    ${milestone}
    Element should not be visible
    ...    xpath=//fieldset/h4[contains(text(), '${milestone}')]/parent::fieldset//a[text()='Close']

I can reopen a milestone
    [Arguments]    ${milestone}
    I can open a milestone task panel    ${milestone}
    Wait until element is visible
    ...    xpath=//fieldset/h4[contains(text(), '${milestone}')]/parent::fieldset//a[text()='Reopen']
    Click Link    xpath=//fieldset/h4[contains(text(), '${milestone}')]/parent::fieldset//a[text()='Reopen']
    Wait for injection to be finished
    # auto-closes current, reopen
    I can open a milestone task panel    ${milestone}
    Wait until element is visible
    ...    xpath=//fieldset/h4[contains(text(), '${milestone}')]/parent::fieldset//a[contains(text(), 'Close')]

I can open a milestone task panel
    [Arguments]    ${milestone}
    # panel 'open' state is session dependent, force open
    Run Keyword And Ignore Error    Click Element    css=#milestone-${milestone}.closed h4
    Wait for injection to be finished

I can see the user is a guest
    [Arguments]    ${username}
    Wait until page contains element
    ...    xpath=//form[@id='member-list-items']//strong[@class='title' and contains(text(), '${username}')]/../../a[contains(text(), 'Guest')]

I write a status update
    [Arguments]    ${message}
    Wait for injection to be finished
    Wait Until Element Is visible    css=.post-box .ProseMirror
    Element should not be visible    css=button[name='form.buttons.statusupdate']
    Click element    css=.post-box .ProseMirror
    Wait Until Element Is visible    css=button[name='form.buttons.statusupdate']
    Input Text    css=.post-box .ProseMirror    ${message}

I cannot write a new status update
    Wait for injection to be finished
    Element should not be visible    css=form.post-box

I post a status update
    [Arguments]    ${message}
    I write a status update    ${message}
    I submit the status update

I submit the status update
    Click button    css=button[name='form.buttons.statusupdate']
    Wait for injection to be finished

I open the post action menu
    [Arguments]    ${message}
    Wait Until Element Is visible
    ...    xpath=//section[@class='post-content']//p[contains(text(), '${message}')]/../..//a[contains(@class, 'icon-ellipsis')]
    Click Link
    ...    xpath=//section[@class='post-content']//p[contains(text(), '${message}')]/../..//a[contains(@class, 'icon-ellipsis')]
    Wait for injection to be finished

I cannot open the post action menu by Alice
    [Arguments]    ${message}
    Page should not contain link
    ...    xpath=//h4[contains(text(), 'Alice')]/../../../section[@class='post-content']//p[contains(text(), '${message}')]/../..//a[contains(@class, 'icon-ellipsis')]

I open the comment action menu
    [Arguments]    ${message}
    Wait Until Element Is visible
    ...    xpath=//section[@class='comment-content']//p[contains(text(), '${message}')]/../..//a[contains(@class, 'icon-ellipsis')]
    Click Link
    ...    xpath=//section[@class='comment-content']//p[contains(text(), '${message}')]/../..//a[contains(@class, 'icon-ellipsis')]
    Wait for injection to be finished

I cannot open the comment action menu
    [Arguments]    ${message}
    Page should not contain link
    ...    xpath=//section[@class='comment-content']//p[contains(text(), '${message}')]/../..//a[contains(@class, 'icon-ellipsis')]

I delete the status update
    [Arguments]    ${message}
    I open the post action menu    ${message}
    Wait Until Element Is Visible    jquery=.icon-trash:contains("Delete post")
    Click element    jquery=.icon-trash:contains("Delete post")
    Wait for injection to be finished
    Click Button    I am sure, delete now

I can see the status delete confirmation
    Wait Until Page Contains    This post has been successfully deleted.

I delete the status reply
    [Arguments]    ${message}
    I open the comment action menu    ${message}
    Click Link    Delete comment
    Wait for injection to be finished
    Click Button    I am sure, delete now

I can see the status reply delete confirmation
    Wait Until Page Contains    This comment has been successfully deleted.

I can edit the status update
    [Arguments]    ${message1}    ${message2}
    I open the post action menu    ${message1}
    Click Link    Edit post
    Wait Until Element Is Visible    jquery=div.panel-body div.ProseMirror p:contains("${message1}")
    Input Text    jquery=div.panel-body div.ProseMirror    ${message2}
    Click Button    Save
    Wait Until Page Contains    Edited

I can edit the status reply
    [Arguments]    ${message1}    ${message2}
    I open the comment action menu    ${message1}
    Click Link    Edit comment
    Wait Until Element Is Visible    jquery=div.panel-body div.ProseMirror p:contains("${message1}")
    Input Text    jquery=div.panel-body div.ProseMirror    ${message2}
    Click Button    Save
    Wait Until Page Contains    Edited

I can access the original text
    [Arguments]    ${message1}    ${message2}
    Click Link
    ...    xpath=//div[starts-with(@id,'activity-stream')]//div[@class='post item']//section[@class='post-content']//a[contains(@class, 'edited-toggle')]
    Comment    Working around some Selenium limitations here
    Wait Until Element Is Visible    //section[contains(@class, 'original-text')]//p/strong
    Page Should Contain    ${message1}

I can access the original reply text
    [Arguments]    ${message1}    ${message2}
    Wait for injection to be finished
    Click Link
    ...    xpath=//div[@id='activity-stream']//div[@class='comment']//section[@class='comment-content']//a[contains(@class, 'edited-toggle')]
    Comment    Working around some Selenium limitations here
    Wait Until Element Is Visible    //section[contains(@class, 'original-text')]//p/strong
    Page Should Contain    ${message1}

I freeze the case
    Wait for injection to be finished
    Click link    Freeze case
    Wait for injection to be finished

I unfreeze the case
    Wait for injection to be finished
    Click link    Unfreeze case
    Wait for injection to be finished

I unfreeze the case via the metromap
    Wait for injection to be finished
    Click link    Unfreeze
    Wait for injection to be finished
    Click Button    I am sure, unfreeze now

I see that the workspace is frozen
    Wait Until Page Contains    Frozen

I see that the workspace is not frozen
    Page Should Not Contain    Frozen

# *** search related keywords ***

I can see the site search button
    Wait Until Page Contains Element    css=#global-nav-search input.search

I can search in the site header for ${SEARCH_STRING}
    Wait for injection to be finished
    Input text    css=#global-nav-search input.search    ${SEARCH_STRING}
    Press Keys    css=#global-nav-search input.search    ENTER
    Wait for injection to be finished

I can include archived items
    Wait for injection to be finished
    Select Checkbox    css=input[type="checkbox"][name="include_archived"]
    Wait for injection to be finished

I can see the search result ${SEARCH_RESULT_TITLE}
    Wait For Condition    return jQuery && jQuery.active == 0
    Wait Until Element Is visible    xpath=//div[@id='results']//*[normalize-space()='${SEARCH_RESULT_TITLE}']

I can see the fuzzy search result ${SEARCH_RESULT_TITLE}
    Wait For Condition    return jQuery && jQuery.active == 0
    Wait Until Element Is visible    xpath=//div[@id='results']//*[contains(text(), '${SEARCH_RESULT_TITLE}')]

I cannot see the search result ${SEARCH_RESULT_TITLE}
    Wait for injection to be finished
    Element should not be visible    xpath=//div[@id='results']//*[normalize-space()='${SEARCH_RESULT_TITLE}']

I cannot see any search result
    Element should not be visible    css=dl#result-listing dt

I can follow the search result ${SEARCH_RESULT_TITLE}
    Click Link    jquery=.results a:contains("${SEARCH_RESULT_TITLE}")
    Page should contain    ${SEARCH_RESULT_TITLE}

I can filter content of type ${CONTENT_TYPE}
    [Documentation]    We remove the classes we will look at to see if the injection is completed
    Execute Javascript    jQuery('.previews-on,.previews-off').removeClass('previews-on').removeClass('previews-off')
    Wait Until Element is Visible    jquery=#filters .document-types label:contains("${CONTENT_TYPE}")
    Click Element    jquery=#filters .document-types label:contains("${CONTENT_TYPE}")
    Wait Until Element is Visible    css=.previews-on,.previews-off

I can unfilter content of type ${CONTENT_TYPE}
    [Documentation]    We remove the classes we will look at to see if the injection is completed
    Execute Javascript    jQuery('.previews-on,.previews-off').removeClass('previews-on').removeClass('previews-off')
    Unselect Checkbox    css=input[type="checkbox"][value="${CONTENT_TYPE}"]
    Wait Until Element is Visible    css=.previews-on,.previews-off

The search results do not contain ${STRING_IN_SEARCH_RESULTS}
    Wait Until Keyword Succeeds    1    3    Page should not contain    ${STRING_IN_SEARCH_RESULTS}

I can set the date range to ${START_DATE} ${END_DATE}
    Wait until page contains element    jquery=#results .filters input[name=start_date]
    Input date into date picker    '#results .filters input[name=start_date]'    ${START_DATE}
    Input date into date picker    '#results .filters input[name=end_date]'    ${END_DATE}
    # Click into the search field again to remove focus from the date fields
    Click element    css=input[name='SearchableText']
    Wait Until Element is Visible    css=dl.search-results[data-search-string*="start_date=${START_DATE}"]
    Wait Until Element is Visible    css=dl.search-results[data-search-string*="end_date=${END_DATE}"]

I toggle the search previews
    [Documentation]    We remove the classes we will look at to see if the injection is completed
    Click Element    css=[href="#view-options"]
    Wait Until Element is Visible    jquery=.tooltip-container label:contains("Display previews")
    Execute Javascript    jQuery('.previews-on,.previews-off').removeClass('previews-on').removeClass('previews-off')
    Click Element    jquery=.tooltip-container label:contains("Display previews")
    Wait Until Element is Visible    css=.previews-on,.previews-off

I can see the search result previews
    Wait Until Element is Visible    css=.previews-on .preview

I cannot see the search result previews
    Wait Until Element is Visible    css=.previews-off

I can see that the first search result is ${RESULT_TITLE}
    Wait Until Element is Visible    jquery=.search-results > :first-child > a:contains(${RESULT_TITLE})

I can sort search results by ${FIELD}
    [Documentation]    We remove the classes we will look at to see if the injection is completed
    Click Element    css=[href="#view-options"]
    Wait Until Element is Visible    jquery=.tooltip-container label:contains("Sort by ${FIELD}")
    Execute Javascript    jQuery('.previews-on,.previews-off').removeClass('previews-on').removeClass('previews-off')
    Click Element    jquery=.tooltip-container label:contains("Sort by ${FIELD}")
    Wait Until Element is Visible    css=.previews-on,.previews-off

I can click the ${TAB_NAME} tab
    Sleep    1
    Wait until element is visible    jquery=#portal-tabs a:contains(${TAB_NAME})
    Click link    jquery=#portal-tabs a:contains(${TAB_NAME})
    Wait for injection to be finished

I can click the search tab ${TAB_NAME}
    Wait until element is visible    jquery=nav > a:contains(${TAB_NAME})
    Click link    jquery=nav > a:contains(${TAB_NAME})
    Wait for injection to be finished

# *** END search related keywords ***

# *** bookmark related keywords ***

I can bookmark the application
    [Arguments]    ${application}
    I can click the Apps tab
    Click element    xpath=//*[contains(text(),'${application}')]/../../../a[contains(text(), 'Bookmark')]
    Close notification
    I can click the Apps tab
    Page should contain element
    ...    xpath=//*[contains(text(),'${application}')]/../../../a[contains(text(), 'Remove bookmark')]

I can unbookmark the application
    [Arguments]    ${application}
    I can click the Apps tab
    Click element    xpath=//*[contains(text(),'${application}')]/../../../a[contains(text(), 'Remove bookmark')]
    Close notification
    I can click the Apps tab
    Page should contain element
    ...    xpath=//*[contains(text(),'${application}')]/../../../a[contains(text(), 'Bookmark')]

I can bookmark the workspace
    [Arguments]    ${workspace}
    I can click the Workspaces tab
    Click element    xpath=//h3[contains(text(),'${workspace}')]/../../a[contains(text(), 'Bookmark')]
    Wait for injection to be finished
    I can click the Workspaces tab
    Page should contain element
    ...    xpath=//h3[contains(text(), '${workspace}')]/../../a[contains(text(), 'Remove bookmark')]

I can unbookmark the workspace
    [Arguments]    ${workspace}
    I can click the Workspaces tab
    Click element    xpath=//h3[contains(text(),'${workspace}')]/../../a[contains(text(), 'Remove bookmark')]
    Wait for injection to be finished
    I can click the Workspaces tab
    Page should contain element    xpath=//h3[contains(text(), '${workspace}')]/../../a[contains(text(), 'Bookmark')]

Bookmark the current context
    Wait Until Element Is Visible    jquery=.quick-functions .icon-bookmark-empty
    Click Element    jquery=.quick-functions .icon-bookmark-empty
    Close notification
    Wait for injection to be finished
    Page should contain element    jquery=.quick-functions :contains('Remove bookmark')

Unbookmark the current context
    Wait Until Element Is Visible    jquery=.quick-functions .icon-bookmark.active
    Click Element    jquery=.quick-functions .icon-bookmark.active
    Close notification
    Wait for injection to be finished
    Page should contain element    jquery=.quick-functions :contains('Bookmark')

I can bookmark the workspace document
    [Arguments]    ${document}
    I open the sidebar documents tile
    Click Element    xpath=//strong[contains(text(), 'Manage Information')]/..
    Wait for injection to be finished
    Click Element    xpath=//strong[contains(text(), '${document}')]/..
    Wait for injection to be finished
    Bookmark the current context

I can unbookmark the workspace document
    [Arguments]    ${document}
    I open the sidebar documents tile
    Wait for injection to be finished
    Click Element    xpath=//strong[contains(text(), 'Manage Information')]/..
    Wait for injection to be finished
    Click Element    xpath=//strong[contains(text(), '${document}')]/..
    Wait for injection to be finished
    Unbookmark the current context

I can bookmark the task
    [Arguments]    ${task}
    I can go to the Example Case
    I can go to the sidebar tasks tile of my case
    Click link    ${task}
    Wait for injection to be finished
    Bookmark the current context

I can unbookmark the task
    [Arguments]    ${task}
    I can go to the Example Case
    I can go to the sidebar tasks tile of my case
    Click link    ${task}
    Unbookmark the current context

I can go to the profile of
    [Arguments]    ${fullname}
    I open the Dashboard
    Input Text    jquery=#portlet-contacts [name=SearchableText]    ${fullname}
    Wait Until Page Contains Element    jquery=#portlet-contacts .follow .title:contains(${fullname})
    Click Element    jquery=#portlet-contacts .follow .title:contains(${fullname})
    Wait Until Page Contains Element    jquery=.contact-info figcaption:contains(${fullname})

I can bookmark the user
    [Arguments]    ${fullname}
    I can go to the profile of    ${fullname}
    Click Element    css=.icon-bookmark-empty
    Wait Until Page Contains Element    css=.icon-bookmark.active

I can unbookmark the user
    [Documentation]    When using "I can go to the profile of" here then the selector for the search results in the contacts portlet fails if there's a non-ascii character in the name. We use the global search as a workaround.
    [Arguments]    ${fullname}
    Input Text    css=#global-nav-search input.search    ${fullname}
    Press Keys    css=#global-nav-search input.search    ENTER
    Wait Until Page Contains Element
    ...    xpath=//*[@id='search-result']//dt[contains(@class, 'type-people')]//a[contains(text(), '${fullname}')]
    Click Element
    ...    xpath=//*[@id='search-result']//dt[contains(@class, 'type-people')]//a[contains(text(), '${fullname}')]
    Wait Until Page Contains Element    jquery=.contact-info figcaption:contains(${fullname})
    Click Element    css=.icon-bookmark.active
    Wait Until Page Contains Element    css=.icon-bookmark-empty

I can go to the application overview page
    Go To    ${PLONE_URL}/apps
    Wait for injection to be finished

I can go to the application
    [Arguments]    ${name}
    I can go to the application overview page
    Click Element    //*[contains(@class, 'tile app')]/a/img[@alt='${name}']/parent::a
    Wait for injection to be finished

I cannot go to the application
    [Arguments]    ${name}
    I can go to the application overview page
    Page should not contain element    //*[contains(@class, 'tile app')]/a/img[@alt='${name}']

I can filter bookmarked application
    Input text    jquery=.application-bookmarks [name=SearchableText]    bookmark
    Wait for injection to be finished
    Page should contain element    jquery=.bookmark :contains(Bookmark)
    Page should not contain element    jquery=.bookmark :contains(Example Case)

I can filter bookmarked content
    Input text    jquery=.application-bookmarks [name=SearchableText]    example
    Wait for injection to be finished
    Page should contain element    jquery=.bookmark :contains(Example Case)
    Page should not contain element    jquery=.bookmark :contains(Bookmark)

I can see the bookmarked applications
    Click Element    jquery=[href='#directory-apps']
    Wait for injection to be finished
    Page should contain element    css=.tile.app-bookmarks

I can see the bookmarked workspaces
    Click Element    jquery=[href='#directory-workspaces']
    Wait for injection to be finished
    Page should contain element    css=.tile.workspace-example-case

I can see the bookmarked people
    Click Element    jquery=[href='#directory-people']
    Wait for injection to be finished
    Page should contain element    css=.user-cards .user-card

I can see the bookmarked documents
    Click Element    jquery=[href='#directory-documents']
    Wait for injection to be finished
    Page should contain element    jquery=figcaption:contains('Budget Proposal')

I can see bookmark grouped by workspace
    Select From List By Value    group_by    workspace
    Wait for injection to be finished
    # I can see a ws
    Page should contain element
    ...    xpath=//h3[contains(text(), 'Example Case')]/../ul/li/a[contains(text(), 'Example Case')]
    # a document inside it
    Page should contain element
    ...    xpath=//h3[contains(text(), 'Example Case')]/../ul/li/a[contains(text(), 'Draft proposal')]
    # and something unrelated
    Page should contain element
    ...    xpath=//h3[contains(text(), 'Not in a workspace')]/../ul/li/a[contains(text(), 'Bookmark')]

I can see bookmark grouped by creation date
    Select From List By Value    group_by    created
    Wait for injection to be finished
    Page should contain element
    ...    xpath=//h3[contains(text(), 'Last week')]/../ul/li/a[contains(text(), 'Draft proposal')]

I can see the bookmarks tile
    I scroll the Dashboard
    Wait Until Page Contains Element    jquery=.portlet .portlet-title :contains(Bookmarks)

I can query the bookmarks tile for
    [Arguments]    ${query}
    I scroll the Dashboard
    Wait Until Page Contains Element    jquery=#portlet-bookmarks [name=SearchableText]
    Input Text    jquery=#portlet-bookmarks [name=SearchableText]    ${query}
    Press Keys    jquery=#portlet-bookmarks [name=SearchableText]    ENTER
    Wait for injection to be finished

I click the contacts portlet tab
    [Arguments]    ${title}
    Click Element    jquery=#portlet-contacts .tabs a:contains('${title}')
    Wait for injection to be finished

I Scroll to the Bookmarks portlet
    # First go to the portlet-bookmarks element, this should trigger the injection of the portlet
    Run Keyword And Ignore Error    Scroll element into view    jquery=#portlet-bookmarks
    Wait for injection to be finished
    # Now scroll down to the tabs
    Run Keyword And Ignore Error    Scroll element into view    jquery=#portlet-bookmarks .tabs
    Press Keys    css=body    ARROW_DOWN

I click the bookmarks portlet tab
    [Arguments]    ${title}
    I Scroll to the Bookmarks portlet
    Wait until element is visible    jquery=#portlet-bookmarks .tabs a:contains('${title}')
    Wait Until Keyword Succeeds
    ...    10x
    ...    100ms
    ...    Click Element
    ...    jquery=#portlet-bookmarks .tabs a:contains('${title}')
    Wait for injection to be finished

I can see in the bookmark tile that the first bookmark is
    [Arguments]    ${text}
    Element should contain    jquery=#bookmarks-search-items li:first a    ${text}

I can see in the bookmark tile that the last bookmark is
    [Arguments]    ${text}
    Element should contain    jquery=#bookmarks-search-items li:last a    ${text}

I can see in the bookmark tile that we have no bookmarks matching
    [Arguments]    ${text}
    Element should contain    jquery=#bookmarks-search-items .pat-message    No bookmarks were found matching ${text}

# *** END bookmark related keywords ***

# *** mail related keywords ***

I open the email
    Click Link    jquery=a:contains("Files for application 2837")

I can see the email sender
    Page should contain    pilz@pilzen.de

I can see the preview of the
    [Arguments]    ${title}
    Click Element    jquery=.document-preview :contains(${title})
    Wait until page contains element    css=#photoswipe-template
    Wait until element is visible    jquery=.tooltip-container:last .pat-gallery :contains(Preview)
    Click Element    jquery=.tooltip-container:last .pat-gallery :contains(Preview)
    Wait until element is visible    css=.pswp__button--close
    Click Element    css=.pswp__button--close

# *** END mail related keywords ***

# *** calendar related keywords ***

I can go to the calendar application
    I can Click the Apps tab
    Wait for injection to be finished
    Wait until element is visible    css=div.app-calendar
    Click Element    css=div.app-calendar
    Wait for injection to be finished
    Wait until page contains element    css=div.pat-calendar__fc
    Page should contain element    css=button.view-week
    Page should contain element    css=select.timezone

I can accept the shared event
    [Arguments]    ${event_id}=brainstorm-session
    Go To    ${PLONE_URL}/workspaces/open-market-committee/${event_id}/@@redirect_to_accept_decline_link
    Click Button    Accept
    Wait for injection to be finished
    Wait Until Page Contains Element    css=div.event-details

I cannot accept the shared event
    [Arguments]    ${event_id}=brainstorm-session
    Go To    ${PLONE_URL}/workspaces/open-market-committee/${event_id}/@@redirect_to_accept_decline_link
    Page Should Not Contain Button    Accept
    Page Should Not Contain Button    Decline

# *** END calendar related keywords ***

Select from pat-select
    # See https://github.com/quaive/ploneintranet/issues/1800
    [Arguments]    ${name}    ${title}
    Select From List By Label    ${name}    ${title}
    Click Element    jquery=.pat-select:has([name="${name}"])
