001/*
002 * (C) Copyright 2016 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 *     Mariana Cedica
018 *     Yannis JULIENNE
019 */
020package org.nuxeo.functionaltests.pages.tabs;
021
022/**
023 * @since 5.7
024 */
025import java.text.DateFormat;
026import java.util.Date;
027import java.util.Locale;
028
029import org.junit.Assert;
030import org.nuxeo.functionaltests.AjaxRequestManager;
031import org.nuxeo.functionaltests.Locator;
032import org.nuxeo.functionaltests.forms.Select2WidgetElement;
033import org.nuxeo.functionaltests.pages.AbstractPage;
034import org.nuxeo.functionaltests.pages.DocumentBasePage;
035import org.openqa.selenium.By;
036import org.openqa.selenium.WebDriver;
037import org.openqa.selenium.WebElement;
038import org.openqa.selenium.support.FindBy;
039
040public class WorkflowTabSubPage extends DocumentBasePage {
041
042    @FindBy(xpath = "//form[contains(@id, 'nxl_tasks_form')]")
043    public WebElement workflowTasksForm;
044
045    @FindBy(xpath = "//select[contains(@id, 'nxw_validationOrReview')]")
046    public WebElement reviewSelector;
047
048    public WorkflowTabSubPage(WebDriver driver) {
049        super(driver);
050    }
051
052    /**
053     * Add reviewer in default serial workflow
054     */
055    public void addWorkflowReviewer(final String username) {
056        Select2WidgetElement particpants = new Select2WidgetElement(driver,
057                driver.findElement(By.xpath("//div[contains(@id, 'nxw_participants_select2')]")), true);
058        particpants.selectValue(username);
059        selectItemInDropDownMenu(reviewSelector, "Simple Review");
060    }
061
062    /**
063     * Add reviewer in default parallel workflow
064     *
065     * @since 5.9.1
066     */
067    public void addParallelWorkflowReviewer(String user) {
068        Select2WidgetElement particpants = new Select2WidgetElement(driver,
069                driver.findElement(By.xpath("//div[contains(@id, 'nxw_participants_select2')]")), true);
070        particpants.selectValue(user);
071    }
072
073    /**
074     * @since 5.9.1
075     */
076    public void addParallelWorkflowEndDate() {
077        DateFormat sdf = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
078        WebElement endDate = driver.findElement((By.xpath("//input[contains(@id, 'nxw_end_dateInputDate')]")));
079        endDate.sendKeys(sdf.format(new Date()));
080        // validate input date
081        Assert.assertTrue(endDate.getAttribute("value").equals(sdf.format(new Date())));
082    }
083
084    public void showGraphView() {
085        AjaxRequestManager arm = new AjaxRequestManager(driver);
086        arm.begin();
087        findElementWaitUntilEnabledAndClick(By.linkText("Show Graph View"));
088        arm.end();
089        // wait for load
090        AbstractPage.getFancyBoxContent();
091        Locator.waitUntilElementPresent(By.id("fancybox-close"));
092        // wait for graph to be loaded to avoid js errors when closing the fancybox too early
093        Locator.waitUntilElementPresent(By.id("jsPlumb_1_6"));
094    }
095
096    public void closeGraphView() {
097        AbstractPage.closeFancyBox();
098    }
099
100    public void startWorkflow() {
101        findElementWaitUntilEnabledAndClick(By.xpath("//input[@value='Start the Review']"));
102    }
103
104    /**
105     * @since 5.9.1
106     */
107    public void endTask(String taskName, String comment) {
108        findElementAndWaitUntilEnabled(By.tagName("textarea")).sendKeys(comment);
109        findElementWaitUntilEnabledAndClick(By.xpath(String.format("//input[@value='%s']", taskName)));
110    }
111
112    public void endTask(String taskName) {
113        findElementWaitUntilEnabledAndClick(By.xpath(String.format("//input[@value='%s']", taskName)));
114    }
115
116    /**
117     * @since 8.3
118     */
119    public <T> T endTask(String taskName, Class<T> pageClassToProxy) {
120        endTask(taskName);
121        return asPage(pageClassToProxy);
122    }
123
124    /**
125     * @since 5.8
126     */
127    public WebElement getTaskLayoutNode() {
128        return findElementWithTimeout(
129                By.xpath("//div[starts-with(@id, 'nxl_current_route_layout:nxw_current_route_user_tasks_panel')]"));
130    }
131
132    @Override
133    public SummaryTabSubPage getSummaryTab() {
134        clickOnDocumentTabLink(summaryTabLink);
135        return asPage(SummaryTabSubPage.class);
136    }
137}