001/**
002 * Copyright 2005-2016 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 edu.sampleu.krad.configview;
017
018import org.kuali.rice.testtools.common.JiraAwareFailable;
019import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
020import org.openqa.selenium.By;
021
022/**
023 * @author Kuali Rice Team (rice.collab@kuali.org)
024 */
025public abstract class HelpAftBase extends WebDriverLegacyITBase {
026
027    /**
028     * /kr-krad/configuration-test-view-uif-controller?viewId=ConfigurationTestView&methodToCall=start&pageId=ConfigurationTestView-Help-Page
029     */
030    public static final String BOOKMARK_URL = "/kr-krad/configuration-test-view-uif-controller?viewId=ConfigurationTestView&methodToCall=start&pageId=ConfigurationTestView-Help-Page";
031    public static final String HELP_FOR_CONFIGURATION_TEST_VIEW_XPATH =
032            "//a[@title='Help for Configuration Test View']";
033
034    @Override
035    protected String getBookmarkUrl() {
036        return BOOKMARK_URL;
037    }
038
039    protected void navigation() throws Exception {
040        waitAndClickKRAD();
041        waitAndClickByXpath(CONFIGURATION_VIEW_XPATH);
042        switchToWindow(CONFIGURATION_VIEW_WINDOW_TITLE);
043        waitAndClickByLinkText("Help");
044        Thread.sleep(5000);
045    }
046
047    protected void testHelpNav(JiraAwareFailable failable) throws Exception {
048        navigation();
049        testViewHelp();
050        testPageHelp();
051        testTooltipHelp();
052        testDisplayOnlyTooltipHelp();
053        testMissingTooltipHelp();
054        passed();
055    }
056
057    protected void testHelpBookmark(JiraAwareFailable failable) throws Exception {
058        testViewHelp();
059        testPageHelp();
060        testTooltipHelp();
061        testDisplayOnlyTooltipHelp();
062        testMissingTooltipHelp();
063        passed();
064    }
065
066
067    /**
068     * Test the tooltip and external help on the page
069     */
070    protected void testPageHelp() throws Exception {
071        // test tooltip help
072        fireMouseOverEventByXpath("//a/span[@class='uif-headerText-span']");
073        waitForElementPresent("//div[@class='popover top in']");
074
075        // test external help
076        switchToWindow("Kuali Portal Index");
077        switchToWindow(CONFIGURATION_VIEW_WINDOW_TITLE);
078    }
079
080    /**
081     * Test the tooltip help on the section and fields
082     */
083    protected void testTooltipHelp() throws Exception {
084        // verify that no tooltips are displayed initially
085        if (isElementPresentByXpath("//td[contains(text(),'Sample text for section help - tooltip help')]")) {
086            waitNotVisibleByXpath("//td[contains(text(),'Sample text for section help - tooltip help')]");
087        }
088
089        if (isElementPresentByXpath("//td[contains(text(),'Sample text for field help - label left')]")) {
090            waitNotVisibleByXpath("//td[contains(text(),'Sample text for field help - label left')]");
091        }
092
093        if (isElementPresentByXpath("//td[contains(text(),'Sample text for field help - label right')]")) {
094            waitNotVisibleByXpath("//td[contains(text(),'Sample text for field help - label right')]");
095        }
096
097// Comment out to see how CI handles the following tests
098//        if (isElementPresentByXpath("//td[contains(text(),'Sample text for field help - label top')]")) {
099//            waitNotVisibleByXpath("//td[contains(text(),'Sample text for field help - label top')]", "passes locally");
100//        }
101
102        if (isElementPresentByXpath("//td[contains(text(),'Sample text for standalone help widget tooltip which will never be rendered')]")) {
103            waitNotVisibleByXpath("//td[contains(text(),'Sample text for standalone help widget tooltip which will never be rendered')]");
104        }
105
106        if (isElementPresentByXpath("//td[contains(text(),'Sample text for field help - there is also a tooltip on the label but it is overridden by the help tooltip')]")) {
107            waitNotVisibleByXpath("//td[contains(text(),'Sample text for field help - there is also a tooltip on the label but it is overridden by the help tooltip')]");
108        }
109
110        if (isElementPresentByXpath("//td[contains(text(),'Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip')]")) {
111            waitNotVisibleByXpath("//td[contains(text(),'Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip')]");
112        }
113
114        if (isElementPresentByXpath("//td[contains(text(),'Sample text for field help - there is also an on-focus tooltip')]")) {
115            waitNotVisibleByXpath("//td[contains(text(),'Sample text for field help - there is also an on-focus tooltip')]");
116        }
117
118        if (isElementPresentByXpath("//td[contains(text(),'Sample text for on-focus event tooltip')]")) {
119            waitNotVisibleByXpath("//td[contains(text(),'Sample text for on-focus event tooltip')]");
120        }
121
122        if (isElementPresentByXpath("//td[contains(text(),'Sample text for check box help')]")) {
123            waitNotVisibleByXpath("//td[contains(text(),'Sample text for check box help')]");
124        }
125
126        // test tooltip help of section header
127        fireMouseOverEventByXpath("//section[@id='ConfigurationTestView-Help-Section1']/header/h3[@class='uif-headerText']");
128        waitForElementPresentByXpath("//div[@class='popover top in']");
129
130        // verify that no external help exist
131        assertFalse(isElementPresent("#ConfigurationTestView-Help-Section1 input.uif-helpImage"));
132
133        // test tooltip help of field with label to the left
134        fireMouseOverEventByXpath("//label[@id='field-label-left_label']");
135        waitForElementPresentByXpath("//div[@class='popover top in']");
136
137        // test tooltip help of field with label to the right
138        fireMouseOverEventByXpath("//label[@id='field-label-right_label']");
139        waitForElementPresentByXpath("//div[@class='popover top in']");
140
141        // test tooltip help of field with label to the top
142        fireMouseOverEventByXpath("//label[@id='field-label-top_label']");
143        waitForElementPresentByXpath("//div[@class='popover top in']");
144        
145        // verify that standalone help with tooltip is not rendered
146        assertFalse(isElementPresentByXpath("//*[@id='standalone-help-not-rendered']"));
147
148        // test tooltip help when it overrides a tooltip
149        fireMouseOverEventByXpath("//label[@id='override-tooltip_label']");
150        waitForElementPresentByXpath("//div[@class='popover top in']");
151        if (isElementPresentByXpath("//td[contains(text(),'Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip')]")) {
152            waitNotVisibleByXpath("//td[contains(text(),'Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip')]");
153        }
154
155        // test tooltip help in conjunction with a focus event tooltip
156        fireMouseOverEventByXpath("//input[@id='on-focus-tooltip_control']");
157        waitForElementPresentByXpath("//div[@class='popover top in']");
158        fireMouseOverEventByXpath("//label[@id='on-focus-tooltip_label']");
159        waitForElementPresentByXpath("//div[@class='popover top in']");
160
161        // test tooltip help against a check box - help contains html
162        fireMouseOverEventByXpath("//label[@id='checkbox_label']");
163        waitForElementPresentByXpath("//div[@class='popover top in']");
164    }
165
166    /**
167     * Test the tooltip help on the sub-section and fields that are display only
168     */
169    protected void testDisplayOnlyTooltipHelp() throws Exception {
170
171        // test tooltip help of sub-section header
172        fireMouseOverEventByXpath("//section[@data-parent='ConfigurationTestView-Help-Section1']/header/h4");
173        waitForElementPresentByXpath("//td[contains(text(),'Sample text for sub-section help')]");
174
175        // test tooltip help of display only data field
176        fireMouseOverEventByXpath("//label[@for='display-field_control']");
177        waitForElementPresentByXpath("//td[contains(text(),'Sample text for read only field help')]");
178    }
179
180    /**
181     * Test the tooltip help on the section and fields with no content
182     */
183    protected void testMissingTooltipHelp() throws Exception {
184
185        // test tooltip help of section header
186        fireMouseOverEventByXpath("//section[@id='ConfigurationTestView-Help-Section2']/div");
187        assertFalse(isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-black' and @style='opacity: 0; top: 627px; left: 2px; position: absolute; display: block;']"));
188
189        // test tooltip help of field
190        fireMouseOverEventByXpath("//label[@id='missing-tooltip-help_label']");
191        assertFalse(isElementPresentByXpath("//div[@class='jquerybubblepopup jquerybubblepopup-black' and @style='opacity: 0; top: 627px; left: 2px; position: absolute; display: block;']"));
192    }
193
194    /**
195     * Test the tooltip and external help on the view
196     */
197    protected void testViewHelp() throws Exception {
198        // test tooltip help
199        fireEvent("field102", "blur");
200        fireMouseOverEventByXpath("//label[@id='field-label-left_label']");
201        waitForElementPresent("//div[@class='popover top in']");
202
203        // test external help
204        switchToWindow("Kuali Portal Index");
205        switchToWindow(CONFIGURATION_VIEW_WINDOW_TITLE);
206    }
207}