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   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class HelpIT {
34      private Selenium selenium;
35  
36      // Delay in milliseconds used to allow the help window reload the new help page.
37      // waitForPopUp will not work since the window already exists.
38      private long HELP_WINDOW_LOAD_DELAY = 3000;
39  
40      @Before
41      public void setUp() throws Exception {
42          System.setProperty("remote.public.url", "http://localhost:8080/kr-dev/kr-krad/configuration-test-view-uif-controller?viewId=ConfigurationTestView-Help&methodToCall=start");
43          selenium = new DefaultSelenium("localhost", 4444, "*firefox", System.getProperty("remote.public.url"));
44          selenium.start();
45  
46          // Login
47          selenium.open(System.getProperty("remote.public.url"));
48          assertEquals("Login", selenium.getTitle());
49          selenium.type("__login_user", "admin");
50          selenium.click("//input[@value='Login']");
51          selenium.waitForPageToLoad("30000");
52      }
53  
54      /**
55       * Test the tooltip and external help on the view
56       */
57      @Test
58      public void testViewHelp() throws Exception {
59          // test tooltip help
60          selenium.mouseOver("css=h1 .uif-headerText-span");
61          assertEquals("Sample text for view help", selenium.getText("css=td.jquerybubblepopup-innerHtml"));
62  
63          // test external help
64          selenium.click("css=input[title=\"Help for Configuration Test View - Help\"]");
65          selenium.waitForPopUp("HelpWindow", "30000");
66          selenium.selectPopUp("HelpWindow");
67          assertEquals("http://www.kuali.org/?view", selenium.getLocation());
68          selenium.deselectPopUp();
69      }
70  
71      /**
72       * Test the tooltip and external help on the page
73       */
74      @Test
75      public void testPageHelp() throws Exception {
76          // test tooltip help
77          selenium.mouseOver("css=h2 .uif-headerText-span");
78          assertEquals("Sample text for page help", selenium.getText("css=td.jquerybubblepopup-innerHtml"));
79  
80          // test external help
81          selenium.click("css=input[title=\"Help for Help Page\"]");
82          selenium.waitForPopUp("HelpWindow", "30000");
83          selenium.selectPopUp("HelpWindow");
84          assertEquals("http://www.kuali.org/?page", selenium.getLocation());
85          selenium.deselectPopUp();
86      }
87  
88      /**
89       * Test the tooltip help on the section and fields
90       */
91      @Test
92      public void testTooltipHelp() throws Exception {
93          // verify that no tooltips are displayed initially
94          if (selenium.isElementPresent("css=td:contains(\"Sample text for section help - tooltip help\")")) {
95              assertFalse(selenium.isVisible("css=td:contains(\"Sample text for section help - tooltip help\")"));
96          }
97          if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - label left\")")) {
98              assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label left\")"));
99          }
100         if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - label right\")")) {
101             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label right\")"));
102         }
103         if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - label top\")")) {
104             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label top\")"));
105         }
106         if (selenium.isElementPresent("css=td:contains(\"Sample text for standalone help widget tooltip which will never be rendered\")")) {
107             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for standalone help widget tooltip which will never be rendered\")"));
108         }
109         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\")")) {
110             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\")"));
111         }
112         if (selenium.isElementPresent("css=td:contains(\"Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip\")")) {
113             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip\")"));
114         }
115         if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - there is also an on-focus tooltip\")")) {
116             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - there is also an on-focus tooltip\")"));
117         }
118         if (selenium.isElementPresent("css=td:contains(\"Sample text for on-focus event tooltip\")")) {
119             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for on-focus event tooltip\")"));
120         }
121         if (selenium.isElementPresent("css=td:contains(\"Sample text for check box help\")")) {
122             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for check box help\")"));
123         }
124 
125         // test tooltip help of section header
126         selenium.mouseOver("css=#ConfigurationTestView-Help-Section1 h3 .uif-headerText-span");
127         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for section help - tooltip help\")"));
128         selenium.mouseOut("css=#ConfigurationTestView-Help-Section1 h3 .uif-headerText-span");
129         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for section help - tooltip help\")"));
130 
131         // verify that no external help exist
132         assertFalse(selenium.isElementPresent("css=#ConfigurationTestView-Help-Section1 input.uif-helpImage"));
133 
134         // test tooltip help of field with label to the left
135         selenium.mouseOver("id=field-label-left_label");
136         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for field help - label left\")"));
137         selenium.mouseOut("id=field-label-left_label");
138         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label left\")"));
139 
140         // test tooltip help of field with label to the right
141         selenium.mouseOver("id=field-label-right_label");
142         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for field help - label righ\")"));
143         selenium.mouseOut("id=field-label-right_label");
144         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label right\")"));
145 
146         // test tooltip help of field with label to the top
147         selenium.mouseOver("id=field-label-top_label");
148         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for field help - label top\")"));
149         selenium.mouseOut("id=field-label-top_label");
150         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label top\")"));
151 
152         // verify that standalone help with tooltip is not rendered
153         assertFalse(selenium.isElementPresent("id=standalone-help-not-rendered"));
154 
155         // test tooltip help when it overrides a tooltip
156         selenium.mouseOver("id=override-tooltip_label");
157         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\")"));
158         if (selenium.isElementPresent("css=td:contains(\"Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip\")")) {
159             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for label tooltip - this will not be rendered as it is overridden by the help tooltip\")"));
160         }
161         selenium.mouseOut("id=override-tooltip_label");
162         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\")"));
163 
164         // test tooltip help in conjunction with a focus event tooltip
165         selenium.mouseOver("id=on-focus-tooltip_control");
166         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for on-focus event tooltip\")"));
167         selenium.mouseOver("id=on-focus-tooltip_label");
168         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for field help - there is also an on-focus tooltip\")"));
169         selenium.mouseOut("id=on-focus-tooltip_control");
170         selenium.mouseOut("id=on-focus-tooltip_label");
171         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - there is also an on-focus tooltip\")"));
172         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for on-focus event tooltip\")"));
173 
174         // test tooltip help against a check box - help contains html
175         selenium.mouseOver("id=checkbox_label");
176         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for check box help\")"));
177         selenium.mouseOut("id=checkbox_label");
178         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for check box help\")"));
179     }
180 
181     /**
182      * Test the tooltip help on the sub-section and fields that are display only
183      */
184     @Test
185     public void testDisplayOnlyTooltipHelp() throws Exception {
186         // verify that no tooltips are displayed initially
187         if (selenium.isElementPresent("css=td:contains(\"Sample text for sub-section help\")")) {
188             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for sub-section help\")"));
189         }
190         if (selenium.isElementPresent("css=td:contains(\"Sample text for read only field help\")")) {
191             assertFalse(selenium.isVisible("css=td:contains(\"Sample text for read only field help\")"));
192         }
193 
194         // test tooltip help of sub-section header
195         selenium.mouseOver("css=h4 .uif-headerText-span");
196         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for sub-section help\")"));
197         selenium.mouseOut("css=h4 .uif-headerText-span");
198         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for sub-section help\")"));
199 
200         // test tooltip help of display only data field
201         selenium.mouseOver("css=#display-field label");
202         assertTrue(selenium.isVisible("css=td:contains(\"Sample text for read only field help\")"));
203         selenium.mouseOut("css=#display-field label");
204         assertFalse(selenium.isVisible("css=td:contains(\"Sample text for read only field help\")"));
205     }
206 
207     /**
208      * Test the tooltip help on the section and fields with no content
209      */
210     @Test
211     public void testMissingTooltipHelp() throws Exception {
212         // verify that no tooltips are displayed initially
213         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
214 
215         // verify that no external help exist
216         assertFalse(selenium.isElementPresent("css=#ConfigurationTestView-Help-Section2 input.uif-helpImage"));
217 
218         // test tooltip help of section header
219         selenium.mouseOver("css=#ConfigurationTestView-Help-Section2 h3 .uif-headerText-span");
220         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
221         selenium.mouseOut("css=#ConfigurationTestView-Help-Section1 h3 .uif-headerText-span");
222         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
223 
224         // test tooltip help of field
225         selenium.mouseOver("id=missing-tooltip-help_label");
226         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
227         selenium.mouseOut("id=missing-tooltip-help_label");
228         assertFalse(selenium.isElementPresent("css=.jquerybubblepopup"));
229     }
230 
231     /**
232      * Test the external help on the section and fields
233      */
234     // TODO: The test fails due to the javascript error
235     //   Error: Permission denied to access property 'close'
236     //   Source File: http://localhost:8080/kr-dev/krad/scripts/krad.utility.js
237     //   Line: 657
238     // when closing the help window.  It works when selenium is not running.
239     @Ignore
240     @Test
241     public void testExternalHelp() throws Exception {
242 
243         // test external help of section
244         selenium.click("css=input[title=\"Help for External Help\"]");
245         selenium.waitForPopUp("HelpWindow", "30000");
246         selenium.selectPopUp("HelpWindow");
247         assertEquals("http://www.kuali.org/?section", selenium.getLocation());
248         selenium.deselectPopUp();
249 
250         // test external help of field with label left
251         selenium.click("css=#field-label-left-external-help .uif-helpImage");
252         selenium.waitForPopUp("HelpWindow", "30000");
253         Thread.sleep(HELP_WINDOW_LOAD_DELAY);
254         selenium.selectPopUp("HelpWindow");
255         assertEquals("http://www.kuali.org/?label_left", selenium.getLocation());
256         selenium.deselectPopUp();
257 
258         // test external help of field with label right
259         selenium.click("css=#field-label-right-external-help .uif-helpImage");
260         selenium.waitForPopUp("HelpWindow", "30000");
261         Thread.sleep(HELP_WINDOW_LOAD_DELAY);
262         selenium.selectPopUp("HelpWindow");
263         assertEquals("http://www.kuali.org/?label_right", selenium.getLocation());
264         selenium.deselectPopUp();
265 
266         // test external help of field with label top and help URL from system parameters
267         // TODO: insert database data
268 //        selenium.click("css=#field-label-top-external-help .uif-helpImage");
269 //        selenium.waitForPopUp("HelpWindow", "30000");
270 //        Thread.sleep(HELP_WINDOW_LOAD_DELAY);
271         //        selenium.selectPopUp("HelpWindow");
272 //        assertEquals("http://www.kuali.org/?label_top", selenium.getLocation());
273 //        selenium.deselectPopUp();
274 
275         // test external help of standalone help widget
276         selenium.click("css=#standalone-external-help .uif-helpImage");
277         selenium.waitForPopUp("HelpWindow", "30000");
278         Thread.sleep(HELP_WINDOW_LOAD_DELAY);
279         selenium.selectPopUp("HelpWindow");
280         assertEquals("http://www.kuali.org/?label_top", selenium.getLocation());
281         selenium.deselectPopUp();
282     }
283 
284     /**
285      * Test the external help on the sub-section and display only fields
286      */
287     @Ignore
288     @Test
289     public void testDisplayOnlyExternalHelp() throws Exception {
290         //TODO: create test
291     }
292 
293     /**
294      * Test the external help on the section and fields with missing help URL
295      */
296     @Ignore
297     @Test
298     public void testMissingExternalHelp() throws Exception {
299         //TODO: create test
300     }
301 
302     /**
303      * Test the tooltip help and external help when both are specified
304      */
305     @Ignore
306     @Test
307     public void testTooltipExternalHelp() throws Exception {
308         //TODO: create test
309     }
310 
311     @After
312     public void tearDown() throws Exception {
313         selenium.stop();
314     }
315 
316 }