001/*
002 * (C) Copyright 2015 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 *     Nelson Silva
018 */
019package org.nuxeo.functionaltests.pages.admincenter.usermanagement;
020
021import org.nuxeo.functionaltests.AjaxRequestManager;
022import org.nuxeo.functionaltests.Locator;
023import org.nuxeo.functionaltests.Required;
024import org.nuxeo.functionaltests.forms.Select2WidgetElement;
025import org.openqa.selenium.NoSuchElementException;
026import org.openqa.selenium.WebDriver;
027import org.openqa.selenium.WebElement;
028import org.openqa.selenium.support.FindBy;
029
030/**
031 * Group creation form page.
032 *
033 * @since 7.2
034 */
035public class GroupCreationFormPage extends UsersGroupsBasePage {
036
037    @FindBy(id = "createGroupView:createGroup:nxl_group:nxw_group_name")
038    WebElement nameInput;
039
040    @FindBy(id = "createGroupView:createGroup:nxl_group:nxw_group_label")
041    WebElement labelInput;
042
043    @Required
044    @FindBy(id = "s2id_createGroupView:createGroup:nxl_group:nxw_group_members_select2")
045    WebElement membersSelect;
046
047    @Required
048    @FindBy(id = "s2id_createGroupView:createGroup:nxl_group:nxw_group_subgroups_select2")
049    WebElement subgroupsSelect;
050
051    @FindBy(id = "createGroupView:createGroup:button_save")
052    WebElement createButton;
053
054    @Required
055    @FindBy(xpath = "//div[@class=\"tabsContent\"]//input[@value=\"Cancel\"]")
056    WebElement cancelButton;
057
058    public GroupCreationFormPage(WebDriver driver) {
059        super(driver);
060    }
061
062    public UsersGroupsBasePage createGroup(String name, String label, String[] members, String[] subgroups)
063            throws NoSuchElementException {
064        nameInput.sendKeys(name);
065        labelInput.sendKeys(label);
066        if (members != null) {
067            new Select2WidgetElement(driver, membersSelect, true).selectValues(members);
068        }
069        if (subgroups != null) {
070            new Select2WidgetElement(driver, subgroupsSelect, true).selectValues(subgroups);
071        }
072        AjaxRequestManager arm = new AjaxRequestManager(driver);
073        arm.begin();
074        Locator.waitUntilEnabledAndClick(createButton);
075        arm.end();
076        return asPage(UsersGroupsBasePage.class);
077    }
078
079    public GroupsTabSubPage cancelCreation() {
080        AjaxRequestManager arm = new AjaxRequestManager(driver);
081        arm.begin();
082        Locator.waitUntilEnabledAndClick(cancelButton);
083        arm.end();
084        return asPage(GroupsTabSubPage.class);
085    }
086}