View Javadoc
1   /**
2    * Copyright 2005-2014 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 org.kuali.rice.krad.demo.uif.library.fields;
17  
18  import org.junit.Ignore;
19  import org.kuali.rice.krad.demo.uif.library.LibraryBase;
20  import org.kuali.rice.testtools.common.JiraAwareFailureUtils;
21  import org.junit.Assert;
22  import org.junit.Rule;
23  import org.junit.Test;
24  import org.junit.rules.ExpectedException;
25  import org.kuali.rice.krad.uif.UifConstants;
26  import org.openqa.selenium.By;
27  import org.openqa.selenium.WebElement;
28  
29  /**
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class LibraryFieldsDataAft extends LibraryBase {
33  
34      /**
35       * /kr-krad/kradsampleapp?viewId=Demo-DataFieldView&methodToCall=start
36       */
37      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-DataFieldView&methodToCall=start";
38      public static final String DIV_DATA_LABEL_DATA_FIELD_1 = "div[data-label='DataField 1']";
39  
40      @Rule
41      public ExpectedException exception = ExpectedException.none();
42  
43      @Override
44      public String getBookmarkUrl() {
45          return BOOKMARK_URL;
46      }
47  
48      @Override
49      protected void navigate() throws Exception {
50          navigateToLibraryDemo("Fields", "Data Field");
51      }
52  
53      protected void testDataFieldDefault() throws Exception {
54          WebElement exampleDiv = navigateToExample("Demo-DataField-Example1");
55          WebElement field = findElement(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv);
56  
57          String fieldId = field.getAttribute("id");
58          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
59  
60          assertIsVisible("#" + fieldId);
61          assertIsVisible("label[for='" + controlId + "']");
62          WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
63          if (!label.getText().contains("DataField 1:")) {
64              jiraAwareFail("Label text does not match");
65          }
66  
67          assertTextPresent("1001", "#" + fieldId, "DataField value not correct");
68  
69          // validate that the value comes after the label
70          findElement(By.xpath("//div/label[@data-label_for='" + fieldId + "']"));
71      }
72  
73      protected void testDataFieldLabelTop() throws Exception {
74          WebElement exampleDiv = navigateToExample("Demo-DataField-Example2");
75          WebElement field = findElement(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv);
76  
77          String fieldId = field.getAttribute("id");
78          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
79  
80          assertIsVisible("#" + fieldId);
81          assertIsVisible("label[for='" + controlId + "']");
82          WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
83          if (!label.getText().contains("DataField 1:")) {
84              jiraAwareFail("Label text does not match");
85          }
86      }
87  
88      protected void testDataFieldLabelRight() throws Exception {
89          WebElement exampleDiv = navigateToExample("Demo-DataField-Example3");
90          WebElement field = findElement(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv);
91  
92          String fieldId = field.getAttribute("id");
93          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
94  
95          assertTextPresent("1001", "#" + fieldId, "DataField value not correct");
96  
97          assertIsVisible("label[for='" + controlId + "']");
98          WebElement label = findElement(By.cssSelector("[for='" + controlId + "']"), field);
99          if (!label.getText().contains("DataField 1")) {
100             jiraAwareFail("Label text does not match");
101         }
102 
103         // validate that the label comes after the value
104         findElement(By.xpath("//div/label[@data-label_for='" + fieldId + "']"));
105     }
106 
107     protected void testDataFieldDefaultValue() throws Exception {
108         String valueText = textValueUnderTest("Demo-DataField-Example4", "DataField 2");
109         if (!valueText.contains("2012")) {
110             jiraAwareFail("Fields Data Field Default Value 2012 not displayed");
111         }
112     }
113     
114     protected void testDataFieldDefaultValueFinderClass() throws Exception {
115         String valueText = textValueUnderTest("Demo-DataField-Example12", "DataField 2");
116         if (!valueText.contains("Value returned from org.kuali.rice.krad.demo.uif.library.DemoValuesFinder")) {
117             jiraAwareFail("Fields Default Value Finder Field not displayed");
118         }
119     }
120 
121     protected void testDataFieldAppendProperty() throws Exception {
122         String valueText = textValueUnderTest("Demo-DataField-Example5", "DataField 1");
123         assertTrue(valueText.endsWith("ID Val"));
124     }
125 
126     protected void testDataFieldReplaceProperty() throws Exception {
127         String valueText = textValueUnderTest("Demo-DataField-Example6", "DataField 1");
128         assertTrue(valueText.contains("ID Val"));
129     }
130 
131     protected void testDataFieldReplacePropertyWithField() throws Exception {
132         String valueText = textValueUnderTest("Demo-DataField-Example7", "DataField 1");
133         assertTrue(valueText.contains("My Book Title"));
134     }
135 
136     protected void testDataFieldAppendPropertyWithField() throws Exception {
137         String valueText = textValueUnderTest("Demo-DataField-Example8", "DataField 1");
138         assertTrue(valueText.contains("1001 *-* My Book Title"));
139     }
140 
141     protected void testDataFieldApplyFullMask() throws Exception {
142         String valueText = textValueUnderTest("Demo-DataField-Example9", "DataField 1");
143         assertTrue("1001 not masked to *********", valueText.contains("*********"));
144     }
145 
146     protected void testDataFieldApplyPartialMask() throws Exception {
147         String valueText = textValueUnderTest("Demo-DataField-Example10", "DataField 1");
148         assertTrue("1001 not masked to **01", valueText.contains("**01"));
149     }
150 
151     protected void testDataFieldHideProperty() throws Exception {
152         WebElement exampleDiv = navigateToExample("Demo-DataField-Example11");
153 
154         if (findElements(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv).size() > 0) {
155             jiraAwareFail(DIV_DATA_LABEL_DATA_FIELD_1 + " not hidden");
156         }
157     }
158 
159     private String textValueUnderTest(String example, String testLabel) throws Exception {
160         WebElement exampleDiv = navigateToExample(example);
161         WebElement field = findElement(By.cssSelector("div[data-label='" + testLabel + "']"), exampleDiv);
162 
163         String fieldId = field.getAttribute("id");
164         String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
165 
166         assertIsVisible("#" + fieldId);
167         assertIsVisible("label[for='" + controlId + "']");
168         WebElement label = findElement(By.cssSelector("[for='" + controlId + "']"), field);
169         if (!label.getText().contains(testLabel)) {
170             jiraAwareFail("Label text does not match");
171         }
172 
173         return findElement(By.id(fieldId)).getText();
174     }
175 
176     protected void testDataFieldExamples() throws Exception {
177         testDataFieldDefault();
178 //        testDataFieldLabelTop(); // removed form demo
179 //        testDataFieldLabelRight(); // removed from demo
180         testDataFieldDefaultValue();
181         testDataFieldDefaultValueFinderClass();
182         testDataFieldAppendProperty();
183         testDataFieldReplaceProperty();
184         testDataFieldReplacePropertyWithField();
185         testDataFieldAppendPropertyWithField();
186         testDataFieldApplyFullMask();
187         testDataFieldApplyPartialMask();
188         testDataFieldHideProperty();
189     }
190 
191     @Test
192     @Ignore // just run the individual tests
193     public void testDataFieldExamplesBookmark() throws Exception {
194         testDataFieldExamples();
195         passed();
196     }
197 
198     @Test
199     @Ignore // just run the individual tests
200     public void testDataFieldExamplesNav() throws Exception {
201         testDataFieldExamples();
202         passed();
203     }
204 
205     @Test
206     public void testDataFieldDefaultBookmark() throws Exception {
207         testDataFieldDefault();
208         passed();
209     }
210 
211     @Test
212     public void testDataFieldDefaultNav() throws Exception {
213         testDataFieldDefault();
214         passed();
215     }
216 
217     @Test
218     public void testDataFieldDefaultValueBookmark() throws Exception {
219         testDataFieldDefaultValue();
220         passed();
221     }
222 
223     @Test
224     public void testDataFieldDefaultValueNav() throws Exception {
225         testDataFieldDefaultValue();
226         passed();
227     }
228     
229     @Test
230     public void testDataFieldDefaultValueFinderClassBookmark() throws Exception {
231         testDataFieldDefaultValueFinderClass();
232         passed();
233     }
234 
235     @Test
236     public void testDataFieldDefaultValueFinderClassNav() throws Exception {
237         testDataFieldDefaultValueFinderClass();
238         passed();
239     }
240 
241     @Test
242     public void testDataFieldAppendPropertyBookmark() throws Exception {
243         testDataFieldAppendProperty();
244         passed();
245     }
246 
247     @Test
248     public void testDataFieldAppendPropertyNav() throws Exception {
249         testDataFieldAppendProperty();
250         passed();
251     }
252 
253     @Test
254     public void testDataFieldReplacePropertyBookmark() throws Exception {
255         testDataFieldReplaceProperty();
256         passed();
257     }
258 
259     @Test
260     public void testDataFieldReplacePropertyNav() throws Exception {
261         testDataFieldReplaceProperty();
262         passed();
263     }
264 
265     @Test
266     public void testDataFieldReplacePropertyWithFieldBookmark() throws Exception {
267         testDataFieldReplacePropertyWithField();
268         passed();
269     }
270 
271     @Test
272     public void testDataFieldReplacePropertyWithFieldNav() throws Exception {
273         testDataFieldReplacePropertyWithField();
274         passed();
275     }
276 
277     @Test
278     public void testDataFieldAppendPropertyWithFieldBookmark() throws Exception {
279         testDataFieldAppendPropertyWithField();
280         passed();
281     }
282 
283     @Test
284     public void testDataFieldAppendPropertyWithFieldNav() throws Exception {
285         testDataFieldAppendPropertyWithField();
286         passed();
287     }
288 
289     @Test
290     public void testDataFieldApplyFullMaskBookmark() throws Exception {
291         testDataFieldApplyFullMask();
292         passed();
293     }
294 
295     @Test
296     public void testDataFieldApplyFullMaskNav() throws Exception {
297         testDataFieldApplyFullMask();
298         passed();
299     }
300 
301     @Test
302     public void testDataFieldApplyPartialMaskBookmark() throws Exception {
303         testDataFieldApplyPartialMask();
304         passed();
305     }
306 
307     @Test
308     public void testDataFieldApplyPartialMaskNav() throws Exception {
309         testDataFieldApplyPartialMask();
310         passed();
311     }
312 
313     @Test
314     public void testDataFieldHidePropertyBookmark() throws Exception {
315         testDataFieldHideProperty();
316         passed();
317     }
318 
319     @Test
320     public void testDataFieldHidePropertyNav() throws Exception {
321         testDataFieldHideProperty();
322         passed();
323     }
324 }