1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.samplu.krad.demo.uif.library;
17
18 import org.kuali.rice.testtools.selenium.JiraAwareFailureUtil;
19 import org.junit.Assert;
20 import org.junit.Rule;
21 import org.junit.Test;
22 import org.junit.rules.ExpectedException;
23 import org.kuali.rice.krad.uif.UifConstants;
24 import org.openqa.selenium.By;
25 import org.openqa.selenium.WebElement;
26
27
28
29
30 public class DemoLibraryFieldsDataSmokeTest extends DemoLibraryBase {
31
32
33
34
35 public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-DataField-View&methodToCall=start";
36 public static final String DIV_DATA_LABEL_DATA_FIELD_1 = "div[data-label='DataField 1']";
37
38 @Rule
39 public ExpectedException exception = ExpectedException.none();
40
41 @Override
42 public String getBookmarkUrl() {
43 return BOOKMARK_URL;
44 }
45
46 @Override
47 protected void navigate() throws Exception {
48 navigateToLibraryDemo("Fields", "Data Field");
49 }
50
51 protected void testDataFieldDefault() throws Exception {
52 WebElement exampleDiv = navigateToExample("Demo-DataField-Example1");
53 WebElement field = findElement(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv);
54
55 String fieldId = field.getAttribute("id");
56 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
57
58 assertIsVisible("#" + fieldId);
59 assertIsVisible("label[for='" + controlId + "']");
60 WebElement label = findElement(By.cssSelector("label[for='" + controlId + "']"), field);
61 if (!label.getText().contains("DataField 1:")) {
62 fail("Label text does not match");
63 }
64
65 assertIsVisible("#" + controlId);
66 assertTextPresent("1001", "#" + controlId, "DataField value not correct");
67
68
69 findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + span[id='" + controlId + "']"),
70 exampleDiv);
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 fail("Label text does not match");
85 }
86
87 WebElement labelSpan = findElement(By.cssSelector("span[data-label_for='" + fieldId + "']"), field);
88
89 if (!labelSpan.getAttribute("class").contains("uif-labelBlock")) {
90 fail("Label span does not contain the appropriate class expected");
91 }
92 }
93
94 protected void testDataFieldLabelRight() throws Exception {
95 WebElement exampleDiv = navigateToExample("Demo-DataField-Example3");
96 WebElement field = findElement(By.cssSelector(DIV_DATA_LABEL_DATA_FIELD_1), exampleDiv);
97
98 String fieldId = field.getAttribute("id");
99 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
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 }