diff options
| author | Aaron Bohy <aab@odoo.com> | 2018-02-08 14:43:14 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-02-12 11:13:42 +0100 |
| commit | 5c67abd0d306f446af9df59cb6bca2428f17f7a9 (patch) | |
| tree | b31d3c4cabe945286001815f3d29c64473d263be /addons/web/static/tests | |
| parent | 107b82f6e13840c218706d55e434071fb2f2ed28 (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')
| -rw-r--r-- | addons/web/static/tests/chrome/action_manager_tests.js | 6 | ||||
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 13 | ||||
| -rw-r--r-- | addons/web/static/tests/helpers/test_utils.js | 21 |
3 files changed, 21 insertions, 19 deletions
diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index 1ee50daaf65..23e59b2f03d 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -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', ]); diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 8488076b3f0..32a5c3c975e 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -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(); }); 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); }; |
