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