[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
This commit is contained in:
qsm-odoo
2019-12-01 16:00:06 +00:00
parent 3be9ae5672
commit 10a467e3e1
@@ -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);
});
},