*** Settings ***
Variables           variables.py
Resource            plone/app/robotframework/selenium.robot
Resource            plone/app/robotframework/keywords.robot
Resource            ../lib/keywords.robot
Library             Remote    ${PLONE_URL}/RobotRemote
Library             DebugLibrary

Test Setup          Prepare test browser
Test Teardown       Close all browsers
# Suite Setup    Set Selenium speed    0.5s


*** Test Cases ***
# The case that a user created outside our local membrane context should be
# able to create a workspace is not supported. Deactivating this test.
# Manager can create a workspace
#    Given I am logged in as the user admin
#    Then I can create a new workspace    My new workspace

Alice can create a workspace
    Given I am logged in as the user alice_lindstrom
    Then I can create a new workspace    My user workspace

Alice can create a superspace
    Given I am logged in as the user alice_lindstrom
    Then I can create a new superspace    My user superspace

User can create a workspace template
    Given I am logged in as the user allan_neece
    Then I can create a new template workspace    New template
    Then I can create a new workspace from a template    New template    A new type of workspace
    Then I can delete a template case    new-template
    Then I can delete a case    a-new-type-of-workspace

Manager can define a subspace
    Given I am logged in as the user christian_stoney
    Then I can go to the Open Market Committee Workspace
    And I can set the superspace    Lounge renovations
    Then Go to    ${PLONE_URL}/workspaces
    When I open the superspace tile    Lounge activities
    And I open the superspace tile    Lounge renovations
    And I enter the double nested subspace    Open Market Committee
    Then I can set the superspace    No super space
    When Go to    ${PLONE_URL}/workspaces
    Then I can see the listed workspace    Open Market Committee

Alice can list workspaces sorted
    Given I am logged in as the user alice_lindstrom
    And I can create a new workspace    Zulu
    And Go to    ${PLONE_URL}/workspaces
    And I can see the last listed workspace is    Zulu
    And I can set workspace listing order    Newest workspaces on top
    And I can see the first listed workspace is    Zulu
    And Go to    ${PLONE_URL}/workspaces
    And I can see the first listed workspace is    Zulu
    And I can set workspace listing order    Alphabetical
    And I can see the last listed workspace is    Zulu
    And Go to    ${PLONE_URL}/workspaces
    And I can see the last listed workspace is    Zulu

Dollie can see only her workspaces
    Given I am logged in as the user dollie_nocera
    And Go to    ${PLONE_URL}/workspaces
    Then I can see the last listed workspace is    Shareholder information
    When I Click only my workspaces
    Then I can see the last listed workspace is    Open Market Committee

Dollie can request access to a secret workspace
    Given I am logged in as the user dollie_nocera
    Then I can file a request access for the workspace    Shareholder information

Christian can deny a request to access a workspace
    Given I am logged in as the user christian_stoney
    Then I can decline the request access of    dollie_nocera

Christian can accept a request to access a workspace
    Given I am logged in as the user christian_stoney
    Then I can accept the request access of    dollie_nocera

Alice can create a division and list workspaces by division
    Given I am logged in as the user alice_lindstrom
    And I can create a new workspace    Aerospace
    And I browse to the workspace    Aerospace
    And I can open the workspace advanced settings tab
    When I can turn the workspace into a division
    And I can list the workspaces grouped by division
    Then I can see the division    Aerospace

Alice can tag a workspace and group workspaces by tag and filter workspaces by tag
    Given I am logged in as the user alice_lindstrom
    And I can create a new workspace    ReadCarefullyWS
    And I browse to the workspace    ReadCarefullyWS
    And I can open the workspace advanced settings tab
    When I can tag the workspace as    Read carefully,Important
    Then I can see the tag in the workspace header    Read carefully
    And I can list the workspaces grouped by tags
    Then I can see the tag    Read carefully
    And I can see the tag group    Read carefully
    And I can see the workspace grouped under tag    ReadCarefullyWS    Read carefully
    And I can see the workspace grouped under tag    ReadCarefullyWS    Important
    And I can filter workspaces by tag    Read carefully    Service announcements

