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.UpgradedSeleniumITBase;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.junit.Test;
23 import org.kuali.rice.krad.uif.UifConstants;
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 UifDataAttributesIT extends UpgradedSeleniumITBase {
36 @Override
37 public String getTestUrl() {
38 return ITUtil.PORTAL;
39 }
40
41 private Log log = LogFactory.getLog(getClass());
42
43
44
45
46
47
48
49
50 private void verifySimpleAttributes(String tag, String tagId, String tagIdSuffix) {
51
52 tagId = tagId + tagIdSuffix;
53 String simpleAttributesXpath="//" + tag + "[(@id='" + tagId + "') and (@data-iconTemplateName='cool-icon-%s.png') and (@data-transitions='3')]";
54 assertTrue(tagId + " does not have simple data attributes (via list) present", isElementPresent(simpleAttributesXpath));
55 verifyStaticDataAttributes(tag, tagId);
56
57 }
58
59
60
61
62
63
64
65 private void verifyStaticDataAttributes(String tag, String tagId) {
66 final String simpleAttributesXpath;
67 simpleAttributesXpath="//" + tag + "[(@id='" + tagId + "')"
68 + " and (@data-role='role') and (@data-type='type') and (@data-meta='meta')]";
69 assertTrue(tagId + " does not have simple data attributes (via data*Attribute) properties present",
70 isElementPresent(simpleAttributesXpath));
71 }
72
73
74
75
76
77
78
79 private void verifyComplexAttributes(String tagId, String suffix) {
80 tagId = tagId + suffix;
81 String complexAttributesXpath="//input[(@type='hidden') and (@data-role='dataScript') and (@data-for='"+ tagId + "')]";
82 assertTrue(tagId + ": complex data attributes script not found", isElementPresent(complexAttributesXpath));
83
84
85
86 String scriptValue = getAttribute(complexAttributesXpath + "@value");
87 assertNotNull("script value is null",scriptValue);
88 boolean ok = scriptValue.contains(
89 "jQuery('#" + tagId + "').data('capitals', {kenya:'nairobi', uganda:'kampala', tanzania:'dar'});")
90 && scriptValue.contains("jQuery('#" + tagId + "').data('intervals', {short:2, medium:5, long:13});");
91 if (!ok) {
92 log.info("scriptValue for " + tagId + " is " + scriptValue);
93 }
94
95 assertTrue(tagId + ": complex attributes script does not contain expected code", ok);
96
97 }
98
99
100
101
102
103
104
105
106 private boolean verifyAllAttributesInScript(String tagId, String suffix) {
107 tagId = tagId + suffix;
108 String complexAttributesXpath="//input[(@type='hidden') and (@data-for='"+ tagId + "')]";
109 assertTrue(tagId + ": complex data attributes script not found see https://jira.kuali.org/browse/KULRICE-7752", isElementPresent(complexAttributesXpath));
110
111
112 String scriptValue = getAttribute(complexAttributesXpath + "@value");
113 assertNotNull("script value is null",scriptValue);
114
115 return scriptValue.contains("jQuery('#" + tagId + "').data('transitions', 3);") &&
116 scriptValue.contains("jQuery('#" + tagId + "').data('iconTemplateName', 'cool-icon-%s.png');") &&
117 scriptValue.contains("jQuery('#" + tagId + "').data('capitals', {kenya:'nairobi', uganda:'kampala', tanzania:'dar'});") &&
118 scriptValue.contains("jQuery('#" + tagId + "').data('intervals', {short:2, medium:5, long:13});");
119 }
120
121
122
123
124
125 @Test
126 public void testDataAttributesPresentInControls () {
127 assertEquals("Kuali Portal Index", getTitle());
128 open( "/kr-dev/kr-krad/data-attributes-test-uif-controller?viewId=dataAttributesView_selenium&methodToCall=start");
129 waitForPageToLoad();
130
131
132 String testIdSuffix = "_attrs";
133
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",
158 "linkField", "linkElement"};
159
160 String[] spanFields = {"messageField", "spaceField"};
161
162 String[] inputFields = {"imageAction"};
163
164 String[] buttonElements = {"buttonTextOnly", "buttonImageBottom", "buttonImageLeft", "buttonImageTop", "buttonImageRight"};
165
166 String[] iframeField = {"iframe"};
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
175
176
177 Map<String, String> simpleTagIdSuffix = new HashMap<String, String>();
178 simpleTagIdSuffix.put("span", "_span");
179
180
181 for (String tag: otherControlsMap.keySet()) {
182 String[] controlIds = otherControlsMap.get(tag);
183 for (int i=0; i<controlIds.length; i++) {
184 String tagId = controlIds[i];
185
186
187 verifyComplexAttributes(tagId, testIdSuffix);
188
189
190 String tagIdSuffix = testIdSuffix;
191 if (simpleTagIdSuffix.containsKey(tag)) {
192 tagIdSuffix = tagIdSuffix + simpleTagIdSuffix.get(tag);
193 }
194
195
196 verifySimpleAttributes(tag, tagId, tagIdSuffix);
197 }
198
199
200 String tagId = "textInputField";
201 String tagIdSuffix = testIdSuffix + "_label";
202
203 verifyComplexAttributes(tagId, tagIdSuffix);
204
205 verifySimpleAttributes("label", tagId, tagIdSuffix);
206
207
208 tagId = "radioButton" + testIdSuffix + UifConstants.IdSuffixes.CONTROL;
209 String[] radioButtonIds = {tagId + "1", tagId + "2"};
210 for (String id: radioButtonIds) {
211 verifyStaticDataAttributes("input", id);
212 }
213
214 verifyAllAttributesInScript(tagId, "");
215 }
216 }
217 }