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 *     Gabriel Barata
018 */
019
020package org.nuxeo.functionaltests.pages.forms;
021
022import org.nuxeo.functionaltests.Locator;
023import org.nuxeo.functionaltests.Required;
024import org.nuxeo.functionaltests.forms.Select2WidgetElement;
025import org.nuxeo.functionaltests.pages.AbstractPage;
026import org.nuxeo.functionaltests.pages.tabs.TopicTabSubPage;
027import org.openqa.selenium.By;
028import org.openqa.selenium.WebDriver;
029import org.openqa.selenium.WebElement;
030import org.openqa.selenium.support.FindBy;
031
032/**
033 * @since 8.3
034 */
035public class TopicCreationFormPage extends AbstractPage {
036
037    @Required
038    @FindBy(xpath = "//input[@id='createThread:title']")
039    public WebElement titleTextInput;
040
041    @FindBy(xpath = "//textarea[@id='createThread:description']")
042    public WebElement descriptionTextInput;
043
044    @Required
045    @FindBy(xpath = "//input[@type='radio' and @value='true']")
046    public WebElement moderationYesRadioButton;
047
048    @Required
049    @FindBy(xpath = "//input[@type='radio' and @value='false']")
050    public WebElement moderationNoRadioButton;
051
052    @Required
053    @FindBy(xpath = "//input[@type='submit' and @value='Create']")
054    public WebElement createButton;
055
056    @Required
057    @FindBy(xpath = "//input[@type='submit' and @value='Cancel']")
058    public WebElement cancelButton;
059
060    public TopicCreationFormPage(WebDriver driver) {
061        super(driver);
062    }
063
064    public TopicTabSubPage createTopicDocument(String title, String description, Boolean moderation,
065            String... usersOrGroups) {
066        titleTextInput.sendKeys(title);
067        descriptionTextInput.sendKeys(description);
068
069        if (moderation) {
070            Locator.scrollAndForceClick(moderationYesRadioButton);
071        } else {
072            Locator.scrollAndForceClick(moderationNoRadioButton);
073        }
074
075        if (usersOrGroups != null) {
076            Select2WidgetElement selectUsersOrGroups = new Select2WidgetElement(driver,
077                    driver.findElement(By
078                                         .xpath("//div[@id='s2id_createThread:nxl_user_group_prefixed_suggestion:nxw_selection_select2']")),
079                    true);
080            selectUsersOrGroups.selectValues(usersOrGroups);
081        }
082
083        Locator.waitUntilEnabledAndClick(createButton);
084        return asPage(TopicTabSubPage.class);
085    }
086}