Alice can create a division and create a workspace for the division
    Given I am logged in as the user alice_lindstrom
    And I can create a new workspace    Aerospace
    And I browse to the workspace    Aerospace
    And I can open the workspace advanced settings tab
    When I can turn the workspace into a division
    Then I can create a new workspace for the division    Engines    Aerospace
    And I browse to the workspace    Engines
    And I can open the workspace advanced settings tab
    And I can see the workspace belongs to division    Aerospace

Non-member cannot see into a workspace
    Given I am logged in as the user alice_lindstrom
    when I can go to the Open Market Committee Workspace
    then I do not have sufficient privileges

Breadcrumbs are not borked
    Given I am in a workspace as a workspace member
    And I am in a workspace as a workspace member
    Then the breadcrumbs show the name of the workspace

Member can access a user profile from sidebar and follow the user
    Given I am in a workspace as a workspace member
    And I can open the workspace member settings tab
    Then I can open Esmeralda's profile
    And I can follow Esmeralda

Member can view sidebar events
    Given I am in a workspace as a workspace member
    Then I can go to the sidebar events tile
    And I can see upcoming events
    Older events are hidden

# The following tests are commented out, since we currently have no concept
# for adding tasks in a workspace. Relying on globally available tasks (the
# reason why these tests used to be passing) is not valid.

Manager can add a task for Allan and Allan can modify it
    Given I am in a workspace as a workspace admin
    Then I create a task for    Allan
    Go to    ${PLONE_URL}/logout
    When I am logged in as the user allan_neece
    Then Task is editable for user    Allan

# Manager can view sidebar tasks
#    Given I am in a workspace as a workspace admin
#    Then I can go to the sidebar tasks tile

# Member can view sidebar tasks
#    Given I am in a workspace as a workspace member
#    Then I can go to the sidebar tasks tile

Traverse Folder in sidebar navigation
    Given I am in a workspace as a workspace member
    Then I can enter the Manage Information Folder
    And Go back to the workspace by clicking the parent button

Search for objects in sidebar navigation
    Given I am in a workspace as a workspace member
    And I open the sidebar documents tile
    Then I can search for items

I can see only my objects in sidebar navigation
    Given I am in a workspace as a workspace member
    Then I can enter the Manage Information Folder
    Then I can create a new document    This is personal
    Then I can show only my documents
    And I can see that the only item displayed in the navigation is    This is personal

The manager can modify workspace security policies
    Given I am in a workspace as a workspace admin
    Then I can open the workspace security settings tab
    And I can set the external visibility to Open
    And I can set the join policy to Admin-Managed
    And I can set the participant policy to Moderate

The manager can modify workspace security policies by clicking on the workspace header icon
    Given I am in a workspace as a workspace admin
    Then I can click the security icon in the header
    And I can set the external visibility to Open

The manager can access member batch-functions only after selecting
    Given I am in a workspace as a workspace admin
    Then I can open the workspace member settings tab
    Then I can enable user selection
    And The batch action buttons are disabled
    Then I select all members
    And The batch action buttons are enabled
    Then I deselect all members
    And The batch action buttons are disabled
    Then I toggle the selection of the first user
    And The batch action buttons are enabled
    Then I toggle the selection of the first user
    And The batch action buttons are disabled

The manager can invite Alice to join the Open Market Committee Workspace from the menu
    Given I am in a workspace as a workspace admin
    And I can open the workspace member settings tab
    Then I can invite Alice to join the workspace from the menu

Member can see document title
    Given I am in a workspace as a workspace member
    And I view a document
    When I open the metadata panel
    Then I see the document title    Minutes

Document title is visible on editable rich-text item
    Given I am in a workspace as a workspace member
    And I view a rich-text document
    When I open the metadata panel
    Then I see the document title    Minutes Overview

Document title is visible on read-only rich-text item
    Given I am logged in as the user guy_hackey
    And I go to the Open Market Committee Workspace
    And I view a rich-text document
    When I open the metadata panel
    Then I see the document title    Public bodies reform
    And I cannot edit the document title

