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 edu.samplu.common.ITUtil;
20  import edu.samplu.common.WebDriverLegacyITBase;
21  
22  import org.junit.Assert;
23  import org.junit.Test;
24  
25  import static junit.framework.Assert.*;
26  
27  /**
28   * test that configuration test view items work as expected
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class ConfigurationTestViewLegacyIT extends WebDriverLegacyITBase {
33      @Override
34      public String getTestUrl() {
35          return ITUtil.PORTAL;
36      }
37      /** bean id prefix in used in view */
38      private String idPrefix = "ConfigurationTestView-ProgressiveRender-";
39      /** bean id suffix for add line controls */
40      String addLineIdSuffix = "InputField_add_control";
41  
42      	
43      /**
44       * test for text input field label - style setting and refreshWhenChanged for components not in collection
45       */
46      @Test
47  	public void testConfigurationTestView() throws Exception {
48          openConfigurationTestView();
49  
50          selectFrame("iframeportlet");
51          // testing for https://groups.google.com/a/kuali.org/group/rice.usergroup.krad/browse_thread/thread/1e501d07c1141aad#
52          String styleValue = getAttributeByXpath("//span[@id='" + idPrefix + "TextInputField_label_span']","style");
53          // log.info("styleValue is " + styleValue);
54          Assert.assertTrue(idPrefix + "textInputField label does not contain expected style", styleValue.replace(" ", "").contains(
55                  "color:red"));
56  
57          // get current list of options
58          String refreshTextSelectLocator = "//select[@id='" + idPrefix + "RefreshTextField_control']";
59          String[] options1 = getSelectOptionsByXpath(refreshTextSelectLocator);
60          String dropDownSelectLocator = "//select[@id='" + idPrefix + "DropDown_control']";
61          selectByXpath(dropDownSelectLocator, "Vegetables");        
62          Thread.sleep(3000);
63          //get list of options after change
64          String[] options2 = getSelectOptionsByXpath(refreshTextSelectLocator);
65          //verify that the change has occurred
66          assertFalse("Field 1 selection did not change Field 2 options https://jira.kuali.org/browse/KULRICE-8163 Configuration Test View Conditional Options doesn't change Field 2 options based on Field 1 selection", options1[options1.length - 1].equalsIgnoreCase(options2[options2.length - 1]));
67          //confirm that control gets disabled
68          selectByXpath(dropDownSelectLocator, "None");
69          Thread.sleep(3000);
70          assertEquals("true", getAttributeByXpath(refreshTextSelectLocator, "disabled"));
71          passed();
72  	}
73  
74      /**
75       * open the configuration test view page
76       */
77      private void openConfigurationTestView() throws InterruptedException {
78          waitAndClickByLinkText("KRAD");
79          waitAndClickByLinkText("Configuration Test View");
80          waitForPageToLoad();
81      }
82  
83      /**
84       * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
85       * a specific time is set
86       */
87      @Test    
88      public void testAddLineWithSpecificTime() throws Exception{
89          openConfigurationTestView();
90          
91          selectFrame("iframeportlet");
92          
93          confirmAddLineControlsPresent();
94          
95          String startTimeId = "//*[@id='" +idPrefix + "StartTime" + addLineIdSuffix + "']";      
96  
97          String inputTime = "7:06";
98          waitAndTypeByXpath(startTimeId, inputTime);
99          String amPmSelectLocator = "//*[@id='" + idPrefix + "StartTimeAmPm" + addLineIdSuffix + "']";
100 
101         selectByXpath(amPmSelectLocator, "PM");
102         assertEquals("PM", getAttributeByXpath(amPmSelectLocator, "value"));
103         Thread.sleep(5000); //allow for ajax refresh        
104         waitAndClickByXpath("//button");
105         Thread.sleep(5000); //allow for line to be added
106         //confirm that line has been added
107         assertTrue("line (//input[@value='7:06'])is not present https://jira.kuali.org/browse/KULRICE-8162 Configuration Test View Time Info add line button doesn't addline", isElementPresentByXpath("//input[@value='7:06']"));
108         passed();
109     }
110 
111     /**
112      * test adding a line to a collection which has the property refreshWhenChangedPropertyNames set
113      * on more than one component.
114      */
115     @Test
116     public void testAddLineWithAllDay() throws Exception {
117         openConfigurationTestView();
118 
119         selectFrame("iframeportlet");
120 
121         confirmAddLineControlsPresent();
122 
123         String startTimeId = "//*[@id='" + idPrefix + "StartTime" + addLineIdSuffix + "']";
124 
125         String inputTime = "5:20";
126         waitAndTypeByXpath(startTimeId, inputTime);
127 
128         String allDaySelector = "//*[@id='" + idPrefix + "AllDay" + addLineIdSuffix + "']";
129 
130         Thread.sleep(5000); //allow for ajax refresh
131         waitAndClickByXpath(allDaySelector);
132 
133         Thread.sleep(5000); //allow for ajax refresh
134         waitAndClick("div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
135         Thread.sleep(5000); //allow for line to be added           
136         passed();
137     }
138 
139     /**
140      * verify that add line controls are present
141      */
142     private void confirmAddLineControlsPresent() {
143         String[] addLineIds = {"StartTime", "StartTimeAmPm", "AllDay"};
144 
145         for (String id: addLineIds) {
146            String tagId = "//*[@id='" + idPrefix + id + addLineIdSuffix + "']";
147            assertTrue("Did not find id " + tagId, isElementPresentByXpath(tagId));
148         }
149     }
150 
151     /**
152      * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
153      * a specific time is set
154      */
155     @Test  
156     public void testAddLineAllDay() throws Exception{
157         openConfigurationTestView();
158         
159         selectFrame("iframeportlet");
160         
161         confirmAddLineControlsPresent();
162 
163         //store number of rows before adding the lines
164         String cssCountRows = "div#ConfigurationTestView-ProgressiveRender-TimeInfoSection.uif-group div#ConfigurationTestView-ProgressiveRender-TimeInfoSection_disclosureContent.uif-disclosureContent table tbody tr";
165         int rowCount = (getCssCount(cssCountRows));
166 
167         String allDayId = "//*[@id='" + idPrefix + "AllDay" + addLineIdSuffix + "']";        
168         Thread.sleep(5000); //allow for ajax refresh
169         waitAndClickByXpath(allDayId);
170         waitAndClick("div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
171         Thread.sleep(5000); //allow for line to be added
172 
173         //confirm that line has been added (by checking for the new delete button)
174         assertEquals("line was not added", rowCount + 1, (getCssCount(cssCountRows)));
175         passed();
176     }
177 }