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