Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,18 @@ public void executeOnEditedContent(Runnable runnable)
}
}
}

/**
* Marks every CKEditor instance on the current page as clean, so that leaving the page doesn't ask the user to
* confirm that they want to discard their changes. Meant to be called when cleaning up after a test that may have
* been interrupted in the middle of an edit: the confirmation dialog would otherwise block the next navigation,
* including the navigation done by the tests that come after in the same browser session.
*
* @since 18.8.0RC1
*/
public static void discardUnsavedChanges()
{
getUtil().getDriver()
.executeScript("Object.values(window.CKEDITOR?.instances ?? {}).forEach(editor => editor.resetDirty());");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.xwiki.edit.test.ui;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -90,6 +91,23 @@ void beforeAll(TestUtils testUtils) throws Exception
testUtils.createUserAndLogin(USER_NAME, "pa$$word", "editor", "Wysiwyg");
}

@AfterEach
void discardUnsavedChanges(TestUtils testUtils)
{
// A test failing in the middle of an edit leaves the page with unsaved changes, so the next navigation shows
// the leave confirmation. All the tests of AllIT share a single browser session, so that dialog blocks every
// test that comes after, in this class and in the other nested ones. Discarding the changes here keeps a
// failure contained to the test that caused it.

// The comment, the annotation and the in-place property are edited on a view page, where there is no edit
// mode to leave: the leave confirmation comes from the CKEditor instances themselves being dirty.
CKEditor.discardUnsavedChanges();

// The object editor asks for confirmation based on its own form state, which only leaving the edit mode
// resets. Done after the editors are marked clean, so that leaving doesn't trigger the dialog itself.
testUtils.maybeLeaveEditMode();
}

/**
* Upload an image while editing a TextArea property in the object editor, using basically the same setup as
* {@code TextAreaIT}.
Expand Down