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 *     Benoit Delbosc
018 *     Antoine Taillefer
019 *     Yannis JULIENNE
020 */
021package org.nuxeo.functionaltests.pages.admincenter.usermanagement;
022
023import static org.junit.Assert.assertEquals;
024
025import java.util.ArrayList;
026import java.util.List;
027
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 user details (New one in the admin center)
037 *
038 * @since 5.4.2
039 */
040public class UserViewTabSubPage extends UsersGroupsBasePage {
041
042    @Required
043    @FindBy(linkText = "View")
044    WebElement viewUserTab;
045
046    @FindBy(linkText = "Delete")
047    WebElement deleteUserLink;
048
049    @FindBy(linkText = "Edit")
050    WebElement editLink;
051
052    @FindBy(linkText = "Change Password")
053    WebElement changePasswordLink;
054
055    @FindBy(xpath = "//div[@id='nxw_userCenterSubTabs_tab_content']//h1")
056    WebElement currentUserName;
057
058    @FindBy(id = "viewUserView:viewUser:nxl_gridUserLayout:nxw_userPanelLeft_panel")
059    WebElement viewUserPanel;
060
061    public UserViewTabSubPage(WebDriver driver) {
062        super(driver);
063    }
064
065    public UsersTabSubPage deleteUser() {
066        deleteUserLink.click();
067        Alert alert = driver.switchTo().alert();
068        assertEquals("Delete user?", alert.getText());
069        alert.accept();
070        return asPage(UsersTabSubPage.class);
071    }
072
073    public UserEditFormPage getEditUserTab() {
074        editLink.click();
075        return asPage(UserEditFormPage.class);
076    }
077
078    public UserChangePasswordFormPage getChangePasswordUserTab() {
079        changePasswordLink.click();
080        return asPage(UserChangePasswordFormPage.class);
081    }
082
083    public UsersTabSubPage backToTheList() {
084        findElementWaitUntilEnabledAndClick(By.linkText("Back to the List"));
085        return asPage(UsersTabSubPage.class);
086    }
087
088    /**
089     * @since 6.0
090     */
091    public void checkUserName(String expectedName) {
092        assertEquals(expectedName, getCurrentUserName().getText());
093    }
094
095    /**
096     * @since 6.0
097     */
098    public WebElement getCurrentUserName() {
099        return currentUserName;
100    }
101
102    /**
103     * @since 8.3
104     */
105    public List<String> getGroupLabels() {
106        List<WebElement> goupElements = viewUserPanel.findElements(By.className("group"));
107        List<String> groups = new ArrayList<>();
108        for (WebElement groupElement : goupElements) {
109            groups.add(groupElement.getText());
110        }
111        return groups;
112    }
113}