View Javadoc

1   /*
2    * Copyright 2005-2013 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  package edu.samplu.krad.demo.uif.library;
17  
18  import org.junit.Assert;
19  import org.junit.Test;
20  import org.kuali.rice.krad.uif.UifConstants;
21  import org.openqa.selenium.By;
22  import org.openqa.selenium.WebElement;
23  
24  /**
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  public class DemoLibraryDataFieldSmokeTest extends DemoLibraryBase {
28  
29      /**
30       * /kr-krad/kradsampleapp?viewId=Demo-DataField-View&methodToCall=start
31       */
32      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-DataField-View&methodToCall=start";
33  
34      @Override
35      public String getBookmarkUrl() {
36          return BOOKMARK_URL;
37      }
38  
39      @Override
40      protected void navigate() throws Exception {
41          navigateToLibraryDemo("Fields", "Data Field");
42      }
43  
44      protected void testDataFieldDefault() throws Exception {
45          WebElement exampleDiv = navigateToExample("Demo-DataField-Example1");
46          WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']"));
47  
48          String fieldId = field.getAttribute("id");
49          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
50  
51          assertIsVisible("#" + fieldId);
52          assertIsVisible("label[for='" + controlId + "']");
53  
54          WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']"));
55          if(!label.getText().contains("DataField 1:")){
56              fail("Label text does not match");
57          }
58  
59          assertIsVisible("#" + controlId);
60  
61          assertTextPresent("1001", "#" + controlId, "DataField value not correct");
62      }
63  
64      protected void testDataFieldLabelTop() throws Exception {
65          WebElement exampleDiv = navigateToExample("Demo-DataField-Example2");
66          WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']"));
67  
68          String fieldId = field.getAttribute("id");
69          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
70  
71          assertIsVisible("#" + fieldId);
72          assertIsVisible("label[for='" + controlId + "']");
73  
74          WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']"));
75          if(!label.getText().contains("DataField 1:")){
76              fail("Label text does not match");
77          }
78  
79          WebElement labelspan = field.findElement(By.cssSelector("span[data-label_for='" + fieldId + "']"));
80          // top and bottom add the uif-labelBlock class
81          if(!labelspan.getAttribute("class").contains("uif-labelBlock")){
82              fail("Label span does not contain the appropriate class expected");
83          }
84  
85          assertIsVisible("#" + controlId);
86      }
87  
88      protected void testDataFieldLabelRight() throws Exception {
89          WebElement exampleDiv = navigateToExample("Demo-DataField-Example3");
90          WebElement field = findElement(By.cssSelector("div[data-label='DataField 1']"), exampleDiv);
91  
92          String fieldId = field.getAttribute("id");
93          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
94  
95          assertIsVisible("#" + fieldId);
96          assertIsVisible("label[for='" + controlId + "']");
97  
98          WebElement label = findElement(By.cssSelector("[for='" + controlId + "']"), field);
99          if(!label.getText().contains("DataField 1")){
100             fail("Label text does not match");
101         }
102 
103         assertIsVisible("#" + controlId);
104 
105         // validate that the label comes after the value
106         findElement(By.cssSelector("span[id='" + controlId + "'] + span[data-label_for='" + fieldId + "']"), exampleDiv);
107     }
108 
109     protected void testDataFieldDefaultValue() throws Exception {
110         String valueText = textValueUnderTest("Demo-DataField-Example4", "DataField 2");
111         Assert.assertEquals("2012", valueText);
112     }
113 
114     protected void testDataFieldAppendProperty() throws Exception {
115         String valueText = textValueUnderTest("Demo-DataField-Example5", "DataField 1");
116         Assert.assertTrue(valueText.endsWith("ID Val"));
117     }
118 
119     protected void testDataFieldReplaceProperty() throws Exception {
120         String valueText = textValueUnderTest("Demo-DataField-Example6", "DataField 1");
121         Assert.assertEquals("ID Val", valueText);
122     }
123 
124     protected void testDataFieldReplacePropertyWithField() throws Exception {
125         String valueText = textValueUnderTest("Demo-DataField-Example7", "DataField 1");
126         Assert.assertEquals("My Book Title", valueText);
127     }
128 
129     protected void testDataFieldAppendPropertyWithField() throws Exception {
130         String valueText = textValueUnderTest("Demo-DataField-Example8", "DataField 1");
131         Assert.assertEquals("1001 *-* My Book Title", valueText);
132     }
133 
134     private String textValueUnderTest(String example, String testLabel) throws Exception {
135         WebElement exampleDiv = navigateToExample(example);
136         WebElement field = findElement(By.cssSelector("div[data-label='" + testLabel + "']"), exampleDiv);
137 
138         String fieldId = field.getAttribute("id");
139         String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
140 
141         assertIsVisible("#" + fieldId);
142         assertIsVisible("label[for='" + controlId + "']");
143 
144         WebElement label = findElement(By.cssSelector("[for='" + controlId + "']"), field);
145         if(!label.getText().contains(testLabel)){
146             fail("Label text does not match");
147         }
148 
149         assertIsVisible("#" + controlId);
150 
151         return findElement(By.id(controlId), field).getText();
152     }
153 
154     protected void testDataFieldExamples() throws Exception{
155         testDataFieldDefault();
156         testDataFieldLabelTop();
157         testDataFieldLabelRight();
158         testDataFieldDefaultValue();
159         testDataFieldAppendProperty();
160         testDataFieldReplaceProperty();
161         testDataFieldReplacePropertyWithField();
162         testDataFieldAppendPropertyWithField();
163     }
164 
165     @Test
166     public void testDataFieldExamplesBookmark() throws Exception {
167         testDataFieldExamples();
168         passed();
169     }
170 
171     @Test
172     public void testDataFieldExamplesNav() throws Exception {
173         testDataFieldExamples();
174         passed();
175     }
176 
177     @Test
178     public void testDataFieldDefaultBookmark() throws Exception {
179         testDataFieldDefault();
180         passed();
181     }
182 
183     @Test
184     public void testDataFieldDefaultNav() throws Exception {
185         testDataFieldDefault();
186         passed();
187     }
188 
189     @Test
190     public void testDataFieldLabelTopBookmark() throws Exception {
191         testDataFieldLabelTop();
192         passed();
193     }
194 
195     @Test
196     public void testDataFieldLabelTopNav() throws Exception {
197         testDataFieldLabelTop();
198         passed();
199     }
200 
201     @Test
202     public void testDataFieldLabelRightBookmark() throws Exception {
203         testDataFieldLabelRight();
204         passed();
205     }
206 
207     @Test
208     public void testDataFieldLabelRightNav() throws Exception {
209         testDataFieldLabelRight();
210         passed();
211     }
212 
213     @Test
214     public void testDataFieldDefaultValueBookmark() throws Exception {
215         testDataFieldDefaultValue();
216         passed();
217     }
218 
219     @Test
220     public void testDataFieldDefaultValueNav() throws Exception {
221         testDataFieldDefaultValue();
222         passed();
223     }
224 
225     @Test
226     public void testDataFieldAppendPropertyBookmark() throws Exception {
227         testDataFieldAppendProperty();
228         passed();
229     }
230 
231     @Test
232     public void testDataFieldAppendPropertyNav() throws Exception {
233         testDataFieldAppendProperty();
234         passed();
235     }
236 
237     @Test
238     public void testDataFieldReplacePropertyBookmark() throws Exception {
239         testDataFieldReplaceProperty();
240         passed();
241     }
242 
243     @Test
244     public void testDataFieldReplacePropertyNav() throws Exception {
245         testDataFieldReplaceProperty();
246         passed();
247     }
248 
249     @Test
250     public void testDataFieldReplacePropertyWithFieldBookmark() throws Exception {
251         testDataFieldReplacePropertyWithField();
252         passed();
253     }
254 
255     @Test
256     public void testDataFieldReplacePropertyWithFieldNav() throws Exception {
257         testDataFieldReplacePropertyWithField();
258         passed();
259     }
260 
261     @Test
262     public void testDataFieldAppendPropertyWithFieldBookmark() throws Exception {
263         testDataFieldAppendPropertyWithField();
264         passed();
265     }
266 
267     @Test
268     public void testDataFieldAppendPropertyWithFieldNav() throws Exception {
269         testDataFieldAppendPropertyWithField();
270         passed();
271     }
272 }