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

File SubmitTest.java

 

Code metrics

0
45
8
1
178
86
8
0.18
5.62
8
1

Classes

Class Line # Actions
SubmitTest 37 45 0% 8 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 java.net.MalformedURLException;
23    import java.net.URL;
24   
25    import org.apache.commons.lang3.RandomStringUtils;
26    import org.junit.Test;
27    import org.openqa.selenium.Keys;
28    import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase;
29   
30    import static org.junit.Assert.*;
31   
32    /**
33    * Functional tests for the submit support inside the WYSIWYG editor.
34    *
35    * @version $Id: ae33c6da181eae214f11e0913281a18e1046ae5c $
36    */
 
37    public class SubmitTest extends AbstractWysiwygTestCase
38    {
39    /**
40    * Loads the editor and submits its content without changing it.
41    */
 
42  1 toggle @Test
43    public void testSubmitAfterEditorIsLoadedAndHasFocus()
44    {
45    // Set the content without saving it.
46  1 clickEditPageInWikiSyntaxEditor();
47  1 setFieldValue("content", "a**b**c");
48  1 clickEditPageInWysiwyg();
49  1 waitForEditorToLoad();
50    // Focus the editor.
51  1 focusRichTextArea();
52    // Switch back to Wiki editor and assert the content.
53  1 clickEditPageInWikiSyntaxEditor();
54  1 assertEquals("a**b**c", getFieldValue("content"));
55    }
56   
57    /**
58    * Loads the editor and submits its content without changing it and without focusing the rich text area.
59    */
 
60  1 toggle @Test
61    public void testSubmitAfterEditorIsLoadedWithoutGainingFocus()
62    {
63    // Set the content without saving it.
64  1 clickEditPageInWikiSyntaxEditor();
65  1 setFieldValue("content", "1**2**3");
66    // Switch to WYSIWYG editor but don't focus the rich text area.
67  1 clickEditPageInWysiwyg();
68  1 waitForEditorToLoad();
69    // Switch back to Wiki editor and assert the content.
70  1 clickEditPageInWikiSyntaxEditor();
71  1 assertEquals("1**2**3", getFieldValue("content"));
72    }
73   
74    /**
75    * Loads the editor and submits its content. We test if the content of the rich text area is stored when the rich
76    * text area looses focus.
77    */
 
78  1 toggle @Test
79    public void testSubmitAfterChangingContentWithFocus()
80    {
81    // Focus the editor.
82  1 focusRichTextArea();
83    // Change the content of the rich text area.
84  1 setContent("x<em>y</em>z");
85    // Blur the rich text area to save the new content.
86  1 blurRichTextArea();
87    // Switch back to Wiki editor and assert the content.
88  1 clickEditPageInWikiSyntaxEditor();
89  1 assertEquals("x//y//z", getFieldValue("content"));
90    }
91   
92    /**
93    * Loads the editor and submits its content after changing it without focusing the rich text area. We test if the
94    * content of the rich text area is stored when the HTML form hosting the rich text area is submitted.
95    */
 
96  1 toggle @Test
97    public void testSubmitAfterChangingContentWithoutFocus()
98    {
99    // Focus the title input to be sure the rich text area doesn't have the focus when its content is changed.
100  1 getSelenium().click("title");
101    // Change the content of the rich text area when it doesn't have the focus.
102  1 setContent("u<tt>v</tt>w");
103    // Save and view.
104  1 clickEditSaveAndView();
105    // Open the Wiki editor and assert the content.
106  1 clickEditPageInWikiSyntaxEditor();
107  1 assertEquals("u##v##w", getFieldValue("content"));
108    }
109   
110    /**
111    * @see XWIKI-5560: Shortcut key malfunction when saving a page within source view.
112    * @throws MalformedURLException
113    */
 
114  1 toggle @Test
115    public void testShortcutsForSaveAndView() throws MalformedURLException
116    {
117    // Switch to source editor and change the contents.
118  1 switchToSource();
119    // Type some content in the source editor
120  1 String content = RandomStringUtils.randomAlphanumeric(5);
121  1 setSourceText(content);
122    // Type alt+s to save and view the contents.
123  1 typeShortcutsForSaveAndView();
124    // Get the loaded page's URL
125  1 URL viewPageUrl = new URL(getSelenium().getLocation());
126    // Assert the page indeed redirect to the view mode for the page saved.
127  1 assertEquals(viewPageUrl.getPath(), getUrl(getClass().getSimpleName(), getTestMethodName()));
128    // Open the Wiki editor and assert the content.
129  1 clickEditPageInWikiSyntaxEditor();
130  1 assertEquals(content, getFieldValue("content"));
131    }
132   
133    /**
134    * @see XWIKI-5560: Shortcut key malfunction when saving a page within source view.
135    */
 
136  1 toggle @Test
137    public void testShortcutsForSaveAndContinue()
138    {
139    // Switch to source editor and change the contents.
140  1 switchToSource();
141    // Get current URL before saving the wiki page
142  1 String currentUrlBeforeSave = getSelenium().getLocation();
143  1 String content = RandomStringUtils.randomAlphanumeric(5);
144    // Type some content in the source editor
145  1 setSourceText(content);
146    // type alt+shift+s to save the contents and continue to edit.
147  1 typeShortcutsForSaveAndContinue();
148    // Get current URL after saving the wiki page
149  1 String currentUrlAfterSave = getSelenium().getLocation();
150    // Assert that the page stays in the same edit mode after saving the page
151  1 assertEquals(currentUrlBeforeSave, currentUrlAfterSave);
152    // Cancel editing. We don't go directly to wiki edit mode because the content would be preserved even if it
153    // wasn't saved.
154  1 clickEditCancelEdition();
155    // Open the Wiki editor and assert the content.
156  1 clickEditPageInWikiSyntaxEditor();
157  1 assertEquals(content, getFieldValue("content"));
158    }
159   
160    /**
161    * Press Alt+s to save and view.
162    */
 
163  1 toggle private void typeShortcutsForSaveAndView()
164    {
165  1 getSourceTextArea().sendKeys(Keys.chord(Keys.ALT, "s"));
166    // Wait for view page to load.
167  1 waitPage();
168    }
169   
170    /**
171    * Press Alt+shift+s to save and continue.
172    */
 
173  1 toggle private void typeShortcutsForSaveAndContinue()
174    {
175  1 getSourceTextArea().sendKeys(Keys.chord(Keys.ALT, Keys.SHIFT, "s"));
176  1 waitForNotificationSuccessMessage("Saved");
177    }
178    }