Create trash and delete a document
    Given I am in a workspace as a workspace member
    Then I can create a new document    My Humble document
    Given I trash through the sidebar    My Humble document
    Then I can see in the trash bin    My Humble document
    Given I can untrash this document
    And I trash through the sidebar    My Humble document
    Then The workspace admin can empty the trash

Member can copy and paste a document
    Given I am in a workspace as a workspace member
    Then I can enter the Manage Information Folder
    And I can create a new document    My Humble document
    Then I copy through the sidebar    My Humble document
    And I can paste my clipboard contents

Manager can cut and paste a document
    Given I am in a workspace as a workspace admin
    Then I can enter the Manage Information Folder
    And I can create a new document    My Humble document
    Then I cut through the sidebar    My Humble document
    And I can paste my clipboard contents

Member cannot cut item in a publish workspace
    Given I am logged in as the user allan_neece
    when I can go to the Open Market Committee Workspace
    And I open the sidebar documents tile
    And I can create a new document    Allan has a new document
    Then the cut action in the sidebar is not available for    Allan has a new document

Manager can rename a document
    Given I am in a workspace as a workspace admin
    And I can create a new document    My Humble document
    And I Open The Sidebar Documents Tile
    And I open the sidebar context menu for    My Humble document
    When I set the new title through the already open context menu    Divina Commedia
    And I open the metadata panel
    Then I see the document title    Divina Commedia

Member can create and edit a folder
    Given I am in a workspace as a workspace member
    Then I can create a new folder
    Then I can edit the new folder

Create image
    Given I am in a workspace as a workspace member
    Then I can create a new image

# https://github.com/quaive/ploneintranet/issues/521

Create structure
    Given I am in a workspace as a workspace member
    Then I can create a structure

Member can upload a file
    Given I am in a workspace as a workspace member
    And I open the sidebar documents tile
    And I select a file to upload
    Then the file appears in the sidebar

Member can upload and autotag file
    Given I am in a workspace as a workspace member
    And I list the documents with the tag    Read carefully
    And I select a file to upload
    Then the file appears in the sidebar

Member can submit a document
    Given I am in a workspace as a workspace member
    When I can create a new document    My awesome document
    Then I can edit the document
    When I submit the content item
    Then I cannot edit the document

Member can create an event
    Given I am in a workspace as a workspace member
    When I can create a new event    Christmas    2014-12-25    2014-12-26
    Then I can edit an event    2120-12-25    2121-12-26    Europe/Rome    Allan Neece    Dollie Nocera
# Owners cannot delete events, in sync with other content objects.

Member can create a link
    Given I am in a workspace as a workspace admin
    Then I can create a new link    Quaive site    https://quaive.com
    Then I can edit the link    Quaive site    https://quaive.net/foo/bar
    And I can publish the new link    Quaive site
    When I am logged in as the user allan_neece
    Then I go to the Open Market Committee Workspace
    And I can see the link    Quaive site    https://quaive.net/foo/bar

Member cannot create an event with invalid dates
    Given I am in a workspace as a workspace member
    When I cannot create a new event    Invalid dates    2014-12-25    2010-12-22

Member cannot edit an event with invalid data
    Given I am in a workspace as a workspace member
    When I can create a new event    Easter    2014-12-25    2014-12-26
    Then I cannot edit an event because of validation    Easter    2121-12-25    2120-12-26    Europe/Rome

Member can share an event to a central calendar
    Given I am logged in as the user allan_neece
    And I go to the Open Market Committee Workspace
    Then I can create a new event for today    Policy Meeting
    And I cannot share the event to a central calendar    HR Events
    And I can share the event to a central calendar    Website Events
    When I can go to the application overview page
    And I can go to the calendar application
    Then I see the event as part of a central calendar    Policy Meeting
    And I see the central calendar in the sidebar    Website Events
    Given I am logged in as the user alice_lindstrom
    And I can go to the calendar application
    Then I see the event as part of a central calendar    Policy Meeting
    And I see the central calendar in the sidebar    Website Events

