View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.samplu.krad.configview;
17  
18  import org.junit.After;
19  import org.junit.Before;
20  import org.junit.Ignore;
21  import org.junit.Test;
22  
23  import com.thoughtworks.selenium.DefaultSelenium;
24  import com.thoughtworks.selenium.Selenium;
25  
26  import static org.junit.Assert.*;
27  
28  /**
29   * Test the help widget
30   *
31   * <p>
32   * Selenium RC does not allow us to test the external help popup windows due to an error on JavaScrips window.close
33   * method when selenium is running.  To test the external help we use the {@link HelpIT2} test
34   * which utilizes WebDriver.  Unfortunately due to a WebDriver bug/feature we can't test the tooltip help there.
35   * </p>
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  public class HelpIT {
40      private Selenium selenium;
41  
42      // Delay in milliseconds used to allow the help window reload the new help page.
43      // waitForPopUp will not work since the window already exists.
44      private long HELP_WINDOW_LOAD_DELAY = 3000;
45  
46      @Before
47      public void setUp() throws Exception {
48          System.setProperty("remote.public.url", "http://localhost:8080/kr-dev/kr-krad/configuration-test-view-uif-controller?viewId=ConfigurationTestView-Help&methodToCall=start");
49          selenium = new DefaultSelenium("localhost", 4444, "*firefox", System.getProperty("remote.public.url"));
50          selenium.start();
51  
52          // Login
53          selenium.open(System.getProperty("remote.public.url"));
54          assertEquals("Login", selenium.getTitle());
55          selenium.type("__login_user", "admin");
56          selenium.click("//input[@value='Login']");
57          selenium.waitForPageToLoad("30000");
58      }
59  
60      /**
61       * Test the tooltip and external help on the view
62       */
63      @Test
64      public void testViewHelp() throws Exception {
65          // test tooltip help
66          selenium.mouseOver("css=h1 .uif-headerText-span");
67          assertEquals("Sample text for view help", selenium.getText("css=td.jquerybubblepopup-innerHtml"));
68  
69          // test external help
70          selenium.click("css=input[title=\"Help for Configuration Test View - Help\"]");
71          selenium.waitForPopUp("HelpWindow", "30000");
72          selenium.selectPopUp("HelpWindow");
73          assertEquals("http://www.kuali.org/?view", selenium.getLocation());
74          selenium.deselectPopUp();
75      }
76  
77      /**
78       * Test the tooltip and external help on the page
79       */
80      @Test
81      public void testPageHelp() throws Exception {
82          // test tooltip help
83          selenium.mouseOver("css=h2 .uif-headerText-span");
84          assertEquals("Sample text for page help", selenium.getText("css=td.jquerybubblepopup-innerHtml"));
85  
86          // test external help
87          selenium.click("css=input[title=\"Help for Help Page\"]");
88          selenium.waitForPopUp("HelpWindow", "30000");
89          selenium.selectPopUp("HelpWindow");
90          assertEquals("http://www.kuali.org/?page", selenium.getLocation());
91          selenium.deselectPopUp();
92      }
93  
94      /**
95       * Test the tooltip help on the section and fields
96       */
97      @Test
98      public void testTooltipHelp() throws Exception {
99          // verify that no tooltips are displayed initially
100         if (selenium.isElementPresent("css=td:contains(\"Sample text for section help - tooltip help\")")) {
101             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for section help - tooltip help\")"));
102         }
103         if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - label left\")")) {
104             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label left\")"));
105         }
106         if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - label right\")")) {
107             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label right\")"));
108         }
109         if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - label top\")")) {
110             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label top\")"));
111         }
112         if (selenium.isElementPresent("css=td:contains(\"Sample text for standalone help widget tooltip which will never be rendered\")")) {
113             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for standalone help widget tooltip which will never be rendered\")"));
114         }
115         if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - there is also a tooltip on the label but it is overridden by the help tooltip\")")) {
116             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - there is also a tooltip on the label but it is overridden by the help tooltip\")"));
117         }
118         if (selenium.isElementPresent("css=td:contains(\"Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip\")")) {
119             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip\")"));
120         }
121         if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - there is also an on-focus tooltip\")")) {
122             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - there is also an on-focus tooltip\")"));
123         }
124         if (selenium.isElementPresent("css=td:contains(\"Sample text for on-focus event tooltip\")")) {
125             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for on-focus event tooltip\")"));
126         }
127         if (selenium.isElementPresent("css=td:contains(\"Sample text for check box help\")")) {
128             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for check box help\")"));
129         }
130 
131         // test tooltip help of section header
132         selenium.mouseOver("css=#ConfigurationTestView-Help-Section1 h3 .uif-headerText-span");
133         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for section help - tooltip help\")"));
134         selenium.mouseOut("css=#ConfigurationTestView-Help-Section1 h3 .uif-headerText-span");
135         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for section help - tooltip help\")"));
136 
137         // verify that no external help exist
138         assertFalse(selenium.isElementPresent("css=#ConfigurationTestView-Help-Section1 input.uif-helpImage"));
139 
140         // test tooltip help of field with label to the left
141         selenium.mouseOver("id=field-label-left_label");
142         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for field help - label left\")"));
143         selenium.mouseOut("id=field-label-left_label");
144         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label left\")"));
145 
146         // test tooltip help of field with label to the right
147         selenium.mouseOver("id=field-label-right_label");
148         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for field help - label righ\")"));
149         selenium.mouseOut("id=field-label-right_label");
150         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label right\")"));
151 
152         // test tooltip help of field with label to the top
153         selenium.mouseOver("id=field-label-top_label");
154         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for field help - label top\")"));
155         selenium.mouseOut("id=field-label-top_label");
156         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label top\")"));
157 
158         // verify that standalone help with tooltip is not rendered
159         assertFalse(selenium.isElementPresent("id=standalone-help-not-rendered"));
160 
161         // test tooltip help when it overrides a tooltip
162         selenium.mouseOver("id=override-tooltip_label");
163         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for field help - there is also a tooltip on the label but it is overridden by the help tooltip\")"));
164         if (selenium.isElementPresent("css=td:contains(\"Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip\")")) {
165             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip\")"));
166         }
167         selenium.mouseOut("id=override-tooltip_label");
168         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - there is also a tooltip on the label but it is overridden by the help tooltip\")"));
169 
170         // test tooltip help in conjunction with a focus event tooltip
171         selenium.mouseOver("id=on-focus-tooltip_control");
172         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for on-focus event tooltip\")"));
173         selenium.mouseOver("id=on-focus-tooltip_label");
174         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for field help - there is also an on-focus tooltip\")"));
175         selenium.mouseOut("id=on-focus-tooltip_control");
176         selenium.mouseOut("id=on-focus-tooltip_label");
177         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - there is also an on-focus tooltip\")"));
178         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for on-focus event tooltip\")"));
179 
180         // test tooltip help against a check box - help contains html
181         selenium.mouseOver("id=checkbox_label");
182         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for check box help\")"));
183         selenium.mouseOut("id=checkbox_label");
184         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for check box help\")"));
185     }
186 
187     /**
188      * Test the tooltip help on the sub-section and fields that are display only
189      */
190     @Test
191     public void testDisplayOnlyTooltipHelp() throws Exception {
192         // verify that no tooltips are displayed initially
193         if (selenium.isElementPresent("css=td:contains(\"Sample text for sub-section help\")")) {
194             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for sub-section help\")"));
195         }
196         if (selenium.isElementPresent("css=td:contains(\"Sample text for read only field help\")")) {
197             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for read only field help\")"));
198         }
199 
200         // test tooltip help of sub-section header
201         selenium.mouseOver("css=h4 .uif-headerText-span");
202         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for sub-section help\")"));
203         selenium.mouseOut("css=h4 .uif-headerText-span");
204         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for sub-section help\")"));
205 
206         // test tooltip help of display only data field
207         selenium.mouseOver("css=#display-field label");
208         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for read only field help\")"));
209         selenium.mouseOut("css=#display-field label");
210         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for read only field help\")"));
211     }
212 
213     /**
214      * Test the tooltip help on the section and fields with no content
215      */
216     @Test
217     public void testMissingTooltipHelp() throws Exception {
218         // verify that no tooltips are displayed initially
219         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
220 
221         // verify that no external help exist
222         assertFalse(selenium.isElementPresent("css=#ConfigurationTestView-Help-Section2 input.uif-helpImage"));
223 
224         // test tooltip help of section header
225         selenium.mouseOver("css=#ConfigurationTestView-Help-Section2 h3 .uif-headerText-span");
226         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
227         selenium.mouseOut("css=#ConfigurationTestView-Help-Section1 h3 .uif-headerText-span");
228         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
229 
230         // test tooltip help of field
231         selenium.mouseOver("id=missing-tooltip-help_label");
232         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
233         selenium.mouseOut("id=missing-tooltip-help_label");
234         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
235     }
236 
237    @After
238     public void tearDown() throws Exception {
239         selenium.stop();
240     }
241 
242 }