[FIX] web_editor: ensure standard selection before running tests
Some editor tests may be sensitive to the existence or not of a selection in the DOM before initializing the editor. The first test to be run won't have a selection before the editable is initialized, but every subsequent test will (removing the test node add the end moves the selection to its parent). One particularly problematic consequence concerns tests that would fail with an initial selection but succeed otherwise. Such a test would only fail when run after another test, but not when run alone. This commit prevents this confusing debugging situation (and potential false negatives) by setting a selection at the beginning of the testNode by default before running each test, ensuring that each test has the same initial conditions. Part-of: odoo/odoo#141303
This commit is contained in:
committed by
Sébastien Geelen (sge)
parent
fff405a6c2
commit
e5d7affed5
@@ -307,6 +307,12 @@ export async function testEditor(Editor = OdooEditor, spec, options = {}) {
|
||||
// the editor as otherwise those would genererate mutations the editor would
|
||||
// consider and the tests would make no sense.
|
||||
testNode.innerHTML = spec.contentBefore;
|
||||
// Setting a selection in the DOM before initializing the editor to ensure
|
||||
// every test is run with the same preconditions.
|
||||
setTestSelection({
|
||||
anchorNode: testNode.parentElement, anchorOffset: 0,
|
||||
focusNode: testNode.parentElement, focusOffset: 0,
|
||||
});
|
||||
const selection = parseTextualSelection(testNode);
|
||||
|
||||
const editor = new Editor(testNode, Object.assign({ toSanitize: false }, options));
|
||||
|
||||
Reference in New Issue
Block a user