001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.rice.testtools.selenium.breadcrumb;
017
018import com.google.common.primitives.Ints;
019import org.junit.Test;
020import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
021import org.openqa.selenium.By;
022
023import java.util.Arrays;
024import java.util.Collections;
025
026/**
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029public abstract class BreadcrumbAftBase extends WebDriverLegacyITBase {
030
031    /**
032     * //div[@class='uif-breadcrumbSiblingContent']//div[@class='uif-inputField']//ul[@class='uif-optionList']
033     */
034    public static final String SECOND_BREADCRUMB_NAV_XPATH = "//div[@class='uif-breadcrumbSiblingContent']//div[@class='uif-inputField']//ul[@class='uif-optionList']";
035
036    /**
037     * (//a[@class='uif-breadcrumbSiblingLink'])[2]
038     */
039    public static final String SECOND_DOWN_TRIANGLE_XPATH = "(//a[@class='uif-breadcrumbSiblingLink'])[2]";
040
041    String[][] selectAsserts = {{"UifCompView", "Uif Components"}};
042
043    int[] breadcrumbOrderIndexes = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1};
044
045    protected String getTriangleXpath() {
046        return SECOND_DOWN_TRIANGLE_XPATH;
047    }
048
049    protected void testBreadcrumb(int pageNumber) throws Exception {
050        // <ul id="u13_control" class="uif-optionList" data-control_for="u13" tabindex="0"><li class="uif-optionList-item uif-optionList-selectedItem"><a href="http://env1.rice.kuali.org/kr-krad/uicomponents?methodToCall=start&pageId=UifCompView-Page1&viewId=UifCompView" data-key="UifCompView-Page1">
051        //         Input Fields and Controls
052        // </a></li>
053        // <li class="uif-optionList-item"><a href="http://env1.rice.kuali.org/kr-krad/uicomponents?methodToCall=start&pageId=UifCompView-Page2&viewId=UifCompView" data-key="UifCompView-Page2">
054        //         Other Fields
055        // </a></li>
056        // etc.
057        jiraAwareWaitFor(By.xpath(SECOND_BREADCRUMB_NAV_XPATH));
058        assertFalse(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
059        // The second ▼
060        waitAndClickByXpath(getTriangleXpath(), "failed on breadcrumb pageNumber " + pageNumber);
061        Thread.sleep(100);
062        assertTrue(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
063        waitAndClickByXpath(getTriangleXpath());
064        assertFalse(isVisibleByXpath(SECOND_BREADCRUMB_NAV_XPATH));
065        waitAndClickByXpath(getTriangleXpath());
066
067        // The Second selection of the second ▼
068        // you can't just click by link text as the same clickable text is on the left navigation.
069        waitAndClickByXpath(SECOND_BREADCRUMB_NAV_XPATH +"/li[" + pageNumber + "]/a");
070        waitForElementPresentById("TopLink" + pageNumber, "Breadcrumb number " + pageNumber + " failure", 30); // bottom jump to top link
071        driver.getCurrentUrl().contains("pageId=UifCompView-Page" + pageNumber);
072    }
073
074    protected void testBreadcrumbs() throws Exception {
075        for (int i = 0, s = breadcrumbOrderIndexes.length; i < s; i++) {
076            testBreadcrumb(breadcrumbOrderIndexes[i]);
077        }
078    }
079
080    protected void testBreadcrumbsShuffled() throws Exception {
081        int[] copiedBreadcrumbOrderIndex = Arrays.copyOf(breadcrumbOrderIndexes, breadcrumbOrderIndexes.length);
082
083        Collections.shuffle(Ints.asList(copiedBreadcrumbOrderIndex));
084        for (int i = 0, s = copiedBreadcrumbOrderIndex.length; i < s; i++) {
085            jGrowl("Click on Bread crumb index number " + i);
086            testBreadcrumb(copiedBreadcrumbOrderIndex[i]);
087        }
088    }
089
090    @Test
091    public void testBreadcrumbBookmark() throws Exception {
092        testBreadcrumbs();
093        passed();
094    }
095
096    @Test
097    public void testBreadcrumbShuffledBookmark() throws Exception {
098        testBreadcrumbsShuffled();
099        passed();
100    }
101
102    @Test
103    public void testBreadcrumbNav() throws Exception {
104        testBreadcrumbs();
105        passed();
106    }
107
108    @Test
109    public void testBreadcrumbShuffledNav() throws Exception {
110        testBreadcrumbsShuffled();
111        passed();
112    }
113}