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