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.UpgradedSeleniumITBase;
21  import org.junit.Assert;
22  import org.junit.Ignore;
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 ConfigurationTestViewIT extends UpgradedSeleniumITBase {
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  	@Test
43      /**
44       * test for text input field label - style setting and refreshWhenChanged for components not in collection
45       */
46  	public void testConfigurationTestView() throws Exception {
47          openConfigurationTestView();
48  
49          // testing for https://groups.google.com/a/kuali.org/group/rice.usergroup.krad/browse_thread/thread/1e501d07c1141aad#
50          String styleValue = getAttribute("//span[@id='" + idPrefix + "TextInputField_label_span']@style");
51          // log.info("styleValue is " + styleValue);
52          Assert.assertTrue(idPrefix + "textInputField label does not contain expected style", styleValue.replace(" ", "").contains(
53                  "color:red"));
54  
55          // testing for refreshWhenChanged when using spel expressions
56          selectFrame("iframeportlet");
57          // get current list of options
58          String refreshTextSelectLocator = "id=" + idPrefix + "RefreshTextField_control";
59          String[] options1 = getSelectOptions(refreshTextSelectLocator);
60          String dropDownSelectLocator = "id=" + idPrefix + "DropDown_control";
61          select(dropDownSelectLocator, "label=Vegetables");
62          waitAndClick("//option[@value='Vegetables']");
63          Thread.sleep(3000);
64          //get list of options after change
65          String[] options2 = getSelectOptions(refreshTextSelectLocator);
66          //verify that the change has occurred
67          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]));
68          //confirm that control gets disabled
69          select(dropDownSelectLocator, "label=None");
70          Thread.sleep(3000);
71          assertEquals("true", getAttribute(refreshTextSelectLocator+ "@disabled"));
72  
73  	}
74  
75      /**
76       * open the configuration test view page
77       */
78      private void openConfigurationTestView() throws InterruptedException {
79          waitAndClick("link=KRAD");
80          waitAndClick("link=Configuration Test View");
81          waitForPageToLoad();
82      }
83  
84      /**
85       * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
86       * a specific time is set
87       */
88      @Test
89      public void testAddLineWithSpecificTime() throws Exception{
90          openConfigurationTestView();
91          confirmAddLineControlsPresent();
92          
93          String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
94          selectFrame("iframeportlet");
95          focus(startTimeId);
96          String inputTime = "7:06";
97          waitAndType(startTimeId, inputTime);
98          String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
99         // waitAndClick(amPmSelectLocator);
100         select(amPmSelectLocator, "label=PM");
101         assertEquals("PM", getSelectedLabel(amPmSelectLocator));
102         Thread.sleep(5000); //allow for ajax refresh        
103         waitAndClick("//button");
104         Thread.sleep(5000); //allow for line to be added
105         //confirm that line has been added
106         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", isElementPresent("//input[@value='7:06']"));
107         
108     }
109 
110     /**
111          * test adding a line to a collection which  has the property refreshWhenChangedPropertyNames
112          * set on more than one component.
113          */
114         @Test
115         public void testAddLineWithAllDay() throws Exception{
116             openConfigurationTestView();
117             confirmAddLineControlsPresent();
118 
119             String startTimeId = "id=" +idPrefix + "StartTime" + addLineIdSuffix;
120             selectFrame("iframeportlet");
121             focus(startTimeId);
122             String inputTime = "5:20";
123             waitAndType(startTimeId, inputTime);
124 
125             String allDaySelector = "id=" + idPrefix + "AllDay" + addLineIdSuffix;
126             focus(allDaySelector);
127             Thread.sleep(5000); //allow for ajax refresh
128             waitAndClick(allDaySelector);
129             
130             //Since All Day checkbox is selected, asserting PM with default AM would fails the test. Commenting out.
131             //Or Else put the commented piece of code before selecting the checkbox. 
132             /*
133             String amPmSelectLocator = "id=" + idPrefix + "StartTimeAmPm" + addLineIdSuffix;
134             waitAndClick(amPmSelectLocator);
135             select(amPmSelectLocator, "label=PM");
136             assertEquals("PM", selenium.getSelectedLabel(amPmSelectLocator));
137              */
138           
139             Thread.sleep(5000); //allow for ajax refresh
140             waitAndClick("css=div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
141             Thread.sleep(5000); //allow for line to be added           
142             
143             //Since All Day checkbox is selected, asserting Start time's presence would fails the test. Commenting out.
144             //assertTrue("line is not present", isElementPresent("//input[@value='5:20']"));
145         }
146 
147     /**
148      * verify that add line controls are present
149      */
150     private void confirmAddLineControlsPresent() {
151         String[] addLineIds = {"StartTime", "StartTimeAmPm", "AllDay"};
152 
153         for (String id: addLineIds) {
154             String tagId = "id=" + idPrefix + id + addLineIdSuffix;
155            assertTrue("Did not find id " + tagId, isElementPresent(tagId));
156         }
157     }
158 
159     /**
160      * test adding a line to a collection which uses an add line that has spring expressions that are evaluated on refresh
161      * a specific time is set
162      */
163     @Test
164     @Ignore("count rows through CSS or XPATH fails")
165     public void testAddLineAllDay() throws Exception{
166         openConfigurationTestView();
167         confirmAddLineControlsPresent();
168 
169         //store number of rows before adding the lines
170         String cssCountRows = "div#ConfigurationTestView-ProgressiveRender-TimeInfoSection.uif-group div#ConfigurationTestView-ProgressiveRender-TimeInfoSection_disclosureContent.uif-disclosureContent table tbody tr";
171         int rowCount = (getCssCount(cssCountRows)).intValue();
172 
173         String allDayId = "id=" + idPrefix + "AllDay" + addLineIdSuffix;
174         focus(allDayId);
175         Thread.sleep(5000); //allow for ajax refresh
176         waitAndClick(allDayId);
177         waitAndClick("css=div#ConfigurationTestView-ProgressiveRender-TimeInfoSection button");
178         Thread.sleep(5000); //allow for line to be added
179 
180         //confirm that line has been added (by checking for the new delete button)
181         assertEquals("line was not added", rowCount + 1, (getCssCount(cssCountRows)).intValue());
182     }
183 }