001 /**
002 * Copyright 2005-2011 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 */
016 package edu.samplu.krad.configview;
017
018 import org.junit.After;
019 import org.junit.Before;
020 import org.junit.Ignore;
021 import org.junit.Test;
022
023 import com.thoughtworks.selenium.DefaultSelenium;
024 import com.thoughtworks.selenium.Selenium;
025
026 import static org.junit.Assert.*;
027
028 /**
029 * Test the help widget
030 *
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033 public class HelpIT {
034 private Selenium selenium;
035
036 // Delay in milliseconds used to allow the help window reload the new help page.
037 // waitForPopUp will not work since the window already exists.
038 private long HELP_WINDOW_LOAD_DELAY = 3000;
039
040 @Before
041 public void setUp() throws Exception {
042 System.setProperty("remote.public.url", "http://localhost:8080/kr-dev/kr-krad/configuration-test-view-uif-controller?viewId=ConfigurationTestView-Help&methodToCall=start");
043 selenium = new DefaultSelenium("localhost", 4444, "*firefox", System.getProperty("remote.public.url"));
044 selenium.start();
045
046 // Login
047 selenium.open(System.getProperty("remote.public.url"));
048 assertEquals("Login", selenium.getTitle());
049 selenium.type("__login_user", "admin");
050 selenium.click("//input[@value='Login']");
051 selenium.waitForPageToLoad("30000");
052 }
053
054 /**
055 * Test the tooltip and external help on the view
056 */
057 @Test
058 public void testViewHelp() throws Exception {
059 // test tooltip help
060 selenium.mouseOver("css=h1 .uif-headerText-span");
061 assertEquals("Sample text for view help", selenium.getText("css=td.jquerybubblepopup-innerHtml"));
062
063 // test external help
064 selenium.click("css=input[title=\"Help for Configuration Test View - Help\"]");
065 selenium.waitForPopUp("HelpWindow", "30000");
066 selenium.selectPopUp("HelpWindow");
067 assertEquals("http://www.kuali.org/?view", selenium.getLocation());
068 selenium.deselectPopUp();
069 }
070
071 /**
072 * Test the tooltip and external help on the page
073 */
074 @Test
075 public void testPageHelp() throws Exception {
076 // test tooltip help
077 selenium.mouseOver("css=h2 .uif-headerText-span");
078 assertEquals("Sample text for page help", selenium.getText("css=td.jquerybubblepopup-innerHtml"));
079
080 // test external help
081 selenium.click("css=input[title=\"Help for Help Page\"]");
082 selenium.waitForPopUp("HelpWindow", "30000");
083 selenium.selectPopUp("HelpWindow");
084 assertEquals("http://www.kuali.org/?page", selenium.getLocation());
085 selenium.deselectPopUp();
086 }
087
088 /**
089 * Test the tooltip help on the section and fields
090 */
091 @Test
092 public void testTooltipHelp() throws Exception {
093 // verify that no tooltips are displayed initially
094 if (selenium.isElementPresent("css=td:contains(\"Sample text for section help - tooltip help\")")) {
095 assertFalse(selenium.isVisible("css=td:contains(\"Sample text for section help - tooltip help\")"));
096 }
097 if (selenium.isElementPresent("css=td:contains(\"Sample text for field help - label left\")")) {
098 assertFalse(selenium.isVisible("css=td:contains(\"Sample text for field help - label left\")"));
099 }
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 }