[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).
This commit is contained in:
Aaron Bohy
2018-02-12 11:13:42 +01:00
parent 107b82f6e1
commit 5c67abd0d3
3 changed files with 21 additions and 19 deletions
@@ -1327,7 +1327,7 @@ QUnit.module('ActionManager', {
QUnit.module('Report actions');
QUnit.test('can execute report actions from db ID', function (assert) {
assert.expect(5);
assert.expect(6);
var actionManager = createActionManager({
actions: this.actions,
@@ -1358,6 +1358,7 @@ QUnit.module('ActionManager', {
assert.verifySteps([
'/web/action/load',
'/report/check_wkhtmltopdf',
'/web/static/src/img/spin.png', // block UI image
'/report/download',
'on_close',
]);
@@ -1366,7 +1367,7 @@ QUnit.module('ActionManager', {
});
QUnit.test('should trigger a notification if wkhtmltopdf is to upgrade', function (assert) {
assert.expect(5);
assert.expect(6);
var actionManager = createActionManager({
actions: this.actions,
@@ -1398,6 +1399,7 @@ QUnit.module('ActionManager', {
'/web/action/load',
'/report/check_wkhtmltopdf',
'notification',
'/web/static/src/img/spin.png', // block UI image
'/report/download',
]);
@@ -1666,7 +1666,7 @@ QUnit.module('basic_fields', {
});
QUnit.test('image fields in subviews are loaded correctly', function (assert) {
assert.expect(5);
assert.expect(6);
this.data.partner.records[0].__last_update = '2017-02-08 10:00:00';
this.data.partner.records[0].document = 'myimage';
@@ -1695,6 +1695,10 @@ QUnit.module('basic_fields', {
assert.step("The view's image should have been fetched");
return $.when('wow');
}
if (route === 'data:image/png;base64,product_image') {
assert.step("The dialog's image should have been fetched");
return $.when();
}
return this._super.apply(this, arguments);
},
});
@@ -1707,9 +1711,10 @@ QUnit.module('basic_fields', {
form.$('tbody td:contains(gold)').click();
assert.strictEqual($('.modal-dialog').length, 1,
'The modal should have opened');
assert.strictEqual($('.modal-dialog').find('.o_field_image > img')[0].src,
'data:image/png;base64,product_image',
'The image of the many2many in its form view should be present');
assert.verifySteps([
"The view's image should have been fetched",
"The dialog's image should have been fetched",
]);
form.destroy();
});
+8 -13
View File
@@ -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);
};