1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.wysiwyg; |
21 |
|
|
22 |
|
import org.junit.Test; |
23 |
|
import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase; |
24 |
|
|
25 |
|
import static org.junit.Assert.*; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@version |
31 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (168) |
Complexity: 11 |
Complexity Density: 0.07 |
|
32 |
|
public class NativeJavaScriptApiTest extends AbstractWysiwygTestCase |
33 |
|
{ |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
42 |
1 |
@Test... |
43 |
|
public void testTextAreaElementsGetters() |
44 |
|
{ |
45 |
1 |
insertEditor("editor", "displayTabs: true"); |
46 |
|
|
47 |
|
|
48 |
1 |
assertEquals("xPlainTextEditor", getSelenium().getEval("window.editor.getPlainTextArea().className")); |
49 |
1 |
assertEquals("textarea", getSelenium().getEval("window.editor.getPlainTextArea().nodeName").toLowerCase()); |
50 |
|
|
51 |
|
|
52 |
1 |
assertEquals("gwt-RichTextArea", getSelenium().getEval("window.editor.getRichTextArea().className")); |
53 |
1 |
assertEquals("iframe", getSelenium().getEval("window.editor.getRichTextArea().nodeName").toLowerCase()); |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
public void testGetSourceTextWhenRichTextAreaIsEnabled() |
62 |
|
{ |
63 |
1 |
insertEditor("editor", "syntax: 'xwiki/2.0'"); |
64 |
1 |
setContent("<em>xwiki</em> is the <strong>best</strong>!<br/>"); |
65 |
1 |
assertEquals("//xwiki// is the **best**!", getSourceText("editor")); |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
public void testGetSourceTextWhenRichTextAreaIsDisabled() |
74 |
|
{ |
75 |
1 |
insertEditor("editor", "syntax: 'xwiki/2.0',\ndisplayTabs: true,\ndefaultEditor: 'wysiwyg'"); |
76 |
1 |
setContent("<h1>Veni, <em>vidi</em>, vici<br/></h1>"); |
77 |
1 |
switchToSource(); |
78 |
1 |
assertEquals("= Veni, //vidi//, vici =", getSourceText("editor")); |
79 |
|
|
80 |
|
|
81 |
1 |
getSourceTextArea().sendKeys("x"); |
82 |
1 |
assertEquals("x= Veni, //vidi//, vici =", getSourceText("editor")); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (37) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void testRelease() |
90 |
|
{ |
91 |
1 |
switchToSource(); |
92 |
1 |
StringBuffer content = new StringBuffer(); |
93 |
1 |
content.append("{{velocity}}\n"); |
94 |
1 |
content.append("{{html}}\n"); |
95 |
1 |
content.append("#wysiwyg_import(true)\n"); |
96 |
1 |
content.append("<div id=\"wrapper\"></div>\n"); |
97 |
1 |
content.append("<div><button onclick=\"loadEditor();\">Load Editor</button></div>\n"); |
98 |
1 |
content.append("<script type=\"text/javascript\">\n"); |
99 |
1 |
content.append("function loadEditor() {\n"); |
100 |
1 |
content.append(" if (window.editor) {\n"); |
101 |
1 |
content.append(" editor.release();\n"); |
102 |
1 |
content.append(" delete window.editor;\n"); |
103 |
1 |
content.append(" }\n"); |
104 |
1 |
content.append(" Wysiwyg.onModuleLoad(function() {\n"); |
105 |
1 |
content.append(" document.getElementById('wrapper').innerHTML = '<textarea id=\"test\"></textarea>';\n"); |
106 |
1 |
content.append(" editor = new WysiwygEditor({hookId: 'test', syntax: 'xwiki/2.0'});\n"); |
107 |
1 |
content.append(" });\n"); |
108 |
1 |
content.append("}\n"); |
109 |
1 |
content.append("</script>\n"); |
110 |
1 |
content.append("{{/html}}\n"); |
111 |
1 |
content.append("{{/velocity}}"); |
112 |
1 |
setSourceText(content.toString()); |
113 |
1 |
clickEditSaveAndView(); |
114 |
|
|
115 |
1 |
clickButtonWithText("Load Editor"); |
116 |
1 |
waitForCondition("typeof window.editor == 'object'"); |
117 |
1 |
waitForEditorToLoad(); |
118 |
1 |
focusRichTextArea(); |
119 |
|
|
120 |
1 |
typeText("x"); |
121 |
1 |
assertEquals("x", getSourceText("editor")); |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
1 |
typeText("Y"); |
127 |
1 |
clickButtonWithText("Load Editor"); |
128 |
1 |
waitForCondition("typeof window.editor == 'object'"); |
129 |
1 |
waitForEditorToLoad(); |
130 |
1 |
focusRichTextArea(); |
131 |
|
|
132 |
1 |
typeText("z"); |
133 |
1 |
applyStyleTitle1(); |
134 |
1 |
assertEquals("= z =", getSourceText("editor")); |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
@see |
139 |
|
|
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
141 |
1 |
@Test... |
142 |
|
public void testEditMissingProperty() |
143 |
|
{ |
144 |
|
|
145 |
1 |
String location = getSelenium().getLocation(); |
146 |
|
|
147 |
|
|
148 |
1 |
open("Test", "Alice", "edit", "editor=wiki"); |
149 |
|
|
150 |
1 |
setFieldValue("content", "I want ice cream"); |
151 |
1 |
clickEditSaveAndView(); |
152 |
|
|
153 |
|
|
154 |
1 |
open(location); |
155 |
1 |
waitForEditorToLoad(); |
156 |
1 |
switchToSource(); |
157 |
|
|
158 |
1 |
StringBuffer content = new StringBuffer(); |
159 |
1 |
content.append("{{velocity}}\n"); |
160 |
1 |
content.append("{{html}}\n"); |
161 |
|
|
162 |
1 |
content.append("<textarea id=\"XWiki.TagClass_0_xyz\"></textarea>\n"); |
163 |
1 |
content.append("#wysiwyg_editProperty($xwiki.getDocument('Test.Alice') 'XWiki.TagClass_0_xyz' false)\n"); |
164 |
1 |
content.append("<script type=\"text/javascript\">\n"); |
165 |
1 |
content.append("document.observe('xwiki:wysiwyg:created', function(event) {\n"); |
166 |
1 |
content.append(" window.editor = event.memo.instance;\n"); |
167 |
1 |
content.append("});\n"); |
168 |
1 |
content.append("</script>\n"); |
169 |
1 |
content.append("{{/html}}\n"); |
170 |
1 |
content.append("{{/velocity}}"); |
171 |
1 |
setSourceText(content.toString()); |
172 |
1 |
clickEditSaveAndView(); |
173 |
|
|
174 |
1 |
waitForCondition("typeof window.editor == 'object'"); |
175 |
1 |
waitForEditorToLoad(); |
176 |
|
|
177 |
1 |
assertEquals("", getSourceText("editor")); |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
@see |
182 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
183 |
1 |
@Test... |
184 |
|
public void testCommandManagerApi() |
185 |
|
{ |
186 |
1 |
insertEditor("editor", "syntax: 'xwiki/2.0'"); |
187 |
1 |
focusRichTextArea(); |
188 |
1 |
typeText("x"); |
189 |
1 |
selectNodeContents("document.body.firstChild"); |
190 |
1 |
assertTrue(Boolean.valueOf(getSelenium().getEval("window.editor.getCommandManager().isSupported('bold')"))); |
191 |
1 |
assertTrue(Boolean.valueOf(getSelenium().getEval("window.editor.getCommandManager().isEnabled('bold')"))); |
192 |
1 |
assertFalse(Boolean.valueOf(getSelenium().getEval("window.editor.getCommandManager().isExecuted('bold')"))); |
193 |
1 |
assertTrue(Boolean.valueOf(getSelenium().getEval("window.editor.getCommandManager().execute('bold')"))); |
194 |
1 |
assertTrue(Boolean.valueOf(getSelenium().getEval("window.editor.getCommandManager().isExecuted('bold')"))); |
195 |
1 |
assertEquals("**x**", getSourceText("editor")); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
201 |
1 |
@Test... |
202 |
|
public void testEvents() |
203 |
|
{ |
204 |
|
|
205 |
1 |
switchToSource(); |
206 |
1 |
StringBuffer content = new StringBuffer(); |
207 |
1 |
content.append("{{velocity}}\n"); |
208 |
1 |
content.append("{{html}}\n"); |
209 |
1 |
content.append("#wysiwyg_import(false)\n"); |
210 |
1 |
content.append("<div id=\"log\"></div>\n"); |
211 |
1 |
content.append("<textarea id=\"source\"></textarea>\n"); |
212 |
1 |
content.append("<script type=\"text/javascript\">\n"); |
213 |
1 |
content.append("['created', 'loaded', 'showingSource', 'showSource'," |
214 |
|
+ " 'showingWysiwyg', 'showWysiwyg'].each(function(actionName) {\n"); |
215 |
1 |
content.append(" document.observe('xwiki:wysiwyg:' + actionName, function(event) {\n"); |
216 |
1 |
content.append(" if (!window.editor || event.memo.instance == window.editor) {\n"); |
217 |
1 |
content.append(" $('log').appendChild(document.createTextNode(event.eventName + ' '));\n"); |
218 |
1 |
content.append(" }\n"); |
219 |
1 |
content.append(" });\n"); |
220 |
1 |
content.append("});\n"); |
221 |
1 |
content.append("document.observe('xwiki:dom:loaded', function() {\n"); |
222 |
1 |
content.append(" Wysiwyg.onModuleLoad(function() {\n"); |
223 |
1 |
content.append(" editor = new WysiwygEditor({\n"); |
224 |
1 |
content.append(" hookId: 'source',\n"); |
225 |
1 |
content.append(" syntax: 'xwiki/2.0',\n"); |
226 |
1 |
String inputURL = |
227 |
|
getUrl(this.getClass().getSimpleName(), "_" + getTestMethodName(), "edit", "xpage=wysiwyginput"); |
228 |
1 |
content.append(" inputURL: '" + inputURL + "',\n"); |
229 |
1 |
content.append(" displayTabs: true,\n"); |
230 |
1 |
content.append(" defaultEditor: 'wysiwyg'\n"); |
231 |
1 |
content.append(" });\n"); |
232 |
1 |
content.append(" });\n"); |
233 |
1 |
content.append("});\n"); |
234 |
1 |
content.append("</script>\n"); |
235 |
1 |
content.append("{{/html}}\n"); |
236 |
1 |
content.append("{{/velocity}}"); |
237 |
1 |
setSourceText(content.toString()); |
238 |
1 |
clickEditSaveAndView(); |
239 |
|
|
240 |
|
|
241 |
1 |
waitForCondition("typeof window.editor == 'object'"); |
242 |
1 |
waitForEditorToLoad(); |
243 |
1 |
focusRichTextArea(); |
244 |
|
|
245 |
|
|
246 |
1 |
typeText("1"); |
247 |
1 |
switchToSource(); |
248 |
1 |
setSourceText("2"); |
249 |
1 |
switchToWysiwyg(); |
250 |
|
|
251 |
|
|
252 |
1 |
assertEquals("xwiki:wysiwyg:created xwiki:wysiwyg:loaded xwiki:wysiwyg:showWysiwyg xwiki:wysiwyg:showingSource" |
253 |
|
+ " xwiki:wysiwyg:showSource xwiki:wysiwyg:showingWysiwyg xwiki:wysiwyg:showWysiwyg ", getSelenium() |
254 |
|
.getEval("window.document.getElementById('log').innerHTML")); |
255 |
|
} |
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
260 |
1 |
@Test... |
261 |
|
public void testAccessConfigurationParameters() |
262 |
|
{ |
263 |
1 |
String hookId = "XWiki.ArticleClass_0_description"; |
264 |
1 |
insertEditor(hookId, "syntax: 'xwiki/2.0',\nxyz: 'abc'"); |
265 |
1 |
assertEquals("abc", getSelenium().getEval("window['" + hookId + "'].getParameter('xyz')")); |
266 |
1 |
assertEquals("3", getSelenium().getEval("window['" + hookId + "'].getParameterNames().length")); |
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
272 |
1 |
@Test... |
273 |
|
public void testAccessWysiwygEditorInstanceByHookId() |
274 |
|
{ |
275 |
1 |
String hookId = "XWiki.ArticleClass_0_description"; |
276 |
1 |
insertEditor(hookId, "syntax: 'xwiki/2.0'"); |
277 |
1 |
assertEquals(hookId, |
278 |
|
getSelenium().getEval("window.Wysiwyg.getInstance('" + hookId + "').getParameter('hookId')")); |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
@param |
285 |
|
@param |
286 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
|
287 |
6 |
protected void insertEditor(String name, String config)... |
288 |
|
{ |
289 |
|
|
290 |
6 |
switchToSource(); |
291 |
6 |
StringBuilder content = new StringBuilder(); |
292 |
6 |
content.append("{{velocity}}\n"); |
293 |
6 |
content.append("{{html}}\n"); |
294 |
6 |
content.append("#wysiwyg_import(false)\n"); |
295 |
6 |
content.append("<textarea id=\"" + name + "\"></textarea>\n"); |
296 |
6 |
content.append("<script type=\"text/javascript\">\n"); |
297 |
6 |
content.append("document.observe('xwiki:dom:loaded', function() {\n"); |
298 |
6 |
content.append(" Wysiwyg.onModuleLoad(function() {\n"); |
299 |
6 |
content.append(" window['" + name + "'] = new WysiwygEditor({\n"); |
300 |
6 |
content.append(" hookId: '" + name + "',\n"); |
301 |
6 |
content.append(" " + config + "\n"); |
302 |
6 |
content.append(" });\n"); |
303 |
6 |
content.append(" });\n"); |
304 |
6 |
content.append("});\n"); |
305 |
6 |
content.append("</script>\n"); |
306 |
6 |
content.append("{{/html}}\n"); |
307 |
6 |
content.append("{{/velocity}}"); |
308 |
6 |
setSourceText(content.toString()); |
309 |
6 |
clickEditSaveAndView(); |
310 |
|
|
311 |
|
|
312 |
6 |
waitForCondition("typeof window['" + name + "'] == 'object'"); |
313 |
6 |
waitForEditorToLoad(); |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
|
@param |
318 |
|
@return |
319 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
320 |
7 |
protected String getSourceText(String editorName)... |
321 |
|
{ |
322 |
7 |
getSelenium().getEval( |
323 |
|
"delete window.sourceText;\nwindow['" + editorName |
324 |
|
+ "'].getSourceText(function(result){window.sourceText = result;})"); |
325 |
7 |
waitForCondition("typeof window.sourceText == 'string'"); |
326 |
7 |
return getSelenium().getEval("window.sourceText"); |
327 |
|
} |
328 |
|
} |