1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.wysiwyg

File LineTest.java

 

Code metrics

0
218
17
1
500
298
17
0.08
12.82
17
1

Classes

Class Line # Actions
LineTest 33 218 0% 17 0
1.0100%
 

Contributing tests

This file is covered by 17 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.test.wysiwyg;
21   
22    import org.junit.Test;
23    import org.openqa.selenium.Keys;
24    import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase;
25   
26    import static org.junit.Assert.*;
27   
28    /**
29    * Functional tests for line support inside the WYSIWYG editor.
30    *
31    * @version $Id: 1a66db180fc891831b62a82b515afba8e9934b9d $
32    */
 
33    public class LineTest extends AbstractWysiwygTestCase
34    {
35    /**
36    * Tests if the user can insert a line break in different contexts.
37    */
 
38  1 toggle @Test
39    public void testInsertLineBreak()
40    {
41    // Under body
42  1 typeText("a");
43  1 typeShiftEnter();
44  1 typeText("b");
45  1 switchToSource();
46  1 assertSourceText("a\nb");
47   
48  1 setSourceText("");
49  1 switchToWysiwyg();
50   
51    // Inside heading
52  1 typeText("c");
53  1 applyStyleTitle1();
54  1 typeShiftEnter();
55  1 typeText("d");
56  1 switchToSource();
57  1 assertSourceText("= c\nd =");
58   
59  1 setSourceText("");
60  1 switchToWysiwyg();
61   
62    // Inside list item
63  1 typeText("e");
64  1 clickUnorderedListButton();
65  1 typeShiftEnter();
66  1 typeText("f");
67  1 switchToSource();
68  1 assertSourceText("* e\nf");
69   
70    // Inside table cell
71  1 setSourceText("|h");
72  1 switchToWysiwyg();
73  1 typeText("g");
74  1 typeShiftEnter();
75  1 switchToSource();
76  1 assertSourceText("|g\nh");
77   
78    // Inside table heading
79  1 setSourceText("|=j");
80  1 switchToWysiwyg();
81  1 typeText("i");
82  1 typeShiftEnter();
83  1 switchToSource();
84  1 assertSourceText("|=i\nj");
85   
86    // Inside paragraph
87  1 setSourceText("l");
88  1 switchToWysiwyg();
89  1 typeText("k");
90  1 typeShiftEnter();
91  1 switchToSource();
92  1 assertSourceText("k\nl");
93    }
94   
95    /**
96    * Tests if the user can split the current line of text.
97    */
 
98  1 toggle @Test
99    public void testSplitLine()
100    {
101    // Under body
102  1 typeTextThenEnter("a");
103  1 typeText("b");
104  1 switchToSource();
105  1 assertSourceText("a\n\nb");
106   
107    // Inside paragraph
108  1 setSourceText("d");
109  1 switchToWysiwyg();
110  1 typeTextThenEnter("c");
111  1 switchToSource();
112  1 assertSourceText("c\n\nd");
113   
114    // Inside heading
115  1 setSourceText("");
116  1 switchToWysiwyg();
117  1 applyStyleTitle2();
118  1 typeTextThenEnter("e");
119  1 typeText("f");
120  1 switchToSource();
121  1 assertSourceText("== e ==\n\nf");
122    }
123   
124    /**
125    * Tests if the user can split the current line when the caret is after a line break.
126    */
 
127  1 toggle @Test
128    public void testSplitLineAfterLineBreak()
129    {
130    // Under body
131  1 typeText("a");
132  1 typeShiftEnter();
133  1 typeEnter();
134  1 typeText("b");
135  1 switchToSource();
136  1 assertSourceText("a\n\nb");
137   
138    // Inside paragraph
139  1 setSourceText("d");
140  1 switchToWysiwyg();
141  1 typeText("c");
142  1 typeShiftEnter();
143  1 typeEnter();
144  1 switchToSource();
145  1 assertSourceText("c\n\nd");
146   
147    // Inside heading
148  1 setSourceText("");
149  1 switchToWysiwyg();
150  1 typeText("e");
151  1 applyStyleTitle3();
152  1 typeShiftEnter();
153  1 typeEnter();
154  1 typeText("f");
155  1 switchToSource();
156  1 assertSourceText("=== e ===\n\nf");
157    }
158   
159    /**
160    * Tests if pressing Enter at the beginning of a paragraph or heading inserts an empty line before them.
161    *
162    * @see XWIKI-3035: Cannot type more than 2 consecutive <enter> in IE6, following are ignored
163    */
 
164  1 toggle @Test
165    public void testInsertEmptyLine()
166    {
167    // Before paragraph
168  1 typeText("a");
169  1 typeEnter(2);
170  1 typeText("b");
171  1 switchToSource();
172  1 assertSourceText("a\n\n\nb");
173   
174    // Before heading
175  1 setSourceText("");
176  1 switchToWysiwyg();
177  1 typeTextThenEnter("c");
178  1 applyStyleTitle4();
179  1 typeEnter();
180  1 typeText("d");
181  1 switchToSource();
182  1 assertSourceText("c\n\n\n==== d ====");
183    }
184   
185    /**
186    * @see XWIKI-3573: Title style removed after hitting return then backspace at the beginning of a line
187    */
 
188  1 toggle @Test
189    public void testRemoveEmptyLineBefore()
190    {
191    // Remove empty lines before header.
192    // Create the header first.
193  1 typeText("x");
194  1 applyStyleTitle5();
195    // Place the caret at the beginning of the line
196  1 moveCaret("document.body.firstChild.firstChild", 0);
197    // Insert two empty lines before.
198  1 typeEnter(2);
199    // Remove them.
200  1 typeBackspace(2);
201    // Check the result.
202  1 switchToSource();
203  1 assertSourceText("===== x =====");
204  1 switchToWysiwyg();
205   
206    // Remove empty lines before paragraph
207    // Create the paragraph.
208  1 triggerToolbarUpdate();
209  1 applyStylePlainText();
210    // Insert two empty lines before.
211  1 typeEnter(2);
212    // Remove them.
213  1 typeBackspace(2);
214    // Check the result.
215  1 switchToSource();
216  1 assertSourceText("x");
217    }
218   
219    /**
220    * @see XWIKI-2996: Text area sometimes loses focus when pressing Enter on an empty line
221    */
 
222  1 toggle @Test
223    public void testEnterOnEmptyLine()
224    {
225  1 typeEnter();
226  1 typeText("foobar");
227  1 applyStyleTitle1();
228  1 typeEnter();
229  1 typeText("x");
230  1 switchToSource();
231  1 assertSourceText("\n= foobar =\n\nx");
232    }
233   
234    /**
235    * @see XWIKI-3011: Different behavior of <enter> on FF2.0 and FF3.0
236    */
 
237  1 toggle @Test
238    public void testParagraphs()
239    {
240  1 typeTextThenEnter("a");
241  1 typeTextThenEnter("b");
242  1 typeText("c");
243  1 switchToSource();
244  1 assertSourceText("a\n\nb\n\nc");
245    }
246   
247    /**
248    * @see XWIKI-2991: Editor is losing the focus when pressing enter after an image
249    */
 
250  1 toggle @Test
251    public void testEnterAfterImage()
252    {
253  1 clickMenu(ImageTest.MENU_IMAGE);
254  1 clickMenu(ImageTest.MENU_INSERT_ATTACHED_IMAGE);
255   
256  1 waitForDialogToLoad();
257    // wait for the main step of the dialog to load
258  1 waitForElement("//*[contains(@class, 'xSelectorAggregatorStep')]");
259    // click the 'All pages' tab
260  1 getSelenium().click("//div[. = 'All pages']");
261  1 String imageSpace = "XWiki";
262  1 waitForElement(ImageTest.SPACE_SELECTOR + "/option[@value = '" + imageSpace + "']");
263  1 getSelenium().select(ImageTest.SPACE_SELECTOR, imageSpace);
264  1 String imagePage = "AdminSheet";
265  1 waitForElement(ImageTest.PAGE_SELECTOR + "/option[@value = '" + imagePage + "']");
266  1 getSelenium().select(ImageTest.PAGE_SELECTOR, imagePage);
267  1 getSelenium().click("//div[@class = 'xPageChooser']//button[. = 'Update']");
268  1 String imageSelector = "//div[@class = 'xImagesSelector']//img[@title = 'import.png']";
269  1 waitForElement(imageSelector);
270  1 getSelenium().click(imageSelector);
271  1 clickButtonWithText("Select");
272  1 waitForElement("//*[contains(@class, 'xImageConfig')]");
273  1 clickButtonWithText("Insert Image");
274  1 waitForDialogToClose();
275   
276    // Make sure the editor is focused.
277  1 getRichTextArea().sendKeys("");
278   
279    // The inserted image should be selected. By pressing the right arrow key the caret is not moved after the image
280    // thus we are forced to collapse the selection to the end.
281  1 getRichTextArea().executeScript("window.getSelection().collapseToEnd()");
282    // If the editor loses focus after pressing Enter then the next typed text won't be submitted.
283  1 getRichTextArea().sendKeys(Keys.RETURN, "xyz");
284   
285    // Submit the changes. If the editor lost focus after pressing Enter then the next line has no effect.
286  1 blurRichTextArea();
287  1 clickEditPageInWikiSyntaxEditor();
288    // Check the result.
289  1 assertEquals("[[image:XWiki.AdminSheet@import.png]]\n\nxyz", getFieldValue("content"));
290    }
291   
292    /**
293    * Creates two paragraphs, makes a selection that spans both paragraphs and then presses Enter.
294    */
 
295  1 toggle @Test
296    public void testEnterOnCrossParagraphSelection()
297    {
298    // Creates the two paragraphs.
299  1 typeText("ab");
300  1 applyStyleTitle1();
301  1 applyStylePlainText();
302  1 typeEnter();
303  1 typeText("cd");
304   
305    // Make a cross paragraph selection.
306  1 select("document.body.firstChild.firstChild", 1, "document.body.lastChild.firstChild", 1);
307   
308    // Press Enter.
309  1 typeEnter();
310  1 switchToSource();
311  1 assertSourceText("a\n\nd");
312    }
313   
314    /**
315    * Inserts a table, types some text in each cell, makes a selection that spans some table cells and then presses
316    * Enter.
317    */
 
318  1 toggle @Test
319    public void testEnterOnCrossTableCellSelection()
320    {
321  1 insertTable();
322   
323    // Fill the table.
324    // Delete the non-breaking space that is found by default in empty table cells.
325  1 typeBackspace();
326  1 typeText("ab");
327  1 typeTab();
328  1 typeText("cd");
329    // Delete the non-breaking space that is found by default in empty table cells.
330  1 typeDelete();
331   
332    // Make a cross table cell selection.
333  1 select("document.body.firstChild.rows[0].cells[0].firstChild", 1,
334    "document.body.firstChild.rows[0].cells[1].firstChild", 1);
335   
336    // Press Enter.
337  1 typeEnter();
338  1 typeText("x");
339  1 switchToSource();
340  1 assertSourceText("|=a\nx|=d\n| | ");
341    }
342   
343    /**
344    * @see XWIKI-3109: Headers generated from wiki syntax look and behave differently
345    */
 
346  1 toggle @Test
347    public void testEnterInHeader()
348    {
349  1 typeText("H1");
350  1 applyStyleTitle1();
351  1 switchToSource();
352  1 assertSourceText("= H1 =");
353  1 switchToWysiwyg();
354   
355    // Place the caret in the middle of the header.
356  1 moveCaret("document.body.firstChild.firstChild", 1);
357   
358    // Type some text to update the tool bar.
359  1 typeText("#");
360   
361    // See if the header is detected.
362  1 waitForStyleDetected("Title 1");
363   
364    // Press enter to split the header and generate a paragraph.
365  1 typeEnter();
366   
367    // See if the paragraph is detected.
368  1 waitForStyleDetected("Plain text");
369   
370  1 switchToSource();
371  1 assertSourceText("= H# =\n\n1");
372    }
373   
374    /**
375    * Tests how the Enter key behaves inside a list item with complex content.
376    */
 
377  1 toggle @Test
378    public void testEnterInListItem()
379    {
380  1 typeText("a");
381  1 clickUnorderedListButton();
382  1 applyStyleTitle1();
383   
384    // Shift+Enter
385  1 typeShiftEnter();
386  1 typeText("b");
387   
388    // Control+Enter
389  1 typeControlEnter();
390  1 typeText("c");
391   
392    // Meta+Enter
393    // FIXME: Selenium doesn't emulate correctly the Meta key.
394    // typeMetaEnter();
395    // typeText("d");
396   
397    // Enter
398  1 typeEnter();
399  1 typeText("e");
400   
401    // Check the result.
402  1 switchToSource();
403  1 assertSourceText("* (((\n= a\nb =\n\nc\n)))\n* e");
404    }
405   
406    /**
407    * @see XWIKI-4023: Cannot place the caret inside an empty heading.
408    */
 
409  1 toggle @Test
410    public void testEmptyHeadingsAreEditable()
411    {
412  1 switchToSource();
413  1 setSourceText("before\n\n= =\n\nafter");
414  1 switchToWysiwyg();
415    // We can't test if the caret can be placed inside the empty heading because the selection is not updated on
416    // fake events. We can only check the generated HTML for a BR spacer that will allow the user to write text
417    // inside the heading.
418  1 assertContent("<p>before</p><h1 id=\"H\"><span></span><br></h1><p>after</p>");
419    }
420   
421    /**
422    * Tests that splitting a line containing only invisible garbage generates two empty lines that can be edited.
423    */
 
424  1 toggle @Test
425    public void testSplitEmptyLineWithGarbage()
426    {
427    // Create a line that has only invisible garbage.
428  1 setContent("<p><em></em><strong></strong></p>");
429    // Move the caret between the garbage.
430  1 moveCaret("document.body.firstChild", 1);
431    // Split the line.
432  1 typeEnter();
433  1 typeText("x");
434    // Check the result. The only way to test if the empty lines can be edited is to look for the BR spacers.
435  1 assertContent("<p><em></em><br></p><p>x<strong></strong><br></p>");
436    }
437   
438    /**
439    * @see XWIKI-4193: When hitting Return at the end of the link the new line should not be a link.
440    * @see XWIKI-3802: It is impossible to continue adding content if there is a link object at the bottom of the page.
441    */
 
442  1 toggle @Test
443    public void testEnterAtTheEndOfALink()
444    {
445  1 switchToSource();
446  1 setSourceText("This is a [[link>>http://www.xwiki.org]]");
447  1 switchToWysiwyg();
448    // Move the caret at the end of the link.
449  1 moveCaret("document.body.firstChild.lastChild.firstChild", 4);
450  1 typeEnter();
451  1 typeText("x");
452  1 switchToSource();
453  1 assertSourceText("This is a [[link>>http://www.xwiki.org]]\n\nx");
454    }
455   
456    /**
457    * @see XWIKI-3678: Justify not preserved when entering a new paragraph.
458    */
 
459  1 toggle @Test
460    public void testTextAlignmentIsPreservedOnANewParagraph()
461    {
462    // Create a level one heading.
463  1 typeText("1");
464  1 applyStyleTitle1();
465    // Center the text.
466  1 pushToolBarButton("Centered");
467    // Create two paragraphs.
468  1 typeEnter();
469  1 typeTextThenEnter("2");
470  1 typeText("34");
471    // Split the last paragraph in half.
472  1 moveCaret("document.body.lastChild.firstChild", 1);
473  1 typeEnter();
474    // Check the result.
475  1 switchToSource();
476  1 assertSourceText("(% style=\"text-align: center;\" %)\n= 1 =\n\n"
477    + "(% style=\"text-align: center;\" %)\n2\n\n" + "(% style=\"text-align: center;\" %)\n3\n\n"
478    + "(% style=\"text-align: center;\" %)\n4");
479    }
480   
481    /**
482    * @see XWIKI-2723: Empty paragraphs should not be displayed even if they have styles applied to them
483    */
 
484  1 toggle @Test
485    public void testEmptyParagraphsGenerateEmptyLines()
486    {
487  1 switchToSource();
488  1 setSourceText("(% style=\"color: blue; text-align: center;\" %)\nHello world");
489  1 switchToWysiwyg();
490   
491    // Place the caret after "Hello ".
492  1 moveCaret("document.body.firstChild.firstChild", 6);
493   
494  1 typeEnter(3);
495   
496  1 switchToSource();
497  1 assertSourceText("(% style=\"color: blue; text-align: center;\" %)\nHello\n\n\n\n"
498    + "(% style=\"text-align: center;\" %)\nworld");
499    }
500    }