summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/helpers/test_utils.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2018-02-08 14:43:14 +0100
committerAaron Bohy <aab@odoo.com>2018-02-12 11:13:42 +0100
commit5c67abd0d306f446af9df59cb6bca2428f17f7a9 (patch)
treeb31d3c4cabe945286001815f3d29c64473d263be /addons/web/static/tests/helpers/test_utils.js
parent107b82f6e13840c218706d55e434071fb2f2ed28 (diff)
[REF] web: tests: move calls to removeSrcAttribute
In the tests environment, we listen to the 'DOMNodeInserted' event to remove the src attribute of img and iframe nodes as soon as they are inserted into the DOM, so that they don't perform RPCs. However, this listener was bound in the create(Async)View, and createActionManager helpers only. This rev. moves it to the addMockEnvironment helper which is more global, and basically used by all tests. Moreover, we now listen to the 'DOMNodeInserted' event on the body, instead of on the widget, as it may happen that some content is inserted into the DOM outside the widget itself (e.g. dialogs are appended to the body).
Diffstat (limited to 'addons/web/static/tests/helpers/test_utils.js')
-rw-r--r--addons/web/static/tests/helpers/test_utils.js21
1 files changed, 8 insertions, 13 deletions
diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js
index 6b2c09d2631..f8c7bd6a22c 100644
--- a/addons/web/static/tests/helpers/test_utils.js
+++ b/addons/web/static/tests/helpers/test_utils.js
@@ -101,19 +101,12 @@ var createActionManager = function (params) {
widget.appendTo($target);
widget.$el.addClass('o_web_client');
- // make sure images and iframes do not trigger a GET on the server
- // AAB; this should be done in addMockEnvironment
- $target.on('DOMNodeInserted.removeSRC', function () {
- removeSrcAttribute($(this), widget);
- });
-
var userContext = params.context && params.context.user_context || {};
var actionManager = new ActionManager(widget, userContext);
var originalDestroy = ActionManager.prototype.destroy;
actionManager.destroy = function () {
actionManager.destroy = originalDestroy;
- $target.off('DOMNodeInserted.removeSRC');
widget.destroy();
};
actionManager.appendTo(widget.$el);
@@ -216,11 +209,6 @@ function createAsyncView(params) {
var view = new params.View(viewInfo, viewOptions);
- // make sure images do not trigger a GET on the server
- $target.on('DOMNodeInserted.removeSRC', function () {
- removeSrcAttribute($(this), widget);
- });
-
// reproduce the DOM environment of views
var $web_client = $('<div>').addClass('o_web_client').prependTo($target);
var controlPanel = new ControlPanel(widget);
@@ -235,7 +223,6 @@ function createAsyncView(params) {
// when it will be called the second time (by its parent)
delete view.destroy;
widget.destroy();
- $('#qunit-fixture').off('DOMNodeInserted.removeSRC');
};
// link the view to the control panel
@@ -326,6 +313,11 @@ function addMockEnvironment(widget, params) {
debug: params.debug,
});
+ // make sure images do not trigger a GET on the server
+ $('body').on('DOMNodeInserted.removeSRC', function () {
+ removeSrcAttribute($(this), widget);
+ });
+
// make sure the debounce value for input fields is set to 0
var initialDebounceValue = DebouncedField.prototype.DEBOUNCE;
DebouncedField.prototype.DEBOUNCE = params.fieldDebounce || 0;
@@ -399,6 +391,9 @@ function addMockEnvironment(widget, params) {
_.extend(core._t.database.parameters, initialParameters);
}
+ $('body').off('DOMNodeInserted.removeSRC');
+ $('.blockUI').remove();
+
widgetDestroy.call(this);
};