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