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