From 10a467e3e114e8cda7d9d8a23a0d9ef76d5c823f Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Sun, 1 Dec 2019 15:44:38 +0000 Subject: [PATCH] [FIX] web_editor: resolve conflict between tests and options mutex In a normal flux, this happen when an option is hovered and left: 1) Hover event -> the widget goes in 'preview' state and notifies a preview to the option 2) The preview is received by the option and, after an internal mutex resolution, the option enables its methods with the widget values. 3) Leave event -> same as (1), except leaving 'preview' state 4) same as (2), except receiving a 'reset' Everything is fine and correctly managed... except if a JS code triggers both hover and leave events in the same execution... and this is what tests are doing. In this case, as (2) executes after an internal mutex resolution, the points (2) and (3) were inverted, so the widget left the 'preview' state before (2) got the widget values. Maybe the test system has to be improved, but this commit solves the problem for this case explicitely. Part of https://github.com/odoo/odoo/pull/40282 In preparation of task-2122935 and other tasks --- .../static/src/js/editor/snippets.options.js | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 81591af81a2..ca8ef46b4d9 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -329,10 +329,24 @@ const UserValueWidget = Widget.extend({ break; } case true: { + // TODO improve this. The preview state has to be updated only + // when the actual option _select is gonna be called... but this + // is delayed by a mutex. So, during test tours, we would notify + // both 'preview' and 'reset' before the 'preview' handling is + // done: and so the widget would be considered not in preview + // during that preview action handling. + data.prepare = () => this.el.classList.add('o_we_preview'); this.trigger_up('user_value_preview', data); break; } default: { + // TODO improve this. The preview state has to be updated only + // when the actual option _select is gonna be called... but this + // is delayed by a mutex. So, during test tours, we would notify + // both 'preview' and 'reset' before the 'preview' handling is + // done: and so the widget would be considered not in preview + // during that preview action handling. + data.prepare = () => this.el.classList.remove('o_we_preview'); this.trigger_up('user_value_reset', data); } } @@ -395,7 +409,6 @@ const UserValueWidget = Widget.extend({ } ev.preventDefault(); - this.el.classList.add('o_we_preview'); this._notifyValueChange(true); }, /** @@ -414,7 +427,6 @@ const UserValueWidget = Widget.extend({ } ev.preventDefault(); - this.el.classList.remove('o_we_preview'); this._notifyValueChange('reset'); }, }); @@ -1584,6 +1596,9 @@ const SnippetOptionWidget = Widget.extend({ _onOptionPreview: function (ev) { ev.stopPropagation(); this._selectEventMutex.exec(() => { + if (ev.data.prepare) { + ev.data.prepare(); + } return this._select(true, ev.data.widget).then(() => { this.$target.trigger('snippet-option-preview', [this]); }); @@ -1599,6 +1614,9 @@ const SnippetOptionWidget = Widget.extend({ _onOptionSelection: function (ev) { ev.stopPropagation(); this._selectEventMutex.exec(() => { + if (ev.data.prepare) { + ev.data.prepare(); + } return this._select(false, ev.data.widget).then(() => { this.$target.trigger('snippet-option-change', [this]); }); @@ -1614,6 +1632,9 @@ const SnippetOptionWidget = Widget.extend({ _onOptionCancel: function (ev) { ev.stopPropagation(); this._selectEventMutex.exec(() => { + if (ev.data.prepare) { + ev.data.prepare(); + } return this._select('reset', ev.data.widget); }); },