summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/helpers/test_utils.js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-01-03 12:28:52 +0100
committerChristophe Simonis <chs@odoo.com>2018-01-03 12:28:52 +0100
commit362f0489d07d5bcd3673278e93848d0ea3d177a8 (patch)
treece164613ca633d736bf41c5b3d02b8ee541baa89 /addons/web/static/tests/helpers/test_utils.js
parenta39491d459f7a70af21bce1f45434bab05f1c284 (diff)
parentfe22a0f9ca92ef0e76bb2f730a2b22da500db5dd (diff)
[MERGE] forward port branch 11.0 up to fe22a0f9ca9
Diffstat (limited to 'addons/web/static/tests/helpers/test_utils.js')
-rw-r--r--addons/web/static/tests/helpers/test_utils.js70
1 files changed, 61 insertions, 9 deletions
diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js
index 37a98de1746..e049ba968b2 100644
--- a/addons/web/static/tests/helpers/test_utils.js
+++ b/addons/web/static/tests/helpers/test_utils.js
@@ -434,11 +434,16 @@ function dragAndDrop($el, $to, options) {
elementCenter.top += $el.outerHeight()/2;
var toOffset = $to.offset();
+ toOffset.top += $to.outerHeight()/2;
toOffset.left += $to.outerWidth()/2;
- if (position === 'center') {
- toOffset.top += $to.outerHeight()/2;
+ if (position === 'top') {
+ toOffset.top -= $to.outerHeight()/2;
} else if (position === 'bottom') {
- toOffset.top += $to.outerHeight();
+ toOffset.top += $to.outerHeight()/2;
+ } else if (position === 'left') {
+ toOffset.left -= $to.outerWidth()/2;
+ } else if (position === 'right') {
+ toOffset.left += $to.outerWidth()/2;
}
$el.trigger($.Event("mousedown", {
@@ -551,6 +556,51 @@ function removeSrcAttribute($el, widget) {
});
}
+var patches = {};
+/**
+ * Patches a given Class with the given properties.
+ *
+ * @param {Class} Klass
+ * @param {Object} props
+ */
+function patch (Klass, props) {
+ var patchID = _.uniqueId('patch_');
+ Klass.__patchID = patchID;
+ patches[patchID] = {
+ Klass: Klass,
+ otherPatchedProps: [],
+ ownPatchedProps: [],
+ };
+ _.each(props, function (value, key) {
+ if (Klass.prototype.hasOwnProperty(key)) {
+ patches[patchID].ownPatchedProps.push({
+ key: key,
+ initialValue: Klass.prototype[key],
+ });
+ } else {
+ patches[patchID].otherPatchedProps.push(key);
+ }
+ });
+ Klass.include(props);
+}
+/**
+ * Unpatches a given Class.
+ *
+ * @param {Class} Klass
+ */
+function unpatch(Klass) {
+ var patchID = Klass.__patchID;
+ var patch = patches[patchID];
+ _.each(patch.ownPatchedProps, function (p) {
+ Klass[p.key] = p.initialValue;
+ });
+ _.each(patch.otherPatchedProps, function (key) {
+ delete Klass.prototype[key];
+ });
+ delete patches[patchID];
+ delete Klass.__patchID;
+}
+
// Loading static files cannot be properly simulated when their real content is
// really needed. This is the case for static XML files so we load them here,
// before starting the qunit test suite.
@@ -566,18 +616,20 @@ return $.when(
QUnit.start();
}, 0);
return {
- intercept: intercept,
- observe: observe,
- createView: createView,
+ addMockEnvironment: addMockEnvironment,
createAsyncView: createAsyncView,
createModel: createModel,
createParent: createParent,
- addMockEnvironment: addMockEnvironment,
+ createView: createView,
dragAndDrop: dragAndDrop,
+ intercept: intercept,
+ observe: observe,
+ patch: patch,
+ removeSrcAttribute: removeSrcAttribute,
+ triggerKeypressEvent: triggerKeypressEvent,
triggerMouseEvent: triggerMouseEvent,
triggerPositionalMouseEvent: triggerPositionalMouseEvent,
- triggerKeypressEvent: triggerKeypressEvent,
- removeSrcAttribute: removeSrcAttribute,
+ unpatch: unpatch,
};
});