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 * verify that add line controls are present
125 */
126 private void confirmAddLineControlsPresent() {
127 String[] addLineIds = {"StartTime", "StartTimeAmPm", "AllDay"};
128
129 for (String id: addLineIds) {
130 String tagId = "id=" + idPrefix + id + addLineIdSuffix;
131 assertTrue("Did not find id " + tagId, selenium.isElementPresent(tagId));
132 }
133 }
134
135 /**
136 * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
137 * a specific time is set
138 */
139 @Test
140 @Ignore("count rows through CSS or XPATH fails")
141 public void testAddLineAllDay() throws Exception{
142 openConfigurationTestView();
143 confirmAddLineControlsPresent();
144
145 //store number of rows before adding the lines
146 String cssCountRows = "div#ConfigurationTestView-ProgressiveRender-TimeInfoSection.uif-group div#ConfigurationTestView-ProgressiveRender-TimeInfoSection_disclosureContent.uif-disclosureContent table tbody tr";
147 int rowCount = (selenium.getCssCount(cssCountRows)).intValue();
148
149 String allDayId = "id=" + idPrefix + "AllDay" + addLineIdSuffix;
150 selenium.focus(allDayId);
151 Thread.sleep(5000); //allow for ajax refresh
152 selenium.click(allDayId);
153 selenium.click("css=div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
154 Thread.sleep(5000); //allow for line to be added
155
156 //confirm that line has been added (by checking for the new delete button)
157 assertEquals("line was not added", rowCount + 1, (selenium.getCssCount(cssCountRows)).intValue());
158 }
159
160
161 @After
162 public void tearDown() throws Exception {
163 selenium.stop();
164 }
165 }