Calendar maintainer can accept a shared event
    Given I am logged in as the user allan_neece
    And I go to the Open Market Committee Workspace
    Then I can create a new event for today    Kickoff Meeting
    And I can share the event to a central calendar    Company Outings
    Given I am logged in as the user dollie_nocera
    Then I can accept the shared event    event_id=kickoff-meeting
    When I can go to the application overview page
    When I can go to the calendar application
    Then I see the event as part of a central calendar    Kickoff Meeting
    And I see the central calendar in the sidebar    Company Outings
    [Teardown]    Delete Event    Kickoff Meeting

Calendar owner can accept a shared event
    Given I am logged in as the user guy_hackey
    And I go to the Open Market Committee Workspace
    Then I can create a new event for today    Brainstorm Session
    And I can share the event to a central calendar    HR Events
    Given I am logged in as the user christian_stoney
    Then I can accept the shared event
    When I can go to the application overview page
    When I can go to the calendar application
    Then I see the event as part of a central calendar    Brainstorm Session
    And I see the central calendar in the sidebar    HR Events
    [Teardown]    Delete Event    Brainstorm Session

Event owner cannot accept a shared event
    Given I am logged in as the user guy_hackey
    And I go to the Open Market Committee Workspace
    Then I can create a new event for today    Management Workshop
    And I can share the event to a central calendar    HR Events
    Then I cannot accept the shared event    event_id=management-workshop
    [Teardown]    Delete Event    Management Workshop

Workspace member cannot accept a shared event
    Given I am logged in as the user guy_hackey
    And I go to the Open Market Committee Workspace
    Then I can create a new event for today    Personnel Workshop
    And I can share the event to a central calendar    HR Events
    Given I am logged in as the user dollie_nocera
    Then I cannot accept the shared event    event_id=personnel-workshop
    [Teardown]    Delete Event    Personnel Workshop

Workspace admin can modify the event agenda items
    Given I am logged in as the user christian_stoney
    And I go to the Open Market Committee Workspace
    Then I can go to the sidebar events tile
    And I open the sidebar event    Open Market Day
    And I see in the event agenda a link to    Repurchase Agreements
    Then I add to the event agenda the item    This is important!
    When I remove from the event agenda the last item
    Then I see that the last event agenda item is    Epilogue and final greetings

Member can submit and retract a document
    Given I am in a workspace as a workspace member
    When I can create a new document    My substandard document
    Then I can edit the document
    When I submit the content item
    Then I cannot edit the document
    When I retract the content item
    Then I can edit the document

Member can publish a document in a Publishers workspace
    Given I am in a workspace as a workspace member
    When I can create a new document    My publishing document
    When I submit the content item
    Then I can publish the content item

Member cannot publish a document in a Producers workspace
    Given I am in a Producers workspace as a workspace member
    When I can create a new document    My non-publishing document
    When I Click the Workflow Submit Button
    Then I cannot publish the content item

Member can publish a file in a Publishers workspace
    Given I am in a workspace as a workspace member
    And I open the sidebar documents tile
    And I browse to a file
    Then I submit the content item
    And I can publish the content item
    And I retract the content item

Member cannot create content in a Consumers workspace
    Given I am in a Consumers workspace as a workspace member
    Then I cannot create a new document

Member cannot create content in a workspace changed from Produce to Consume
    Given I am logged in as the user christian_stoney
    And I go to the Open Parliamentary Papers Guidance Workspace
    Then I can open the workspace security settings tab
    And I can set the participant policy to Consume
    When I am logged in as the user allan_neece
    And I go to the Open Parliamentary Papers Guidance Workspace
    Then I cannot create a new document

Non-Member can view published content in an open workspace
    Given I am in an open workspace as a non-member
    Then I can see the document    Terms and conditions
    And I cannot see the document    Customer satisfaction survey

Member can download the pdf version of a document
    Given I am in a workspace as a workspace member
    Then I can open the documents tab
    Then Maneuver to    Manage Information
    Then Maneuver to    Minutes
    And I open the sharing menu
    Then The menu contains the link to download the PDF

Member can see an email
    Given I am logged in as the user admin
    And I go to the Open Market Committee Workspace
    And I open the sidebar documents tile
    And I open the email
    Then I can see the email sender
    And I can see the preview of the    Minutes

