From 9d0e2affff99152bf4e941e4a9ed9d95df8ab5fe Mon Sep 17 00:00:00 2001
From: Marius Dumitru Florea <marius@xwiki.com>
Date: Wed, 9 Oct 2024 16:33:59 +0300
Subject: [PATCH] XWIKI-22351: The autosave triggers a merge conflict sometimes
 even if there's no save done outside the realtime session * Update tests
 (when inserting a block widget from an empty paragraph, at the end of the
 edited content, the widget is inserted before that paragraph; the paragraph
 was previously wrongly considered as block separator in wiki syntax;
 moreover, CKEditor output a non-breaking space in empty paragraphs).

---
 .../test/it/org/xwiki/ckeditor/test/ui/ImageIT.java  | 12 ++++++------
 .../org/xwiki/ckeditor/test/ui/QuickActionsIT.java   |  5 ++---
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/xwiki-platform-core/xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-docker/src/test/it/org/xwiki/ckeditor/test/ui/ImageIT.java b/xwiki-platform-core/xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-docker/src/test/it/org/xwiki/ckeditor/test/ui/ImageIT.java
index 438e0d18928..dfe6af4ce9e 100644
--- a/xwiki-platform-core/xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-docker/src/test/it/org/xwiki/ckeditor/test/ui/ImageIT.java
+++ b/xwiki-platform-core/xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-docker/src/test/it/org/xwiki/ckeditor/test/ui/ImageIT.java
@@ -138,7 +138,7 @@ void insertImage(TestUtils setup, TestReference testReference) throws Exception
         // Verify that the content matches what we did using CKEditor.
         assertEquals("[[image:image.gif]]\n"
             + "\n"
-            + "[[Caption>>image:image.gif]]", savedPage.editWiki().getContent());
+            + "[[Caption>>image:image.gif]]\n\n ", savedPage.editWiki().getContent());
     }
 
     @Test
@@ -321,7 +321,7 @@ void imageWithCaption(TestUtils setup, TestReference testReference) throws Excep
         ViewPage savedPage = wysiwygEditPage.clickSaveAndView();
 
         // Verify that the content matches what we did using CKEditor.
-        assertEquals("[[Caption>>image:image.gif||data-xwiki-image-style-alignment=\"center\"]]",
+        assertEquals("[[Caption>>image:image.gif||data-xwiki-image-style-alignment=\"center\"]]\n\n ",
             savedPage.editWiki().getContent());
 
         // Re-edit the page.
@@ -337,7 +337,7 @@ void imageWithCaption(TestUtils setup, TestReference testReference) throws Excep
         savedPage = wysiwygEditPage.clickSaveAndView();
 
         // Verify that the content matches what we did using CKEditor.
-        assertEquals("[[image:image.gif||data-xwiki-image-style-alignment=\"center\"]]",
+        assertEquals("[[image:image.gif||data-xwiki-image-style-alignment=\"center\"]]\n\n ",
             savedPage.editWiki().getContent());
 
         // Edit again to set the caption a second time.
@@ -353,7 +353,7 @@ void imageWithCaption(TestUtils setup, TestReference testReference) throws Excep
         savedPage = wysiwygEditPage.clickSaveAndView();
 
         // Verify that the content matches what we did using CKEditor.
-        assertEquals("[[Caption>>image:image.gif||data-xwiki-image-style-alignment=\"center\"]]",
+        assertEquals("[[Caption>>image:image.gif||data-xwiki-image-style-alignment=\"center\"]]\n\n ",
             savedPage.editWiki().getContent());
     }
 
@@ -456,7 +456,7 @@ void imageWithLinkAndCaptionUI(TestUtils setup, TestReference testReference) thr
         ViewPage savedPage = wysiwygEditPage.clickSaveAndView();
 
         assertEquals("[[~[~[Caption~>~>image:image.gif~|~|data-xwiki-image-style-alignment=\"center\"~]~]"
-            + ">>doc:Main.WebHome]]", savedPage.editWiki().getContent());
+            + ">>doc:Main.WebHome]]\n\n ", savedPage.editWiki().getContent());
         // Test that when re-editing the image, the link, caption and alignment are still set.
         wysiwygEditPage = savedPage.editWYSIWYG();
         editor = new CKEditor("content").waitToLoad();
@@ -486,7 +486,7 @@ void imageWithLinkAndCaptionUI(TestUtils setup, TestReference testReference) thr
         savedPage = wysiwygEditPage.clickSaveAndView();
 
         assertEquals("[[~[~[New Caption~>~>image:image.gif~|~|data-xwiki-image-style-alignment=\"center\"~]~]"
-            + ">>doc:Main.WebHome]]", savedPage.editWiki().getContent());
+            + ">>doc:Main.WebHome]]\n\n ", savedPage.editWiki().getContent());
     }
 
     @Test
diff --git a/xwiki-platform-core/xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-docker/src/test/it/org/xwiki/ckeditor/test/ui/QuickActionsIT.java b/xwiki-platform-core/xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-docker/src/test/it/org/xwiki/ckeditor/test/ui/QuickActionsIT.java
index 8c1197d9cef..58aec78d224 100644
--- a/xwiki-platform-core/xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-docker/src/test/it/org/xwiki/ckeditor/test/ui/QuickActionsIT.java
+++ b/xwiki-platform-core/xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-docker/src/test/it/org/xwiki/ckeditor/test/ui/QuickActionsIT.java
@@ -479,10 +479,9 @@ void toc()
         qa.waitForItemSelected("/toc", "Table of Contents");
         textArea.sendKeys(Keys.ENTER);
         qa.waitForItemSubmitted();
+        textArea.waitForContentRefresh();
 
-        textArea = editor.getRichTextArea();
-
-        assertSourceEquals("{{toc/}}\n");
+        assertSourceEquals("{{toc/}}\n\n ");
     }
 
     @Test
-- 
GitLab