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    }
093
094    public void closeGraphView() {
095        AbstractPage.closeFancyBox();
096    }
097
098    public void startWorkflow() {
099        findElementWaitUntilEnabledAndClick(By.xpath("//input[@value='Start the Review']"));
100    }
101
102    /**
103     * @since 5.9.1
104     */
105    public void endTask(String taskName, String comment) {
106        findElementAndWaitUntilEnabled(By.tagName("textarea")).sendKeys(comment);
107        findElementWaitUntilEnabledAndClick(By.xpath(String.format("//input[@value='%s']", taskName)));
108    }
109
110    public void endTask(String taskName) {
111        findElementWaitUntilEnabledAndClick(By.xpath(String.format("//input[@value='%s']", taskName)));
112    }
113
114    /**
115     * @since 8.3
116     */
117    public <T> T endTask(String taskName, Class<T> pageClassToProxy) {
118        endTask(taskName);
119        return asPage(pageClassToProxy);
120    }
121
122    /**
123     * @since 5.8
124     */
125    public WebElement getTaskLayoutNode() {
126        return findElementWithTimeout(
127                By.xpath("//div[starts-with(@id, 'nxl_current_route_layout:nxw_current_route_user_tasks_panel')]"));
128    }
129
130    @Override
131    public SummaryTabSubPage getSummaryTab() {
132        clickOnDocumentTabLink(summaryTabLink);
133        return asPage(SummaryTabSubPage.class);
134    }
135}