[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.
This commit is contained in:
Géry Debongnie
2017-05-11 09:53:08 +02:00
parent e1edd62320
commit 33710d540c
3 changed files with 16 additions and 7 deletions
+2 -2
View File
@@ -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();
@@ -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);
+10 -4
View File
@@ -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});
}