From 33710d540c5584926fcc061ed7e6a04d48f8166e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 10 May 2017 14:53:42 +0200 Subject: [PATCH] [FIX] web: small fixes in test framework We fix in this commit three small issues in the test framework. 1. throw an explicit error when we try to do a fieldviewget in the mock server with a model that does not exist. This will make it easier to figure out what went wrong when copy pasting a test from one file into another, and forgetting to change the model in the createView parameters 2. wrap the result of special methods in the mock server in a deferred, so we can simply return a value when using that functionality. Also, it is more consistent with the rest of the mock server 3. for iframes, we no longer change the src attribute to #test:url. This had the problem of actually loading the page. Instead, we change it into about:blank and we copy the old url into the data-src attribute for reference. --- addons/mrp/static/tests/mrp_tests.js | 4 ++-- addons/web/static/tests/helpers/mock_server.js | 5 ++++- addons/web/static/tests/helpers/test_utils.js | 14 ++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/addons/mrp/static/tests/mrp_tests.js b/addons/mrp/static/tests/mrp_tests.js index 3d94c2d1ca3..ed4dab4f91b 100644 --- a/addons/mrp/static/tests/mrp_tests.js +++ b/addons/mrp/static/tests/mrp_tests.js @@ -77,8 +77,8 @@ QUnit.module('mrp', { "there should not be a any visible 'Upload' button"); assert.notOk(form.$('.o_field_widget iframe.o_pdfview_iframe').hasClass('o_hidden'), "there should be an visible iframe"); - assert.strictEqual(form.$('.o_field_widget iframe.o_pdfview_iframe').attr('src'), - '#test:/web/static/lib/pdfjs/web/viewer.html?file=%2Fweb%2Fimage%3Fmodel%3Dpartner%26field%3Ddocument%26id%3D1', + assert.strictEqual(form.$('.o_field_widget iframe.o_pdfview_iframe').attr('data-src'), + '/web/static/lib/pdfjs/web/viewer.html?file=%2Fweb%2Fimage%3Fmodel%3Dpartner%26field%3Ddocument%26id%3D1', "the src attribute should be correctly set on the iframe"); form.destroy(); diff --git a/addons/web/static/tests/helpers/mock_server.js b/addons/web/static/tests/helpers/mock_server.js index 60024292edd..db6d7449a19 100644 --- a/addons/web/static/tests/helpers/mock_server.js +++ b/addons/web/static/tests/helpers/mock_server.js @@ -62,6 +62,9 @@ var MockServer = Class.extend({ * @returns {Object} an object with 2 keys: arch and fields */ fieldsViewGet: function (arch, model, toolbar) { + if (!(model in this.data)) { + throw new Error('Model ' + model + ' was not defined in mock server data'); + } var fields = $.extend(true, {}, this.data[model].fields); var fvg = this._fieldsViewGet(arch, model, fields); var fields_views = {}; @@ -898,7 +901,7 @@ var MockServer = Class.extend({ } var model = this.data[args.model]; if (model && typeof model[args.method] === 'function') { - return this.data[args.model][args.method](args.args, args.kwargs); + return $.when(this.data[args.model][args.method](args.args, args.kwargs)); } console.error("Unimplemented route", route, args); diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js index 516971f96fe..e460b0555b3 100644 --- a/addons/web/static/tests/helpers/test_utils.js +++ b/addons/web/static/tests/helpers/test_utils.js @@ -143,7 +143,7 @@ function createAsyncView(params) { var view = new params.View(viewInfo, viewOptions); // make sure images do not trigger a GET on the server - $('#qunit-fixture').on('DOMNodeInserted.removeSRC', function () { + $target.on('DOMNodeInserted.removeSRC', function () { removeSrcAttribute($(this), widget); }); @@ -436,9 +436,15 @@ function triggerPositionalMouseEvent(x, y, type){ */ function removeSrcAttribute($el, widget) { $el.find('img, iframe[src]').each(function () { - var src = $(this).attr('src'); - if (src[0] !== '#') { - $(this).attr('src', '#test:' + $(this).attr('src')); + var $el = $(this); + var src = $el.attr('src'); + if (src[0] !== '#' && src !== 'about:blank') { + if ($el[0].nodeName === 'IMG') { + $el.attr('src', '#test:' + src); + } else { + $el.attr('data-src', src); + $el.attr('src', 'about:blank'); + } if (widget) { widget._rpc({route: src}); }