diff options
| author | Christophe Matthieu <chm@odoo.com> | 2018-07-19 09:15:56 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2018-08-13 17:09:28 +0200 |
| commit | 79a0f401a4e9492b7a086450d1bc1851336b2eb6 (patch) | |
| tree | a7dbb10aab25f9611d3c56b5764bfd73aca5f232 /addons/web/static/tests/helpers/test_utils.js | |
| parent | 5779807a316f2cbd71f533fbe1191dcba219fba9 (diff) | |
[IMP] web: add options to `dragAndDrop` test util function
There is now an option `continueMove` that can be used to extend a previous drag
done in this function.
The option `position` has also been extended to take an object (to precise the
move position).
Diffstat (limited to 'addons/web/static/tests/helpers/test_utils.js')
| -rw-r--r-- | addons/web/static/tests/helpers/test_utils.js | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js index b9a783f3bbd..767f0de6dbc 100644 --- a/addons/web/static/tests/helpers/test_utils.js +++ b/addons/web/static/tests/helpers/test_utils.js @@ -553,27 +553,35 @@ function createParent(params) { * @param {jqueryElement} $el * @param {jqueryElement} $to * @param {Object} [options] - * @param {string} [options.position=center] target position - * @param {string} [options.disableDrop=false] whether to trigger the drop action + * @param {string|Object} [options.position='center'] target position: + * can either be one of {'top', 'bottom', 'left', 'right'} or + * an object with two attributes (top and left)) + * @param {boolean} [options.disableDrop=false] whether to trigger the drop action + * @param {boolean} [options.continueMove=false] whether to trigger the + * mousedown action (will only work after another call of this function with + * without this option) */ function dragAndDrop($el, $to, options) { var position = (options && options.position) || 'center'; var elementCenter = $el.offset(); - elementCenter.left += $el.outerWidth()/2; - elementCenter.top += $el.outerHeight()/2; - var toOffset = $to.offset(); - toOffset.top += $to.outerHeight()/2; - toOffset.left += $to.outerWidth()/2; - var vertical_offset = (toOffset.top < elementCenter.top) ? -1 : 1; - if (position === 'top') { - toOffset.top -= $to.outerHeight()/2 + vertical_offset; - } else if (position === 'bottom') { - toOffset.top += $to.outerHeight()/2 - vertical_offset; - } else if (position === 'left') { - toOffset.left -= $to.outerWidth()/2; - } else if (position === 'right') { + + if (_.isObject(position)) { + toOffset.top += position.top; + toOffset.left += position.left; + } else { + toOffset.top += $to.outerHeight()/2; toOffset.left += $to.outerWidth()/2; + var vertical_offset = (toOffset.top < elementCenter.top) ? -1 : 1; + if (position === 'top') { + toOffset.top -= $to.outerHeight()/2 + vertical_offset; + } else if (position === 'bottom') { + toOffset.top += $to.outerHeight()/2 - vertical_offset; + } else if (position === 'left') { + toOffset.left -= $to.outerWidth()/2; + } else if (position === 'right') { + toOffset.left += $to.outerWidth()/2; + } } if ($to[0].ownerDocument !== document) { @@ -583,11 +591,16 @@ function dragAndDrop($el, $to, options) { toOffset.top += bound.top; } - $el.trigger($.Event("mousedown", { - which: 1, - pageX: elementCenter.left, - pageY: elementCenter.top - })); + if (!(options && options.continueMove)) { + elementCenter.left += $el.outerWidth()/2; + elementCenter.top += $el.outerHeight()/2; + + $el.trigger($.Event("mousedown", { + which: 1, + pageX: elementCenter.left, + pageY: elementCenter.top + })); + } $el.trigger($.Event("mousemove", { which: 1, |
