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

File TableTest.java

 

Code metrics

0
71
6
1
223
106
6
0.08
11.83
6
1

Classes

Class Line # Actions
TableTest 33 71 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 6 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 the table support inside the WYSIWYG editor.
30    *
31    * @version $Id: cdd178fb6f64d108677eee11c5090e772fed9677 $
32    */
 
33    public class TableTest extends AbstractWysiwygTestCase
34    {
35    public static final String ROWS_SELECTOR = "//input[@title = 'Row count']";
36   
37    public static final String COLUMNS_SELECTOR = "//input[@title = 'Column count']";
38   
39    /**
40    * The caret should be moved to the next or previous cell, depending on the Shift key.
41    *
42    * @see XWIKI-3043: Prevent tab from moving focus from the new WYSIWYG editor
43    */
 
44  1 toggle @Test
45    public void testTabInTableCell()
46    {
47  1 insertTable();
48  1 typeText("a");
49    // Shit+Tab should do nothing since we are in the first cell.
50  1 typeShiftTab();
51  1 typeText("b");
52  1 typeTab(3);
53    // Delete the non-breaking space that is found by default in empty table cells.
54  1 typeDelete();
55  1 typeText("c");
56    // Tab should insert a new row since we are in the last cell.
57  1 typeTab();
58    // Delete the non-breaking space that is found by default in empty table cells.
59  1 typeDelete();
60  1 typeText("d");
61  1 typeShiftTab(4);
62  1 typeText("e");
63  1 switchToSource();
64  1 assertSourceText("|=eab|= \n| |c\n|d| ");
65    }
66   
67    /**
68    * @see XWIKI-3090: Cannot move cursor before table
69    * @see XWIKI-3089: Cannot move cursor after table
70    * @see XWIKI-3829: Use Control/Meta+Up/Down arrow keys to navigate before/after a table
71    */
 
72  1 toggle @Test
73    public void testMoveCaretBeforeAndAfterTable()
74    {
75  1 switchToSource();
76  1 setSourceText("|=Space|=Page\n|Main|WebHome");
77  1 switchToWysiwyg();
78   
79    // Place the caret in one of the table cells.
80  1 moveCaret("document.body.getElementsByTagName('table')[0].rows[0].cells[0].firstChild", 2);
81   
82    // Move the caret before the table and type some text. This time using Control+Up.
83  1 getRichTextArea().sendKeys(Keys.chord(Keys.CONTROL, Keys.ARROW_UP), "1");
84   
85    // Place the caret again in one of the table cells.
86  1 moveCaret("document.body.getElementsByTagName('table')[0].rows[0].cells[0].firstChild", 2);
87   
88    // Move the caret before the table and type some text. This time using Meta+Up.
89    // FIXME: Selenium doesn't simulate correctly the Meta key.
90    // getRichTextArea().sendKeys(Keys.chord(Keys.META, Keys.ARROW_UP), "2");
91   
92    // Place the caret again in one of the table cells.
93  1 moveCaret("document.body.getElementsByTagName('table')[0].rows[1].cells[1].firstChild", 3);
94   
95    // Move the caret after the table and type some text. This time using Control+Down.
96  1 getRichTextArea().sendKeys(Keys.chord(Keys.CONTROL, Keys.ARROW_DOWN), "4");
97   
98    // Place the caret again in one of the table cells.
99  1 moveCaret("document.body.getElementsByTagName('table')[0].rows[1].cells[1].firstChild", 3);
100   
101    // Move the caret after the table and type some text. This time using Meta+Down.
102    // FIXME: Selenium doesn't simulate correctly the Meta key.
103    // getRichTextArea().sendKeys(Keys.chord(Keys.META, Keys.ARROW_DOWN), "3");
104   
105  1 switchToSource();
106  1 assertSourceText("1\n\n|=Space|=Page\n|Main|WebHome\n\n4");
107    }
108   
109    /**
110    * @see XWIKI-4017: The close X button from the "Insert Table" dialog acts like the "Insert" button after a table
111    * has been inserted.
112    */
 
113  1 toggle @Test
114    public void testCancelInsertTable()
115    {
116  1 openInsertTableDialog();
117    // Cancel the insert table operation.
118  1 closeDialog();
119   
120    // Insert a default table this time.
121  1 insertTable();
122   
123    // Move the caret after the table.
124  1 getRichTextArea().sendKeys(Keys.chord(Keys.CONTROL, Keys.ARROW_DOWN));
125   
126  1 openInsertTableDialog();
127    // Cancel the insert table operation again.
128  1 closeDialog();
129   
130    // Check the result.
131  1 switchToSource();
132  1 assertSourceText("|= |= \n| | \n");
133    }
134   
135    /**
136    * @see XWIKI-4231: "Enter" doesn't work in the Table Dialog
137    */
 
138  1 toggle @Test
139    public void testEnterInTableConfigDialog()
140    {
141  1 openInsertTableDialog();
142    // Make sure the input fields have valid data.
143  1 getSelenium().type(ROWS_SELECTOR, "1");
144  1 getSelenium().type(COLUMNS_SELECTOR, "1");
145  1 getSelenium().uncheck("//div[@class = 'xDialogBody']//input[@type = 'checkbox']");
146    // Press Enter
147  1 getSelenium().typeKeys(ROWS_SELECTOR, "\\13");
148    // Check the result.
149  1 waitForDialogToClose();
150  1 switchToSource();
151  1 assertSourceText("| ");
152    }
153   
154    /**
155    * Tests if the values entered on the table configuration dialog are validated and if proper validation message are
156    * displayed.
157    */
 
158  1 toggle @Test
159    public void testValidateTableConfigDialog()
160    {
161  1 openInsertTableDialog();
162    // Validation messages should not be present.
163  1 assertFieldErrorIsNotPresent();
164    // Enter invalid values.
165  1 getSelenium().type(ROWS_SELECTOR, "");
166  1 getSelenium().type(COLUMNS_SELECTOR, "0");
167    // Try to submit.
168  1 getSelenium().click("//button[text()=\"Insert Table\"]");
169    // Check that the first input is in error
170  1 assertFieldErrorIsPresent("Please enter a number greater than zero.", "//input[@title = 'Row count']");
171    // Check that the second input is in error
172  1 assertFieldErrorIsPresent("Please enter a number greater than zero.", "//input[@title = 'Column count']");
173    // Check that there are actually 2 error messages visible
174  1 assertEquals(2, getSelenium().getXpathCount("//div[contains(@class, 'xErrorMsg') and @style = '']"));
175    // Fix the value of the first input.
176  1 getSelenium().type(ROWS_SELECTOR, "1");
177    // Try to submit again.
178  1 getSelenium().click("//button[text()=\"Insert Table\"]");
179    // Check if the validation message is present for the second field.
180  1 assertFieldErrorIsPresent("Please enter a number greater than zero.", "//input[@title = 'Column count']");
181    // Cancel the dialog and open it again.
182  1 closeDialog();
183  1 openInsertTableDialog();
184    // The previous validation message should not be present.
185  1 assertFieldErrorIsNotPresent();
186    // The dialog should have preserved its state so try to submit again.
187  1 getSelenium().click("//button[text()=\"Insert Table\"]");
188    // Check if the validation message is present for the second field.
189  1 assertFieldErrorIsPresent("Please enter a number greater than zero.", "//input[@title = 'Column count']");
190    // Fix the error and submit.
191  1 getSelenium().type(COLUMNS_SELECTOR, "1");
192  1 getSelenium().click("//button[text()=\"Insert Table\"]");
193  1 waitForDialogToClose();
194    // Check the result.
195  1 switchToSource();
196  1 assertSourceText("|= ");
197    }
198   
199    /**
200    * @see XWIKI-7606: Cannot delete a table row when the selection spans across multiple cells
201    */
 
202  1 toggle @Test
203    public void testDeleteRowWhenSelectionSpansAcrossMultipleCells()
204    {
205    // Insert a table.
206  1 switchToSource();
207  1 setSourceText("|=A|=B|=C\n|1|2|3\n|x|y|z");
208  1 switchToWysiwyg();
209   
210    // Select the text from the first two cells of the second row.
211  1 select("document.body.getElementsByTagName('td')[0].firstChild", 0,
212    "document.body.getElementsByTagName('td')[1].firstChild", 1);
213   
214    // Delete the row.
215  1 clickMenu("Table");
216  1 assertTrue(isMenuEnabled("Delete Row"));
217  1 clickMenu("Delete Row");
218   
219    // Check the result.
220  1 switchToSource();
221  1 assertSourceText("|=A|=B|=C\n|x|y|z");
222    }
223    }