001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Mariana Cedica
016 */
017package org.nuxeo.functionaltests.pages;
018
019import org.nuxeo.functionaltests.AjaxRequestManager;
020import org.nuxeo.functionaltests.fragment.GadgetsContainerFragment;
021import org.nuxeo.functionaltests.pages.tabs.SummaryTabSubPage;
022import org.openqa.selenium.By;
023import org.openqa.selenium.WebDriver;
024import org.openqa.selenium.WebElement;
025import org.openqa.selenium.support.FindBy;
026
027/**
028 * @since 5.7
029 */
030public class UserHomePage extends AbstractPage {
031
032    // not required: when navigating to home, we could be on another tab than
033    // dashboard
034    @FindBy(id = GadgetsContainerFragment.GADGETS_CONTAINER_ID)
035    public WebElement gadgetsContainer;
036
037    protected GadgetsContainerFragment gadgetsFragment;
038
039    public UserHomePage(WebDriver driver) {
040        super(driver);
041    }
042
043    protected GadgetsContainerFragment getGadgetsFragment() {
044        if (gadgetsFragment == null) {
045            gadgetsFragment = getWebFragment(gadgetsContainer, GadgetsContainerFragment.class);
046        }
047        return gadgetsFragment;
048    }
049
050    public boolean isTaskGadgetLoaded() {
051        return getGadgetsFragment().isGadgetLoaded("My Tasks");
052    }
053
054    public SummaryTabSubPage redirectToTask(String taskTitle) {
055        WebDriver driver = getGadgetsFragment().switchToFrame("My Tasks");
056        driver.findElement(By.linkText(taskTitle)).click();
057        return new SummaryTabSubPage(driver);
058    }
059
060    public boolean isTaskGadgetEmpty() {
061        return getGadgetsFragment().isTaskGadgetEmpty("My Tasks");
062    }
063
064    /**
065     * @since 5.8
066     */
067    public WorkflowHomePage getWorkflowHomePage() {
068        goToTab("nxw_WorkflowHome");
069        return asPage(WorkflowHomePage.class);
070    }
071
072    public UserHomePage goToDashboard() {
073        goToTab("nxw_Dashboard");
074        return this;
075    }
076
077    public ProfilePage goToProfile() {
078        goToTab("nxw_Profile");
079        return asPage(ProfilePage.class);
080    }
081
082    protected void goToTab(String id) {
083        clickOnTabIfNotSelected("nxw_homeTabs_panel", id);
084    }
085
086}