View Javadoc

1   /*
2    * Copyright 2006-2012 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  
17  package edu.samplu.travel.krad.test;
18  
19  import com.thoughtworks.selenium.DefaultSelenium;
20  import org.junit.After;
21  import org.junit.Assert;
22  import org.junit.Before;
23  import org.junit.Ignore;
24  import org.junit.Test;
25  import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
26  import org.kuali.rice.krad.uif.component.Component;
27  import org.kuali.rice.krad.uif.view.View;
28  
29  import static junit.framework.Assert.*;
30  
31  /**
32   * test that configuration test view items work as expected
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class ConfigurationTestViewIT {
37      private DefaultSelenium selenium;
38      /** bean id prefix in used in view */
39      private String idPrefix = "ConfigurationTestView-ProgressiveRender-";
40      /** bean id suffix for add line controls */
41      String addLineIdSuffix = "InputField_add_control";
42      @Before
43  	public void setUp() throws Exception {
44  		selenium = new DefaultSelenium("localhost", 4444, "*chrome", System.getProperty("remote.public.url"));
45  		selenium.start();
46  	}
47  
48  	@Test
49      /**
50       * test for text input field label - style setting and refreshWhenChanged for components not in collection
51       */
52  	public void testConfigurationTestView() throws Exception {
53          openConfigurationTestView();
54  
55          // testing for https://groups.google.com/a/kuali.org/group/rice.usergroup.krad/browse_thread/thread/1e501d07c1141aad#
56          String styleValue = selenium.getAttribute("//span[@id='" + idPrefix + "TextInputField_label_span']@style");
57          // log.info("styleValue is " + styleValue);
58          Assert.assertTrue(idPrefix + "textInputField label does not contain expected style", styleValue.replace(" ", "").contains(
59                  "color:red"));
60  
61          // testing for refreshWhenChanged when using spel expressions
62          selenium.selectFrame("iframeportlet");
63          // get current list of options
64          String refreshTextSelectLocator = "id=" + idPrefix + "RefreshTextField_control";
65          String[] options1 = selenium.getSelectOptions(refreshTextSelectLocator);
66          String dropDownSelectLocator = "id=" + idPrefix + "DropDown_control";
67          selenium.select(dropDownSelectLocator, "label=Vegetables");
68          selenium.click("//option[@value='Vegetables']");
69          Thread.sleep(3000);
70          //get list of options after change
71          String[] options2 = selenium.getSelectOptions(refreshTextSelectLocator);
72          //verify that the change has occurred
73          assertFalse(options1[options1.length - 1].equalsIgnoreCase(options2[options2.length - 1]));
74          //confirm that control gets disabled
75          selenium.select(dropDownSelectLocator, "label=None");
76          Thread.sleep(3000);
77          assertEquals("true", selenium.getAttribute(refreshTextSelectLocator+ "@disabled"));
78  
79  	}
80  
81      /**
82       * open the configuration test view page
83       */
84      private void openConfigurationTestView() {
85          selenium.open("/kr-dev/portal.do");
86          selenium.type("name=__login_user", "admin");
87          selenium.click("css=input[type=\"submit\"]");
88          selenium.waitForPageToLoad("30000");
89          selenium.click("link=KRAD");
90          selenium.waitForPageToLoad("30000");
91          selenium.isElementPresent("link=Configuration Test View");
92          selenium.click("link=Configuration Test View");
93          selenium.waitForPageToLoad("30000");
94      }
95  
96      /**
97       * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
98       * a specific time is set
99       */
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 }