001/*
002 * (C) Copyright 2015-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 *     Nelson Silva
018 *     Yannis JULIENNE
019 */
020package org.nuxeo.functionaltests.pages.admincenter.usermanagement;
021
022import static org.junit.Assert.assertEquals;
023
024import java.util.ArrayList;
025import java.util.List;
026
027import org.nuxeo.functionaltests.Locator;
028import org.nuxeo.functionaltests.Required;
029import org.openqa.selenium.Alert;
030import org.openqa.selenium.By;
031import org.openqa.selenium.WebDriver;
032import org.openqa.selenium.WebElement;
033import org.openqa.selenium.support.FindBy;
034
035/**
036 * View group details
037 *
038 * @since 7.2
039 */
040public class GroupViewTabSubPage extends UsersGroupsBasePage {
041
042    @Required
043    @FindBy(xpath = "//div[@id='nxw_adminCenterSubTabs_tab_content']//h1")
044    WebElement groupName;
045
046    @FindBy(id = "viewGroupView:viewGroup")
047    WebElement viewGroupForm;
048
049    @FindBy(id = "viewGroupView:viewGroup:nxl_group:nxw_group_label")
050    WebElement groupLabel;
051
052    @Required
053    @FindBy(linkText = "View")
054    WebElement viewGroupTab;
055
056    @FindBy(linkText = "Delete")
057    WebElement deleteGroupLink;
058
059    @FindBy(linkText = "Edit")
060    WebElement editLink;
061
062    public GroupViewTabSubPage(WebDriver driver) {
063        super(driver);
064    }
065
066    public GroupsTabSubPage deleteGroup() {
067        deleteGroupLink.click();
068        Alert alert = driver.switchTo().alert();
069        assertEquals("Delete group?", alert.getText());
070        alert.accept();
071        return asPage(GroupsTabSubPage.class);
072    }
073
074    public GroupEditFormPage getEditGroupTab() {
075        waitUntilEnabledAndClick(editLink);
076        return asPage(GroupEditFormPage.class);
077    }
078
079    public GroupsTabSubPage backToTheList() {
080        findElementWaitUntilEnabledAndClick(By.linkText("Back to the List"));
081        return asPage(GroupsTabSubPage.class);
082    }
083
084    /**
085     * @since 8.3
086     */
087    public String getGroupName() {
088        return groupName.getText();
089    }
090
091    /**
092     * @since 8.3
093     */
094    public String getGroupLabel() {
095        return groupLabel.getText();
096    }
097
098    /**
099     * @since 8.3
100     */
101    public List<String> getGroupMembers() {
102        List<WebElement> userElements = viewGroupForm.findElements(By.className("user"));
103        List<String> users = new ArrayList<>();
104        for (WebElement userElement : userElements) {
105            users.add(Locator.findParentTag(userElement, "a").getAttribute("title"));
106        }
107        return users;
108    }
109
110    /**
111     * @since 8.3
112     */
113    public List<String> getSubGroupLabels() {
114        List<WebElement> goupElements = viewGroupForm.findElements(By.className("group"));
115        List<String> groups = new ArrayList<>();
116        for (WebElement groupElement : goupElements) {
117            groups.add(groupElement.getText());
118        }
119        return groups;
120    }
121
122}