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