001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Sun Seng David TAN <stan@nuxeo.com>
018 */
019package org.nuxeo.functionaltests.pages.tabs;
020
021import java.util.ArrayList;
022import java.util.List;
023
024import org.nuxeo.functionaltests.AjaxRequestManager;
025import org.nuxeo.functionaltests.pages.AbstractPage;
026import org.openqa.selenium.By;
027import org.openqa.selenium.NoSuchElementException;
028import org.openqa.selenium.WebDriver;
029import org.openqa.selenium.WebElement;
030import org.openqa.selenium.support.FindBy;
031
032/**
033 * @author Sun Seng David TAN <stan@nuxeo.com>
034 */
035public class SummaryTabSubPage extends AbstractPage {
036
037    private static final String COLLECTIONS_FORM_ID = "nxl_grid_summary_layout:nxw_summary_current_document_collections_form";
038
039    public static final String WORKFLOW_START_BUTTON_XPATH = "//input[contains(@id, 'nxw_start_route_widget_start_route')]";
040
041    public static final String WORKFLOW_SELECTOR_XPATH = "//select[contains(@id, 'nxw_start_route_widget')]";
042
043    @FindBy(xpath = WORKFLOW_START_BUTTON_XPATH)
044    public WebElement startWorkflowBtn;
045
046    @FindBy(xpath = WORKFLOW_SELECTOR_XPATH)
047    public WebElement workflowSelector;
048
049    @FindBy(xpath = "//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_current_document_single_tasks')]")
050    public WebElement workflowTasksForm;
051
052    @FindBy(xpath = "//div[@class='nxw_lastContributor']")
053    public WebElement lastContributor;
054
055    @FindBy(xpath = "//div[@class='nxw_author']")
056    public WebElement creator;
057
058    @FindBy(xpath = "//span[@id='nxl_grid_summary_layout:nxw_summary_current_document_dublincore_form:nxl_dublincore:nxw_created']")
059    public WebElement createdAt;
060
061    @FindBy(xpath = "//span[@id='nxl_grid_summary_layout:nxw_summary_current_document_dublincore_form:nxl_dublincore:nxw_modified']")
062    public WebElement lastModifiedAt;
063
064    @FindBy(xpath = "//span[@class[starts-with(.,'nxw_contributors_')]]")
065    public List<WebElement> contributors;
066
067    @FindBy(xpath = "//form[@id='nxl_grid_summary_layout:nxw_summary_current_document_states_form']")
068    public WebElement lifeCycleState;
069
070    public SummaryTabSubPage(WebDriver driver) {
071        super(driver);
072    }
073
074    public void startDefaultWorkflow() {
075        AjaxRequestManager a = new AjaxRequestManager(driver);
076        a.watchAjaxRequests();
077        selectItemInDropDownMenu(workflowSelector, "Serial document review");
078        a.waitForAjaxRequests();
079        startWorkflowBtn.click();
080    }
081
082    public void startDefaultParallelWorkflow() {
083        selectItemInDropDownMenu(workflowSelector, "Parallel document review");
084
085        startWorkflowBtn.click();
086    }
087
088    public boolean workflowAlreadyStarted() {
089        return findElementWithTimeout(By.xpath("//*[@id='nxl_grid_summary_layout:nxw_summary_document_route_form']")).getText().contains(
090                "review has been started");
091    }
092
093    public boolean openTaskForCurrentUser() {
094        return findElementWithTimeout(
095                By.xpath("//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_current_document_single_tasks')]")).getText().contains(
096                "Please accept or reject the document");
097    }
098
099    /**
100     * @since 5.8
101     */
102    public boolean parallelOpenTaskForCurrentUser() {
103        return findElementWithTimeout(
104                By.xpath("//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_current_document_single_tasks')]")).getText().contains(
105                "Please give your opinion. Click on N/A if you have no advice.");
106    }
107
108    public WorkflowTabSubPage getWorkflow() {
109        clickOnTabIfNotSelected("nxw_documentTabs_panel", "nxw_TAB_ROUTE_WORKFLOW");
110        return asPage(WorkflowTabSubPage.class);
111    }
112
113    public boolean cantStartWorkflow() {
114        return findElementWithTimeout(
115                By.xpath("//form[contains(@id, 'nxl_grid_summary_layout:nxw_summary_document_route_form')]")).getText().contains(
116                "No workflow process can be started on this document.");
117    }
118
119    /**
120     * Get the creator of the doc.
121     *
122     * @since 5.8
123     */
124    public String getCreator() {
125        return creator.getText();
126    }
127
128    /**
129     * Get the last contributor of the doc.
130     *
131     * @since 5.8
132     */
133    public String getLastContributor() {
134        return lastContributor.getText();
135    }
136
137    /**
138     * Get the list of contributors of the doc.
139     *
140     * @since 5.8
141     */
142    public List<String> getContributors() {
143        List<String> result = new ArrayList<String>();
144        for (WebElement contributor : contributors) {
145            result.add(contributor.getText());
146        }
147        return result;
148    }
149
150    /**
151     * @since 5.8
152     */
153    public String getCurrentLifeCycleState() {
154        return lifeCycleState.findElement(By.className("sticker")).getText();
155    }
156
157    /**
158     * @since 5.9.3
159     */
160    public boolean isCollectionsFormDisplayed() {
161        try {
162            driver.findElement(By.id(COLLECTIONS_FORM_ID));
163            return true;
164        } catch (NoSuchElementException e) {
165            return false;
166        }
167    }
168
169    /**
170     * @since 5.9.3
171     */
172    public int getCollectionCount() {
173        return driver.findElement(By.id(COLLECTIONS_FORM_ID)).findElements(
174                By.xpath("div/span[@id='nxl_grid_summary_layout:nxw_summary_current_document_collections_form:collections']/span[@class='tag tagLink']")).size();
175    }
176}