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 java.util.Date; |
23 |
|
|
24 |
|
import org.junit.Test; |
25 |
|
import org.openqa.selenium.By; |
26 |
|
import org.openqa.selenium.Keys; |
27 |
|
import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase; |
28 |
|
|
29 |
|
import com.thoughtworks.selenium.Wait; |
30 |
|
|
31 |
|
import static org.junit.Assert.*; |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (163) |
Complexity: 18 |
Complexity Density: 0.12 |
|
33 |
|
public class TabsTest extends AbstractWysiwygTestCase |
34 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
35 |
1 |
@Test... |
36 |
|
public void testMultipleClicksOnTheSameTab() |
37 |
|
{ |
38 |
1 |
setContent("<strong>foo</strong>"); |
39 |
1 |
switchToWysiwyg(false); |
40 |
1 |
switchToWysiwyg(); |
41 |
1 |
switchToSource(); |
42 |
1 |
assertSourceText("**foo**"); |
43 |
|
} |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
48 |
1 |
@Test... |
49 |
|
public void testMultipleSwitches() |
50 |
|
{ |
51 |
1 |
StringBuffer content = new StringBuffer(); |
52 |
|
|
53 |
1 |
content.append("<strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor " |
54 |
|
+ "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation " |
55 |
|
+ "ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in " |
56 |
|
+ "voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " |
57 |
|
+ "proident, sunt in culpa qui officia deserunt mollit anim id est laborum."); |
58 |
1 |
content.append("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt " |
59 |
|
+ "ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " |
60 |
|
+ "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in " |
61 |
|
+ "voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " |
62 |
|
+ "proident, sunt in culpa qui officia deserunt mollit anim id est laborum."); |
63 |
1 |
content.append("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt " |
64 |
|
+ "ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " |
65 |
|
+ "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in " |
66 |
|
+ "voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " |
67 |
|
+ "proident, sunt in culpa qui officia deserunt mollit anim id est laborum."); |
68 |
1 |
content.append("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt " |
69 |
|
+ "ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " |
70 |
|
+ "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in " |
71 |
|
+ "voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " |
72 |
|
+ "proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</strong>"); |
73 |
1 |
setContent(content.toString()); |
74 |
|
|
75 |
|
|
76 |
1 |
switchToSource(false); |
77 |
1 |
switchToWysiwyg(false); |
78 |
1 |
switchToSource(false); |
79 |
1 |
switchToWysiwyg(false); |
80 |
1 |
switchToSource(); |
81 |
|
|
82 |
1 |
assertFalse(getSourceText().contains("strong")); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
@see |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void testLinksAreNotLostWhenSwitchingToSourceTab() |
90 |
|
{ |
91 |
1 |
String content = "Visit [[XWiki>>http://www.xwiki.org]] and our [[blog>>Blog.WebHome]]."; |
92 |
1 |
switchToSource(); |
93 |
1 |
setSourceText(content); |
94 |
1 |
switchToWysiwyg(); |
95 |
1 |
switchToSource(); |
96 |
1 |
assertSourceText(content); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
@see |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
102 |
1 |
@Test... |
103 |
|
public void testContextDocumentIsPreserved() |
104 |
|
{ |
105 |
|
|
106 |
1 |
clickEditPageInWikiSyntaxEditor(); |
107 |
1 |
setFieldValue("content", "{{velocity}}$doc.fullName{{/velocity}}"); |
108 |
1 |
clickEditPageInWysiwyg(); |
109 |
1 |
waitForEditorToLoad(); |
110 |
1 |
String expected = getRichTextArea().getText(); |
111 |
1 |
switchToSource(); |
112 |
1 |
switchToWysiwyg(); |
113 |
1 |
assertEquals(expected, getRichTextArea().getText()); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
public void testSwitchToSourceWhileWysiwygIsLoading() |
121 |
|
{ |
122 |
1 |
switchToSource(); |
123 |
1 |
StringBuffer sourceText = new StringBuffer(); |
124 |
1 |
sourceText.append("{{code language=\"java\"}}\n"); |
125 |
1 |
sourceText.append("public interface Command {\n"); |
126 |
1 |
sourceText.append(" boolean execute(String parameter);\n"); |
127 |
1 |
sourceText.append("}\n"); |
128 |
1 |
sourceText.append("{{/code}}"); |
129 |
1 |
setSourceText(sourceText.toString()); |
130 |
|
|
131 |
1 |
getSourceTextArea().sendKeys(Keys.HOME, Keys.PAGE_UP, Keys.chord(Keys.CONTROL, Keys.ARROW_RIGHT), |
132 |
|
Keys.ARROW_RIGHT); |
133 |
|
|
134 |
1 |
switchToWysiwyg(false); |
135 |
|
|
136 |
1 |
switchToSource(); |
137 |
1 |
getSourceTextArea().sendKeys("x"); |
138 |
|
|
139 |
|
|
140 |
1 |
assertSourceText(sourceText.substring(0, 7) + "x" + sourceText.substring(7)); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@see |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
148 |
1 |
@Test... |
149 |
|
public void testSwitchToSourceWithHTMLChangesAndWait() |
150 |
|
{ |
151 |
1 |
typeText("1"); |
152 |
1 |
applyStyleTitle1(); |
153 |
1 |
switchToSource(); |
154 |
1 |
getSourceTextArea().sendKeys("x"); |
155 |
1 |
assertSourceText("x= 1 ="); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
161 |
1 |
@Test... |
162 |
|
public void testSwitchToSourceWithoutHTMLChanges() |
163 |
|
{ |
164 |
1 |
switchToSource(); |
165 |
1 |
String sourceText = "one **two** three"; |
166 |
1 |
setSourceText(sourceText); |
167 |
|
|
168 |
1 |
getSourceTextArea().sendKeys(Keys.chord(Keys.CONTROL, Keys.ARROW_LEFT, Keys.ARROW_LEFT), Keys.ARROW_LEFT); |
169 |
1 |
switchToWysiwyg(); |
170 |
|
|
171 |
1 |
switchToSource(); |
172 |
1 |
getSourceTextArea().sendKeys("x"); |
173 |
|
|
174 |
1 |
assertSourceText(sourceText.substring(0, 5) + "x" + sourceText.substring(5)); |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
180 |
1 |
@Test... |
181 |
|
public void testSwitchToSourceWithHTMLChangesAndDontWait() |
182 |
|
{ |
183 |
1 |
setContent("<!--startmacro:code|-|language=\"java\"|-|public class Apple extends Fruit {\n" |
184 |
|
+ " public String getColor() {\n return Colors.RED;\n }\n}--><!--stopmacro-->"); |
185 |
|
|
186 |
1 |
switchToSource(false); |
187 |
|
|
188 |
1 |
switchToWysiwyg(); |
189 |
|
|
190 |
1 |
new Wait() |
191 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
192 |
1 |
public boolean until()... |
193 |
|
{ |
194 |
1 |
return getSourceText().length() > 1; |
195 |
|
} |
196 |
|
}.wait("Conversion takes too long!"); |
197 |
|
|
198 |
1 |
switchToSource(false); |
199 |
1 |
assertTrue(getSourceTextArea().isEnabled()); |
200 |
1 |
getSourceTextArea().sendKeys("x"); |
201 |
1 |
assertSourceText("x{{code language=\"java\"}}\npublic class Apple extends Fruit {\n" |
202 |
|
+ " public String getColor() {\n return Colors.RED;\n }\n}\n{{/code}}"); |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
208 |
1 |
@Test... |
209 |
|
public void testSwitchToSourceFailure() |
210 |
|
{ |
211 |
|
|
212 |
1 |
String content = "<span class=\"wikiexternallink\"><a href=\"mailto:x@y.z\">xyz</a></span><!--stopwikilink-->"; |
213 |
1 |
setContent(content); |
214 |
|
|
215 |
1 |
switchToSource(false); |
216 |
|
|
217 |
1 |
waitForElement("//div[@class = 'gwt-TabBarItem gwt-TabBarItem-selected']/div[. = 'WYSIWYG']"); |
218 |
|
|
219 |
1 |
assertContent(content); |
220 |
|
|
221 |
1 |
setContent("<p>Should be fine now.</p>"); |
222 |
1 |
switchToSource(); |
223 |
1 |
assertSourceText("Should be fine now."); |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
229 |
1 |
@Test... |
230 |
|
public void testCancelSwitchToSource() |
231 |
|
{ |
232 |
|
|
233 |
1 |
setContent("<h1>Heading</h1><p>paragraph</p><ul><li>list</li></ul><table><tr><td>cell</td></tr></table>"); |
234 |
|
|
235 |
1 |
moveCaret("document.body.firstChild.firstChild", 3); |
236 |
|
|
237 |
1 |
switchToSource(false); |
238 |
|
|
239 |
1 |
switchToWysiwyg(); |
240 |
|
|
241 |
1 |
typeText("X"); |
242 |
|
|
243 |
1 |
switchToSource(); |
244 |
|
|
245 |
1 |
assertSourceText("= HeaXding =\n\nparagraph\n\n* list\n\n|cell"); |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
@see |
250 |
|
|
251 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
252 |
1 |
@Test... |
253 |
|
public void testSwitchToSourceBeforeWysiwygLoad() |
254 |
|
{ |
255 |
|
|
256 |
1 |
switchToSource(); |
257 |
1 |
String sourceText = |
258 |
|
"{{code}}long x = 1L;{{/code}}\n\n{{html}}" + new Date().getTime() |
259 |
|
+ "{{/html}}\n\n{{velocity}}$doc.name{{/velocity}}"; |
260 |
1 |
setSourceText(sourceText); |
261 |
1 |
clickEditSaveAndContinue(); |
262 |
|
|
263 |
1 |
getSelenium().runScript("window.location.reload(true)"); |
264 |
|
|
265 |
1 |
waitForElement("//div[@class = 'gwt-TabBarItem']/div[. = 'Source']"); |
266 |
1 |
switchToSource(); |
267 |
|
|
268 |
1 |
assertSourceText(sourceText); |
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
} |
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
280 |
1 |
@Test... |
281 |
|
public void testSwitchToWysiwygWhileSourceIsLoading() |
282 |
|
{ |
283 |
1 |
String content = |
284 |
|
"before <!--startmacro:code|-|language=\"java\"|-|\\npublic class Apple extends Fruit {\n" |
285 |
|
+ " public String getColor() {\n return Colors.RED;\n }\n}\n--><!--stopmacro--> after"; |
286 |
1 |
setContent(content); |
287 |
|
|
288 |
1 |
select("document.body.firstChild", 3, "document.body.firstChild", 6); |
289 |
|
|
290 |
1 |
switchToSource(false); |
291 |
|
|
292 |
1 |
switchToWysiwyg(); |
293 |
|
|
294 |
1 |
typeText("#"); |
295 |
|
|
296 |
1 |
assertContent(content.substring(0, 3) + "#" + content.substring(6)); |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
302 |
1 |
@Test... |
303 |
|
public void testSwitchToWysiwygWithoutSourceChanges() |
304 |
|
{ |
305 |
1 |
setContent("<em>alice</em> and <strong>bob</strong>"); |
306 |
1 |
select("document.body.firstChild.firstChild", 3, "document.body.lastChild.firstChild", 1); |
307 |
|
|
308 |
1 |
switchToSource(); |
309 |
1 |
assertSourceText("//alice// and **bob**"); |
310 |
|
|
311 |
1 |
switchToWysiwyg(); |
312 |
|
|
313 |
1 |
pushToolBarButton("Clear Formatting"); |
314 |
1 |
assertContent("<em>ali</em>ce and b<strong>ob</strong>"); |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
320 |
1 |
@Test... |
321 |
|
public void testSwitchToWysiwygWithSourceChangesAndWait() |
322 |
|
{ |
323 |
1 |
switchToSource(); |
324 |
1 |
setSourceText("**X**Wiki"); |
325 |
1 |
switchToWysiwyg(); |
326 |
1 |
typeText("+"); |
327 |
1 |
assertContent("<p><strong>+X</strong>Wiki</p>"); |
328 |
|
} |
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
334 |
1 |
@Test... |
335 |
|
public void testSwitchToWysiwygWithHTMLChangesAndDontWait() |
336 |
|
{ |
337 |
1 |
switchToSource(); |
338 |
1 |
String sourceText = "before {{code language=\"java\"}}private static final long x = 1L;{{/code}}"; |
339 |
1 |
setSourceText(sourceText); |
340 |
|
|
341 |
1 |
switchToWysiwyg(false); |
342 |
|
|
343 |
1 |
switchToSource(); |
344 |
1 |
getDriver().waitUntilElementDisappears(By.xpath("//div[@class = 'xRichTextEditor']//div[@class = 'loading']")); |
345 |
|
|
346 |
1 |
switchToWysiwyg(); |
347 |
1 |
typeText("#"); |
348 |
1 |
switchToSource(); |
349 |
1 |
assertSourceText("#" + sourceText); |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
355 |
1 |
@Test... |
356 |
|
public void testCancelSwitchToWysiwyg() |
357 |
|
{ |
358 |
|
|
359 |
1 |
switchToSource(); |
360 |
1 |
StringBuilder sourceText = new StringBuilder(); |
361 |
1 |
sourceText.append("{{code language=\"java\"}}\n"); |
362 |
1 |
sourceText.append("public final class Apple extends Fruit {\n"); |
363 |
1 |
sourceText.append(" public String getColor() {\n"); |
364 |
1 |
sourceText.append(" return \"red\";\n"); |
365 |
1 |
sourceText.append(" }\n"); |
366 |
1 |
sourceText.append("}\n"); |
367 |
1 |
sourceText.append("{{/code}}"); |
368 |
1 |
setSourceText(sourceText.toString()); |
369 |
|
|
370 |
1 |
getSourceTextArea().sendKeys(Keys.HOME, Keys.PAGE_UP, Keys.ARROW_DOWN, |
371 |
|
Keys.chord(Keys.CONTROL, Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, Keys.ARROW_RIGHT), Keys.ARROW_RIGHT); |
372 |
|
|
373 |
1 |
switchToWysiwyg(false); |
374 |
|
|
375 |
1 |
switchToSource(); |
376 |
|
|
377 |
1 |
getSourceTextArea().sendKeys("X"); |
378 |
|
|
379 |
1 |
switchToWysiwyg(); |
380 |
|
|
381 |
1 |
switchToSource(); |
382 |
1 |
getSourceTextArea().sendKeys("Y"); |
383 |
1 |
assertSourceText(sourceText.substring(0, 44) + "XY" + sourceText.substring(44)); |
384 |
|
} |
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
389 |
1 |
@Test... |
390 |
|
public void testUndoSourceChange() |
391 |
|
{ |
392 |
1 |
typeText("1"); |
393 |
1 |
applyStyleTitle1(); |
394 |
1 |
switchToSource(); |
395 |
|
|
396 |
1 |
getSourceTextArea().sendKeys(Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, "2"); |
397 |
|
|
398 |
1 |
switchToWysiwyg(); |
399 |
|
|
400 |
1 |
waitForPushButton(TOOLBAR_BUTTON_UNDO_TITLE, true); |
401 |
1 |
clickUndoButton(); |
402 |
|
|
403 |
1 |
switchToSource(); |
404 |
|
|
405 |
1 |
assertSourceText("1"); |
406 |
|
} |
407 |
|
} |