001 /*
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package edu.samplu.krad.demo.uif.library;
017
018 import org.kuali.rice.testtools.selenium.JiraAwareFailureUtil;
019 import org.junit.Assert;
020 import org.junit.Rule;
021 import org.junit.Test;
022 import org.junit.rules.ExpectedException;
023 import org.kuali.rice.krad.uif.UifConstants;
024 import org.openqa.selenium.By;
025 import org.openqa.selenium.WebElement;
026
027 /**
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030 public class DemoLibraryFieldsDataSmokeTest extends DemoLibraryBase {
031
032 /**
033 * /kr-krad/kradsampleapp?viewId=Demo-DataField-View&methodToCall=start
034 */
035 public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-DataField-View&methodToCall=start";
036 public static final String DIV_DATA_LABEL_DATA_FIELD_1 = "div[data-label='DataField 1']";
037
038 @Rule
039 public ExpectedException exception = ExpectedException.none();
040
041 @Override
042 public String getBookmarkUrl() {
043 return BOOKMARK_URL;
044 }
045
046 @Override
047 protected void navigate() throws Exception {
048 navigateToLibraryDemo("Fields", "Data Field");
049 }
050
051 protected void testDataFieldDefault() throws Exception {
052 WebElement exampleDiv = navigateToExample("Demo-DataField-Example1");
053 WebElement field = findElement(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv);
054
055 String fieldId = field.getAttribute("id");
056 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
057
058 assertIsVisible("#" + fieldId);
059 assertIsVisible("label[for='" + controlId + "']");
060 WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
061 if (!label.getText().contains("DataField 1:")) {
062 fail("Label text does not match");
063 }
064
065 assertIsVisible("#" + controlId);
066 assertTextPresent("1001", "#" + controlId, "DataField value not correct");
067
068 // validate that the value comes after the label
069 findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + span[id='" + controlId + "']"),
070 exampleDiv);
071 }
072
073 protected void testDataFieldLabelTop() throws Exception {
074 WebElement exampleDiv = navigateToExample("Demo-DataField-Example2");
075 WebElement field = findElement(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv);
076
077 String fieldId = field.getAttribute("id");
078 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
079
080 assertIsVisible("#" + fieldId);
081 assertIsVisible("label[for='" + controlId + "']");
082 WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
083 if (!label.getText().contains("DataField 1:")) {
084 fail("Label text does not match");
085 }
086
087 WebElement labelSpan = findElement(By.cssSelector("span[data-label_for='" + fieldId + "']"), field);
088 // top and bottom add the uif-labelBlock class
089 if (!labelSpan.getAttribute("class").contains("uif-labelBlock")) {
090 fail("Label span does not contain the appropriate class expected");
091 }
092 }
093
094 protected void testDataFieldLabelRight() throws Exception {
095 WebElement exampleDiv = navigateToExample("Demo-DataField-Example3");
096 WebElement field = findElement(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv);
097
098 String fieldId = field.getAttribute("id");
099 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
100
101 assertIsVisible("#" + controlId);
102 assertTextPresent("1001", "#" + controlId, "DataField value not correct");
103
104 assertIsVisible("#" + fieldId);
105 assertIsVisible("label[for='" + controlId + "']");
106 WebElement label = findElement(By.cssSelector("[for='" + controlId + "']"), field);
107 if (!label.getText().contains("DataField 1")) {
108 fail("Label text does not match");
109 }
110
111 // validate that the label comes after the value
112 findElement(By.cssSelector("span[id='" + controlId + "'] + span[data-label_for='" + fieldId + "']"),
113 exampleDiv);
114 }
115
116 protected void testDataFieldDefaultValue() throws Exception {
117 String valueText = textValueUnderTest("Demo-DataField-Example4", "DataField 2");
118 if(!"2012".equals(valueText)) {
119 JiraAwareFailureUtil.fail("Fields Data Field Default Value 2012 not displayed", this);
120 }
121 }
122
123 protected void testDataFieldAppendProperty() throws Exception {
124 String valueText = textValueUnderTest("Demo-DataField-Example5", "DataField 1");
125 Assert.assertTrue(valueText.endsWith("ID Val"));
126 }
127
128 protected void testDataFieldReplaceProperty() throws Exception {
129 String valueText = textValueUnderTest("Demo-DataField-Example6", "DataField 1");
130 Assert.assertEquals("ID Val", valueText);
131 }
132
133 protected void testDataFieldReplacePropertyWithField() throws Exception {
134 String valueText = textValueUnderTest("Demo-DataField-Example7", "DataField 1");
135 Assert.assertEquals("My Book Title", valueText);
136 }
137
138 protected void testDataFieldAppendPropertyWithField() throws Exception {
139 String valueText = textValueUnderTest("Demo-DataField-Example8", "DataField 1");
140 Assert.assertEquals("1001 *-* My Book Title", valueText);
141 }
142
143 protected void testDataFieldApplyFullMask() throws Exception {
144 String valueText = textValueUnderTest("Demo-DataField-Example9", "DataField 1");
145 Assert.assertEquals("*********", valueText);
146 }
147
148 protected void testDataFieldApplyPartialMask() throws Exception {
149 String valueText = textValueUnderTest("Demo-DataField-Example10", "DataField 1");
150 Assert.assertEquals("**01", valueText);
151 }
152
153 protected void testDataFieldHideProperty() throws Exception {
154 WebElement exampleDiv = navigateToExample("Demo-DataField-Example11");
155
156 if (findElements(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv).size() > 0) {
157 failableFail(DIV_DATA_LABEL_DATA_FIELD_1 + " not hidden");
158 }
159 }
160
161 private String textValueUnderTest(String example, String testLabel) throws Exception {
162 WebElement exampleDiv = navigateToExample(example);
163 WebElement field = findElement(By.cssSelector("div[data-label='" + testLabel + "']"), exampleDiv);
164
165 String fieldId = field.getAttribute("id");
166 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
167
168 assertIsVisible("#" + fieldId);
169 assertIsVisible("label[for='" + controlId + "']");
170 WebElement label = findElement(By.cssSelector("[for='" + controlId + "']"), field);
171 if (!label.getText().contains(testLabel)) {
172 fail("Label text does not match");
173 }
174
175 assertIsVisible("#" + controlId);
176
177 return findElement(By.id(controlId), field).getText();
178 }
179
180 protected void testDataFieldExamples() throws Exception {
181 testDataFieldDefault();
182 testDataFieldLabelTop();
183 testDataFieldLabelRight();
184 testDataFieldDefaultValue();
185 testDataFieldAppendProperty();
186 testDataFieldReplaceProperty();
187 testDataFieldReplacePropertyWithField();
188 testDataFieldAppendPropertyWithField();
189 testDataFieldApplyFullMask();
190 testDataFieldApplyPartialMask();
191 testDataFieldHideProperty();
192 }
193
194 @Test
195 public void testDataFieldExamplesBookmark() throws Exception {
196 testDataFieldExamples();
197 passed();
198 }
199
200 @Test
201 public void testDataFieldExamplesNav() throws Exception {
202 testDataFieldExamples();
203 passed();
204 }
205
206 @Test
207 public void testDataFieldDefaultBookmark() throws Exception {
208 testDataFieldDefault();
209 passed();
210 }
211
212 @Test
213 public void testDataFieldDefaultNav() throws Exception {
214 testDataFieldDefault();
215 passed();
216 }
217
218 @Test
219 public void testDataFieldLabelTopBookmark() throws Exception {
220 testDataFieldLabelTop();
221 passed();
222 }
223
224 @Test
225 public void testDataFieldLabelTopNav() throws Exception {
226 testDataFieldLabelTop();
227 passed();
228 }
229
230 @Test
231 public void testDataFieldLabelRightBookmark() throws Exception {
232 testDataFieldLabelRight();
233 passed();
234 }
235
236 @Test
237 public void testDataFieldLabelRightNav() throws Exception {
238 testDataFieldLabelRight();
239 passed();
240 }
241
242 @Test
243 public void testDataFieldDefaultValueBookmark() throws Exception {
244 testDataFieldDefaultValue();
245 passed();
246 }
247
248 @Test
249 public void testDataFieldDefaultValueNav() throws Exception {
250 testDataFieldDefaultValue();
251 passed();
252 }
253
254 @Test
255 public void testDataFieldAppendPropertyBookmark() throws Exception {
256 testDataFieldAppendProperty();
257 passed();
258 }
259
260 @Test
261 public void testDataFieldAppendPropertyNav() throws Exception {
262 testDataFieldAppendProperty();
263 passed();
264 }
265
266 @Test
267 public void testDataFieldReplacePropertyBookmark() throws Exception {
268 testDataFieldReplaceProperty();
269 passed();
270 }
271
272 @Test
273 public void testDataFieldReplacePropertyNav() throws Exception {
274 testDataFieldReplaceProperty();
275 passed();
276 }
277
278 @Test
279 public void testDataFieldReplacePropertyWithFieldBookmark() throws Exception {
280 testDataFieldReplacePropertyWithField();
281 passed();
282 }
283
284 @Test
285 public void testDataFieldReplacePropertyWithFieldNav() throws Exception {
286 testDataFieldReplacePropertyWithField();
287 passed();
288 }
289
290 @Test
291 public void testDataFieldAppendPropertyWithFieldBookmark() throws Exception {
292 testDataFieldAppendPropertyWithField();
293 passed();
294 }
295
296 @Test
297 public void testDataFieldAppendPropertyWithFieldNav() throws Exception {
298 testDataFieldAppendPropertyWithField();
299 passed();
300 }
301
302 @Test
303 public void testDataFieldApplyFullMaskBookmark() throws Exception {
304 testDataFieldApplyFullMask();
305 passed();
306 }
307
308 @Test
309 public void testDataFieldApplyFullMaskNav() throws Exception {
310 testDataFieldApplyFullMask();
311 passed();
312 }
313
314 @Test
315 public void testDataFieldApplyPartialMaskBookmark() throws Exception {
316 testDataFieldApplyPartialMask();
317 passed();
318 }
319
320 @Test
321 public void testDataFieldApplyPartialMaskNav() throws Exception {
322 testDataFieldApplyPartialMask();
323 passed();
324 }
325
326 @Test
327 public void testDataFieldHidePropertyBookmark() throws Exception {
328 testDataFieldHideProperty();
329 passed();
330 }
331
332 @Test
333 public void testDataFieldHidePropertyNav() throws Exception {
334 testDataFieldHideProperty();
335 passed();
336 }
337 }