From 45d197c2087e61e702f288f76ccbf99bdd9b235d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Fri, 14 Sep 2018 16:50:45 +0200 Subject: [PATCH] [FIX] web: tests: adapt JS tests from forward-port 9c77066f345360429a0920ca4d17af1f84a7ebea The test was failing because it was using an old approach to mock services in JS tests. Also, it provides ajax service in the list of services, which was not supported in a mocked environment. With this commit, when an ajax service is provided in the test, it will use this service instead of using mocked RPCs from the mocked server. --- addons/web/static/tests/core/widget_tests.js | 4 +++- addons/web/static/tests/helpers/test_utils.js | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/web/static/tests/core/widget_tests.js b/addons/web/static/tests/core/widget_tests.js index 9510079e380..f61d4a18f9b 100644 --- a/addons/web/static/tests/core/widget_tests.js +++ b/addons/web/static/tests/core/widget_tests.js @@ -391,7 +391,9 @@ QUnit.module('core', {}, function () { return def; }, }, - services: [AjaxService], + services: { + ajax: AjaxService + }, }); var widget = new Widget(parent); diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js index 7c47bf5574a..5bf8e3d2e1b 100644 --- a/addons/web/static/tests/helpers/test_utils.js +++ b/addons/web/static/tests/helpers/test_utils.js @@ -494,7 +494,7 @@ function addMockEnvironment(widget, params) { // Dispatch service calls // Note: some services could call other services at init, // Which is why we have to init services after that - var services = {ajax: null}; // mocked ajax service already loaded + var services = {}; intercept(widget, 'call_service', function (ev) { var args, result; if (services[ev.data.service]) { @@ -502,7 +502,7 @@ function addMockEnvironment(widget, params) { args = (ev.data.args || []); result = service[ev.data.method].apply(service, args); } else if (ev.data.service === 'ajax') { - // ajax service is already mocked by the server + // use ajax service that is mocked by the server var route = ev.data.args[0]; args = ev.data.args[1]; result = mockServer.performRpc(route, args); @@ -560,6 +560,9 @@ function addMockEnvironment(widget, params) { // Deploy services var done = false; var servicesToDeploy = _.clone(params.services); + if (!servicesToDeploy.ajax) { + services.ajax = null; // use mocked ajax from mocked server + } while (!done) { var serviceName = _.findKey(servicesToDeploy, function (Service) { return !_.some(Service.prototype.dependencies, function (depName) {