Skip to content
Snippets Groups Projects
Commit 99182b77 authored by Marius Dumitru Florea's avatar Marius Dumitru Florea
Browse files

XWIKI-22221: Saving from Inplace Edit mode, after switching to Source, breaks the content

* Bulletproof the code that detects if we submit the raw content or the rendered content.

(cherry picked from commit 37464645)
parent f49a87df
No related branches found
No related tags found
No related merge requests found
...@@ -296,6 +296,8 @@ ...@@ -296,6 +296,8 @@
}); });
$(document).on('xwiki:actions:beforeSave.contentEditor', function(event) { $(document).on('xwiki:actions:beforeSave.contentEditor', function(event) {
config.document[editor.mode === 'source' ? 'content' : 'renderedContent'] = editor.getData(); config.document[editor.mode === 'source' ? 'content' : 'renderedContent'] = editor.getData();
// Delete the document content field that is not used so that the in-place editor knows what to submit on save.
delete config.document[editor.mode === 'source' ? 'renderedContent' : 'content'];
config.document.syntax = editor.config.sourceSyntax; config.document.syntax = editor.config.sourceSyntax;
}); });
$(document).one('xwiki:actions:view.contentEditor', function(event, data) { $(document).one('xwiki:actions:view.contentEditor', function(event, data) {
......
...@@ -96,6 +96,12 @@ ...@@ -96,6 +96,12 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-ckeditor-test-pageobjects</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<testSourceDirectory>src/test/it</testSourceDirectory> <testSourceDirectory>src/test/it</testSourceDirectory>
......
...@@ -28,7 +28,12 @@ ...@@ -28,7 +28,12 @@
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.openqa.selenium.Alert; import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.ExpectedConditions;
import org.xwiki.ckeditor.test.po.AutocompleteDropdown;
import org.xwiki.ckeditor.test.po.CKEditor;
import org.xwiki.ckeditor.test.po.RichTextAreaElement;
import org.xwiki.edit.test.po.InplaceEditablePage; import org.xwiki.edit.test.po.InplaceEditablePage;
import org.xwiki.test.docker.junit5.TestReference; import org.xwiki.test.docker.junit5.TestReference;
import org.xwiki.test.docker.junit5.UITest; import org.xwiki.test.docker.junit5.UITest;
...@@ -135,6 +140,53 @@ void editInplace(TestUtils setup, TestReference testReference) ...@@ -135,6 +140,53 @@ void editInplace(TestUtils setup, TestReference testReference)
@Test @Test
@Order(2) @Order(2)
void saveFromSourceMode(TestUtils setup, TestReference testReference)
{
// Enter in-place edit mode.
InplaceEditablePage viewPage = new InplaceEditablePage().editInplace();
CKEditor ckeditor = new CKEditor("content");
RichTextAreaElement richTextArea = ckeditor.getRichTextArea();
richTextArea.clear();
// Insert a macro that is editable in-line.
richTextArea.sendKeys("/inf");
AutocompleteDropdown qa = new AutocompleteDropdown();
qa.waitForItemSelected("/inf", "Info Box");
richTextArea.sendKeys(Keys.ENTER);
qa.waitForItemSubmitted();
// The content is reloaded after the macro is inserted.
ckeditor.getRichTextArea();
// Switch to Source mode and save without making any change.
ckeditor.getToolBar().toggleSourceMode();
assertEquals("", ckeditor.getSourceTextArea().getText());
viewPage.saveAndView();
// Edit again and check the source.
viewPage.editInplace();
ckeditor = new CKEditor("content");
// Focus the rich text area to get the floating toolbar.
ckeditor.getRichTextArea().click();
ckeditor.getToolBar().toggleSourceMode();
WebElement sourceTextArea = ckeditor.getSourceTextArea();
assertEquals("{{info}}\nType your information message here.\n{{/info}}", sourceTextArea.getAttribute("value"));
// Modify the soure and save twice, without any change in between.
sourceTextArea.clear();
sourceTextArea.sendKeys("{{success}}test{{/success}}");
viewPage.save().saveAndView();
// Edit again and check the source.
viewPage.editInplace();
ckeditor = new CKEditor("content");
ckeditor.getRichTextArea().click();
ckeditor.getToolBar().toggleSourceMode();
assertEquals("{{success}}\ntest\n{{/success}}", ckeditor.getSourceTextArea().getAttribute("value"));
}
@Test
@Order(3)
void editInPlaceWithMandatoryTitle(TestUtils setup, TestReference testReference) throws Exception void editInPlaceWithMandatoryTitle(TestUtils setup, TestReference testReference) throws Exception
{ {
// First of all, test that we can save with an empty title. // First of all, test that we can save with an empty title.
...@@ -172,7 +224,7 @@ void editInPlaceWithMandatoryTitle(TestUtils setup, TestReference testReference) ...@@ -172,7 +224,7 @@ void editInPlaceWithMandatoryTitle(TestUtils setup, TestReference testReference)
} }
@Test @Test
@Order(3) @Order(4)
void editInPlaceWithMandatoryVersionSummary(TestUtils setup, TestReference testReference) throws Exception void editInPlaceWithMandatoryVersionSummary(TestUtils setup, TestReference testReference) throws Exception
{ {
setup.loginAsSuperAdmin(); setup.loginAsSuperAdmin();
...@@ -222,7 +274,7 @@ void editInPlaceWithMandatoryVersionSummary(TestUtils setup, TestReference testR ...@@ -222,7 +274,7 @@ void editInPlaceWithMandatoryVersionSummary(TestUtils setup, TestReference testR
} }
@Test @Test
@Order(4) @Order(5)
void saveWithMergeReloadsEditor(TestUtils setup, TestReference testReference) throws Exception void saveWithMergeReloadsEditor(TestUtils setup, TestReference testReference) throws Exception
{ {
// Enter in-place edit mode. // Enter in-place edit mode.
......
...@@ -873,7 +873,7 @@ ...@@ -873,7 +873,7 @@
// Submit either the raw (source) content (no syntax conversion needed in this case) or the rendered content (HTML) // Submit either the raw (source) content (no syntax conversion needed in this case) or the rendered content (HTML)
// in which case we have to force the conversion to the document syntax on the server. // in which case we have to force the conversion to the document syntax on the server.
const submitRawContent = xwikiDocument.content !== xwikiDocument.originalDocument.content; const submitRawContent = typeof xwikiDocument.renderedContent !== 'string';
form.find('input[name="content"]').val(submitRawContent ? xwikiDocument.content : xwikiDocument.renderedContent); form.find('input[name="content"]').val(submitRawContent ? xwikiDocument.content : xwikiDocument.renderedContent);
form.find('input[name="RequiresHTMLConversion"]').prop('disabled', submitRawContent); form.find('input[name="RequiresHTMLConversion"]').prop('disabled', submitRawContent);
form.find('input[name="content_syntax"]').val(xwikiDocument.syntax).prop('disabled', submitRawContent); form.find('input[name="content_syntax"]').val(xwikiDocument.syntax).prop('disabled', submitRawContent);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment