001 /*
002 * Copyright 2006-2012 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
017 package edu.samplu.travel.krad.test;
018
019 import com.thoughtworks.selenium.DefaultSelenium;
020 import org.junit.After;
021 import org.junit.Assert;
022 import org.junit.Before;
023 import org.junit.Ignore;
024 import org.junit.Test;
025 import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
026 import org.kuali.rice.krad.uif.component.Component;
027 import org.kuali.rice.krad.uif.view.View;
028
029 import static junit.framework.Assert.*;
030
031 /**
032 * test that configuration test view items work as expected
033 *
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 */
036 public class ConfigurationTestViewIT {
037 private DefaultSelenium selenium;
038 /** bean id prefix in used in view */
039 private String idPrefix = "ConfigurationTestView-ProgressiveRender-";
040 /** bean id suffix for add line controls */
041 String addLineIdSuffix = "InputField_add_control";
042 @Before
043 public void setUp() throws Exception {
044 selenium = new DefaultSelenium("localhost", 4444, "*chrome", System.getProperty("remote.public.url"));
045 selenium.start();
046 }
047
048 @Test
049 /**
050 * test for text input field label - style setting and refreshWhenChanged for components not in collection
051 */
052 public void testConfigurationTestView() throws Exception {
053 openConfigurationTestView();
054
055 // testing for https://groups.google.com/a/kuali.org/group/rice.usergroup.krad/browse_thread/thread/1e501d07c1141aad#
056 String styleValue = selenium.getAttribute("//span[@id='" + idPrefix + "TextInputField_label_span']@style");
057 // log.info("styleValue is " + styleValue);
058 Assert.assertTrue(idPrefix + "textInputField label does not contain expected style", styleValue.replace(" ", "").contains(
059 "color:red"));
060
061 // testing for refreshWhenChanged when using spel expressions
062 selenium.selectFrame("iframeportlet");
063 // get current list of options
064 String refreshTextSelectLocator = "id=" + idPrefix + "RefreshTextField_control";
065 String[] options1 = selenium.getSelectOptions(refreshTextSelectLocator);
066 String dropDownSelectLocator = "id=" + idPrefix + "DropDown_control";
067 selenium.select(dropDownSelectLocator, "label=Vegetables");
068 selenium.click("//option[@value='Vegetables']");
069 Thread.sleep(3000);
070 //get list of options after change
071 String[] options2 = selenium.getSelectOptions(refreshTextSelectLocator);
072 //verify that the change has occurred
073 assertFalse(options1[options1.length - 1].equalsIgnoreCase(options2[options2.length - 1]));
074 //confirm that control gets disabled
075 selenium.select(dropDownSelectLocator, "label=None");
076 Thread.sleep(3000);
077 assertEquals("true", selenium.getAttribute(refreshTextSelectLocator+ "@disabled"));
078
079 }
080
081 /**
082 * open the configuration test view page
083 */
084 private void openConfigurationTestView() {
085 selenium.open("/kr-dev/portal.do");
086 selenium.type("name=__login_user", "admin");
087 selenium.click("css=input[type=\"submit\"]");
088 selenium.waitForPageToLoad("30000");
089 selenium.click("link=KRAD");
090 selenium.waitForPageToLoad("30000");
091 selenium.isElementPresent("link=Configuration Test View");
092 selenium.click("link=Configuration Test View");
093 selenium.waitForPageToLoad("30000");
094 }
095
096 /**
097 * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
098 * a specific time is set
099 */
100 @Test
101 public void testAddLineWithSpecificTime() throws Exception{
102 openConfigurationTestView();
103 confirmAddLineControlsPresent();
104
105 String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
106 selenium.focus(startTimeId);
107 String inputTime = "7:06";
108 selenium.type(startTimeId, inputTime);
109
110 String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
111 selenium.click(amPmSelectLocator);
112 selenium.select(amPmSelectLocator, "label=PM");
113 assertEquals("PM", selenium.getSelectedLabel(amPmSelectLocator));
114
115 Thread.sleep(5000); //allow for ajax refresh
116 selenium.click("css=div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
117 Thread.sleep(5000); //allow for line to be added
118
119 //confirm that line has been added
120 assertTrue("line is not present", selenium.isElementPresent("//input[@value='7:06']"));
121 }
122
123 /**
124 * test adding a line to a collection which has the property refreshWhenChangedPropertyNames
125 * set on more than one component.
126 */
127 @Test
128 public void testAddLineWithAllDay() throws Exception{
129 openConfigurationTestView();
130 confirmAddLineControlsPresent();
131
132 String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
133 selenium.focus(startTimeId);
134 String inputTime = "5:20";
135 selenium.type(startTimeId, inputTime);
136
137 String allDaySelector = "id=" + idPrefix + "AllDay" + addLineIdSuffix;
138 selenium.focus(allDaySelector);
139 Thread.sleep(5000); //allow for ajax refresh
140 selenium.click(allDaySelector);
141
142 String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
143 selenium.click(amPmSelectLocator);
144 selenium.select(amPmSelectLocator, "label=PM");
145 assertEquals("PM", selenium.getSelectedLabel(amPmSelectLocator));
146
147 Thread.sleep(5000); //allow for ajax refresh
148 selenium.click("css=div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
149 Thread.sleep(5000); //allow for line to be added
150
151 //confirm that line has been added
152 assertTrue("line is not present", selenium.isElementPresent("//input[@value='5:20']"));
153 }
154
155 /**
156 * verify that add line controls are present
157 */
158 private void confirmAddLineControlsPresent() {
159 String[] addLineIds = {"StartTime", "StartTimeAmPm", "AllDay"};
160
161 for (String id: addLineIds) {
162 String tagId = "id=" + idPrefix + id + addLineIdSuffix;
163 assertTrue("Did not find id " + tagId, selenium.isElementPresent(tagId));
164 }
165 }
166
167 /**
168 * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
169 * a specific time is set
170 */
171 @Test
172 @Ignore("count rows through CSS or XPATH fails")
173 public void testAddLineAllDay() throws Exception{
174 openConfigurationTestView();
175 confirmAddLineControlsPresent();
176
177 //store number of rows before adding the lines
178 String cssCountRows = "div#ConfigurationTestView-ProgressiveRender-TimeInfoSection.uif-group div#ConfigurationTestView-ProgressiveRender-TimeInfoSection_disclosureContent.uif-disclosureContent table tbody tr";
179 int rowCount = (selenium.getCssCount(cssCountRows)).intValue();
180
181 String allDayId = "id=" + idPrefix + "AllDay" + addLineIdSuffix;
182 selenium.focus(allDayId);
183 Thread.sleep(5000); //allow for ajax refresh
184 selenium.click(allDayId);
185 selenium.click("css=div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
186 Thread.sleep(5000); //allow for line to be added
187
188 //confirm that line has been added (by checking for the new delete button)
189 assertEquals("line was not added", rowCount + 1, (selenium.getCssCount(cssCountRows)).intValue());
190 }
191
192
193 @After
194 public void tearDown() throws Exception {
195 selenium.stop();
196 }
197 }