Skip to content

Commit 7e2bd7d

Browse files
vmassolclaude
andcommitted
XWIKI-24806: TextAreaImageUploadIT is flickering and its missing edit-mode cleanup fails the rest of AllIT (#6309)
* Discard the unsaved changes after each test, so that a failure no longer leaves an armed beforeunload handler that blocks every test running after it in the shared browser session. * Add CKEditor#discardUnsavedChanges() to the page objects, marking every editor instance on the page as clean. This is what arms the leave confirmation for the comment, the annotation and the in-place property, all edited on a view page where there is no edit mode to leave. * Leave the edit mode for the object editor, which asks for confirmation based on its own form state. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> (cherry picked from commit 879250a)
1 parent 2913491 commit 7e2bd7d

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

  • xwiki-platform-core
    • xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-pageobjects/src/main/java/org/xwiki/ckeditor/test/po
    • xwiki-platform-edit/xwiki-platform-edit-test/xwiki-platform-edit-test-docker/src/test/it/org/xwiki/edit/test/ui

xwiki-platform-core/xwiki-platform-ckeditor/xwiki-platform-ckeditor-test/xwiki-platform-ckeditor-test-pageobjects/src/main/java/org/xwiki/ckeditor/test/po/CKEditor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,18 @@ public void executeOnEditedContent(Runnable runnable)
170170
}
171171
}
172172
}
173+
174+
/**
175+
* Marks every CKEditor instance on the current page as clean, so that leaving the page doesn't ask the user to
176+
* confirm that they want to discard their changes. Meant to be called when cleaning up after a test that may have
177+
* been interrupted in the middle of an edit: the confirmation dialog would otherwise block the next navigation,
178+
* including the navigation done by the tests that come after in the same browser session.
179+
*
180+
* @since 18.8.0RC1
181+
*/
182+
public static void discardUnsavedChanges()
183+
{
184+
getUtil().getDriver()
185+
.executeScript("Object.values(window.CKEDITOR?.instances ?? {}).forEach(editor => editor.resetDirty());");
186+
}
173187
}

xwiki-platform-core/xwiki-platform-edit/xwiki-platform-edit-test/xwiki-platform-edit-test-docker/src/test/it/org/xwiki/edit/test/ui/TextAreaImageUploadIT.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package org.xwiki.edit.test.ui;
2121

22+
import org.junit.jupiter.api.AfterEach;
2223
import org.junit.jupiter.api.BeforeAll;
2324
import org.junit.jupiter.api.Order;
2425
import org.junit.jupiter.api.Test;
@@ -86,6 +87,23 @@ void beforeAll(TestUtils testUtils) throws Exception
8687
testUtils.addClassProperty(CLASS_REFERENCE, PROPERTY_NAME, "TextArea");
8788
}
8889

90+
@AfterEach
91+
void discardUnsavedChanges(TestUtils testUtils)
92+
{
93+
// A test failing in the middle of an edit leaves the page with unsaved changes, so the next navigation shows
94+
// the leave confirmation. All the tests of AllIT share a single browser session, so that dialog blocks every
95+
// test that comes after, in this class and in the other nested ones. Discarding the changes here keeps a
96+
// failure contained to the test that caused it.
97+
98+
// The comment, the annotation and the in-place property are edited on a view page, where there is no edit
99+
// mode to leave: the leave confirmation comes from the CKEditor instances themselves being dirty.
100+
CKEditor.discardUnsavedChanges();
101+
102+
// The object editor asks for confirmation based on its own form state, which only leaving the edit mode
103+
// resets. Done after the editors are marked clean, so that leaving doesn't trigger the dialog itself.
104+
testUtils.maybeLeaveEditMode();
105+
}
106+
89107
/**
90108
* Upload an image while editing a TextArea property in the object editor, using basically the same setup as
91109
* {@code TextAreaIT}.

0 commit comments

Comments
 (0)