1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.sampleu.travel;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.junit.Test;
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
23 import org.kuali.rice.testtools.selenium.WebDriverUtils;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import static org.junit.Assert.*;
29
30
31
32
33
34
35 public class UifDataAttributesNavAft extends WebDriverLegacyITBase {
36
37 public static String BOOKMARK_URL = WebDriverUtils.getBaseUrlString()+ "/kr-krad/data-attributes-test-uif-controller?viewId=dataAttributesView_selenium&methodToCall=start";
38
39 @Override
40 protected String getBookmarkUrl() {
41 return BOOKMARK_URL;
42 }
43
44 private Log log = LogFactory.getLog(getClass());
45
46
47
48
49
50
51
52
53 private void verifySimpleAttributes(String tag, String tagId, String tagIdSuffix) throws Exception{
54
55 tagId = tagId + tagIdSuffix;
56 String simpleAttributesXpath="//" + tag + "[@id='" + tagId + "' and @data-iconTemplateName='cool-icon-%s.png' and @data-transitions='3']";
57 assertTrue(tagId + " does not have simple data attributes (via list) present", isElementPresentByXpath(simpleAttributesXpath));
58 verifyStaticDataAttributes(tag, tagId);
59
60 }
61
62
63
64
65
66
67
68 private void verifyStaticDataAttributes(String tag, String tagId) {
69 final String simpleAttributesXpath;
70 simpleAttributesXpath="//" + tag + "[@id='" + tagId + "'"
71 + " and @data-dataroleattribute='role' and @data-datatypeattribute='type' and @data-datametaattribute='meta']";
72 assertTrue(tagId + " does not have simple data attributes (via data*Attribute) properties present",
73 isElementPresentByXpath(simpleAttributesXpath));
74 }
75
76
77
78
79
80
81
82 private void verifyComplexAttributes(String tagId, String suffix)throws Exception {
83 tagId = tagId + suffix;
84 String complexAttributesXpath="//input[(@type='hidden') and (@data-role='dataScript') and (@data-for='"+ tagId + "')]";
85 assertTrue(tagId + ": complex data attributes script not found", isElementPresentByXpath(complexAttributesXpath));
86
87
88
89 String scriptValue = waitAndGetAttributeByXpath(complexAttributesXpath, "value");
90 assertNotNull("script value is null",scriptValue);
91 boolean ok = scriptValue.contains(
92 "jQuery('#" + tagId + "').data('capitals', {kenya:'nairobi', uganda:'kampala', tanzania:'dar'});")
93 && scriptValue.contains("jQuery('#" + tagId + "').data('intervals', {short:2, medium:5, long:13});");
94 if (!ok) {
95 log.info("scriptValue for " + tagId + " is " + scriptValue);
96 }
97
98 assertTrue(tagId + ": complex attributes script does not contain expected code", ok);
99
100 }
101
102
103
104
105
106
107
108
109 private boolean verifyAllAttributesInScript(String tagId, String suffix)throws Exception {
110 checkForIncidentReport();
111 tagId = tagId + suffix;
112 String complexAttributesXpath="//input[@type='hidden' and @data-for='"+ tagId + "']";
113
114
115 String scriptValue = waitAndGetAttributeByXpath(complexAttributesXpath, "value");
116 assertNotNull("script value is null",scriptValue);
117
118 return scriptValue.contains("jQuery('#" + tagId + "').data('transitions', 3);") &&
119 scriptValue.contains("jQuery('#" + tagId + "').data('iconTemplateName', 'cool-icon-%s.png');") &&
120 scriptValue.contains("jQuery('#" + tagId + "').data('capitals', {kenya:'nairobi', uganda:'kampala', tanzania:'dar'});") &&
121 scriptValue.contains("jQuery('#" + tagId + "').data('intervals', {short:2, medium:5, long:13});");
122 }
123
124
125
126
127
128 @Test
129 public void testDataAttributesPresentInControlsNav() throws Exception{
130 assertEquals("Kuali Portal Index", getTitle());
131 open(getBookmarkUrl());
132 waitForPageToLoad();
133
134
135 String testIdSuffix = "_attrs";
136
137 String[] inputControls = {"textInputField", "textAreaInputField", "dropDown", "datePicker", "fileUpload", "userControl",
138 "spinnerControl", "hiddenControl", "checkBox"};
139 for (int i=0; i<inputControls.length; i++) {
140 assertTrue(inputControls[i] + ": script does not contain expected code",
141 verifyAllAttributesInScript(inputControls[i], testIdSuffix + UifConstants.IdSuffixes.CONTROL));
142 String tag = "input";
143 if (inputControls[i].equalsIgnoreCase("textAreaInputField")) {
144 tag = "textarea";
145 } else if (inputControls[i].equalsIgnoreCase("dropDown")) {
146 tag = "select";
147 }
148 verifyStaticDataAttributes(tag, inputControls[i] + testIdSuffix + UifConstants.IdSuffixes.CONTROL);
149 }
150
151 Map<String, String[]> otherControlsMap = new HashMap<String, String[]>();
152
153 String[] imgControls = {"imageField_image"};
154
155 String[] anchorFields = {"navigationLink", "actionLink-noImage", "actionLink-imageRight", "actionLink-imageLeft", "linkElement"};
156
157 String[] spanFields = {"messageField"};
158
159 String[] inputFields = {"imageAction"};
160
161 String[] buttonElements = {"buttonTextOnly", "buttonImageBottom", "buttonImageLeft", "buttonImageTop", "buttonImageRight"};
162
163 String[] iframeField = {"iframe"};
164 String[] divField={"spaceField","linkField"};
165
166 otherControlsMap.put("img", imgControls);
167 otherControlsMap.put("a", anchorFields);
168 otherControlsMap.put("span", spanFields);
169 otherControlsMap.put("input", inputFields);
170 otherControlsMap.put("button", buttonElements);
171 otherControlsMap.put("iframe", iframeField);
172 otherControlsMap.put("div", divField);
173
174
175
176 Map<String, String> simpleTagIdSuffix = new HashMap<String, String>();
177 simpleTagIdSuffix.put("span", "_span");
178
179
180 for (String tag: otherControlsMap.keySet()) {
181 String[] controlIds = otherControlsMap.get(tag);
182 for (int i=0; i<controlIds.length; i++) {
183 String tagId = controlIds[i];
184
185
186 verifyComplexAttributes(tagId, testIdSuffix);
187
188
189 String tagIdSuffix = testIdSuffix;
190 if (simpleTagIdSuffix.containsKey(tag)) {
191 tagIdSuffix = tagIdSuffix + simpleTagIdSuffix.get(tag);
192 }
193
194
195 verifySimpleAttributes(tag, tagId, tagIdSuffix);
196 }
197
198
199 String tagId = "textInputField";
200 String tagIdSuffix = testIdSuffix + "_label";
201
202 verifyComplexAttributes(tagId, tagIdSuffix);
203
204 verifySimpleAttributes("label", tagId, tagIdSuffix);
205
206
207 tagId = "radioButton" + testIdSuffix + UifConstants.IdSuffixes.CONTROL;
208 String[] radioButtonIds = {tagId + "_0", tagId + "_1"};
209 for (String id: radioButtonIds) {
210 verifyStaticDataAttributes("input", id);
211 }
212
213 verifyAllAttributesInScript(tagId, "");
214 }
215 passed();
216 }
217 }