001/*
002 * (C) Copyright 2013 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 *     Mariana Cedica
018 */
019package org.nuxeo.functionaltests.pages;
020
021import org.nuxeo.functionaltests.AjaxRequestManager;
022import org.nuxeo.functionaltests.fragment.GadgetsContainerFragment;
023import org.nuxeo.functionaltests.pages.tabs.SummaryTabSubPage;
024import org.openqa.selenium.By;
025import org.openqa.selenium.WebDriver;
026import org.openqa.selenium.WebElement;
027import org.openqa.selenium.support.FindBy;
028
029/**
030 * @since 5.7
031 */
032public class UserHomePage extends AbstractPage {
033
034    // not required: when navigating to home, we could be on another tab than
035    // dashboard
036    @FindBy(id = GadgetsContainerFragment.GADGETS_CONTAINER_ID)
037    public WebElement gadgetsContainer;
038
039    protected GadgetsContainerFragment gadgetsFragment;
040
041    public UserHomePage(WebDriver driver) {
042        super(driver);
043    }
044
045    protected GadgetsContainerFragment getGadgetsFragment() {
046        if (gadgetsFragment == null) {
047            gadgetsFragment = getWebFragment(gadgetsContainer, GadgetsContainerFragment.class);
048        }
049        return gadgetsFragment;
050    }
051
052    public boolean isTaskGadgetLoaded() {
053        return getGadgetsFragment().isGadgetLoaded("My Tasks");
054    }
055
056    public SummaryTabSubPage redirectToTask(String taskTitle) {
057        WebDriver driver = getGadgetsFragment().switchToFrame("My Tasks");
058        driver.findElement(By.linkText(taskTitle)).click();
059        return new SummaryTabSubPage(driver);
060    }
061
062    public boolean isTaskGadgetEmpty() {
063        return getGadgetsFragment().isTaskGadgetEmpty("My Tasks");
064    }
065
066    /**
067     * @since 5.8
068     */
069    public WorkflowHomePage getWorkflowHomePage() {
070        goToTab("nxw_WorkflowHome");
071        return asPage(WorkflowHomePage.class);
072    }
073
074    public UserHomePage goToDashboard() {
075        goToTab("nxw_Dashboard");
076        return this;
077    }
078
079    public ProfilePage goToProfile() {
080        goToTab("nxw_Profile");
081        return asPage(ProfilePage.class);
082    }
083
084    protected void goToTab(String id) {
085        clickOnTabIfNotSelected("nxw_homeTabs_panel", id);
086    }
087
088}