Site Administrator can add example user as member of workspace
    Given I am logged in as the user admin
    Add workspace    Example Workspace
    And I can add a new member    Alice

The manager can grant the Producer role in a Consumer workspace
    Given I am in a Consumers workspace as a workspace admin
    And I give the Producer role to Allan
    When I am in a Consumers workspace as a workspace member
    Then I open the create document panel

The manager can grant the Consumer role in a Producer workspace
    Given I am in a Producers workspace as a workspace admin
    And I give the Consumer role to Allan
    When I am in a Producers workspace as a workspace member
    Then I cannot create a new document

The manager can remove a special role from a workspace member
    Given I am in a Consumers workspace as a workspace admin
    And I give the Producer role to Allan
    When I am in a Consumers workspace as a workspace admin
    Then I can remove the Producer role from Allan

The manager can change a special role
    Given I am in a Consumers workspace as a workspace admin
    And I give the Producer role to Allan
    Then I can change Allan's role to Moderator

The manager can add other workspace admins
    Given I am in a Consumers workspace as a workspace admin
    Then I give the Admin role to Allan

The manager can remove a workspace member
    Given I am in a workspace as a workspace admin
    Then I can remove allan_neece from the workspace members

The manager can archive a workspace
    Given I am logged in as the user christian_stoney
    And I can create a new workspace    Archived Workspace
    And I browse to the workspace    Archived Workspace
    And I can open the workspace advanced settings tab
    When I can archive the workspace
    And I can list the workspaces
    And I can't see the workspace    Archived Workspace
    And I can list the archived workspaces
    And I can see the workspace    Archived Workspace
    When I go to the Archived Workspace
    And I can open the workspace advanced settings tab
    And I can unarchive the workspace
    And I can list the workspaces
    Then I can see the workspace    Archived Workspace

Archived workspaces are marked in search results
    Given I am in a workspace as a workspace admin
    And I can create a new workspace    ArchivedWSSearch
    And I browse to the workspace    ArchivedWSSearch
    And I can open the workspace advanced settings tab
    And I can archive the workspace
    Then I can list the workspaces
    And I can search in the site header for ArchivedWSSearch
    And I cannot see the search result ArchivedWSSearch
    Then I can include archived items
    And I can see the fuzzy search result ArchivedWSSearch
    Then I can see that the workspace is archived    ArchivedWSSearch

User can archive a workspace document
    Given I am logged in as the user christian_stoney
    And I Go To the Terms and Conditions document
    Then I can archive the current context
    Then I can unarchive the current context

A secret workspace is accessible only to members
    Given I am logged in as the user alice_lindstrom
    Then I can create a new secret workspace    My secret workspace
    And I browse to the workspace    My secret workspace
    And I can create a new document    My secret document
    When I am logged in as the user allan_neece
    And I can search in the site header for My secret document
    Then the search results do not contain my-secret-workspace/my-secret-document
    And I cannot access the document    my-secret-workspace/my-secret-document

Owner gets properly removed when user leaves workspace
    Given I am logged in as the user pearlie_whitby
    And I can create a new secret workspace    My own private workspace
    And I browse to the workspace    My own private workspace
    And I can create a new document    My secret document
    # Browse to WS again, so that the member selection works
    Then I browse to the workspace    My own private workspace
    And I can add a new member    Allan
    And I give the Admin role to Allan
    Then I am logged in as the user allan_neece
    And I browse to the workspace    My own private workspace
    And I can remove pearlie_whitby from the workspace members
    When I am logged in as the user pearlie_whitby
    And I can search in the site header for My secret document
    Then the search results do not contain my-own-private-workspace/my-secret-document
    And I cannot access the document    my-own-private-workspace/my-secret-document


*** Keywords ***
Delete Event
    [Arguments]    ${title}
    Given I am logged in as the user christian_stoney
    And I go to the Open Market Committee Workspace
    Then I can delete an event    ${title}
    And Close all browsers

# See lib/keywords.robot in the section "workspace related keywords"
