summaryrefslogtreecommitdiff
path: root/addons/web/static/test/testing.js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-03-05 10:05:56 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit905e01921f3c3ef43ace6fc537d1d8c0d280002c (patch)
tree265c43ab21c5401a5d9f0f3d64d86f1ac417451c /addons/web/static/test/testing.js
parent54d4c73af4ad05c7640d28c1892247c9538b8017 (diff)
[REF] web, *: redesign all JS views
This commit introduce a full redesign of all JS views. We started basically from scratch. The goal was to unify all the various views under a common framework, to make them testable, to make then usable in different conditions (in studio, or in the frontend), and to make our lives easier. Some important points are: - we introduced new coding guidelines (camelCase, 80 chars width, ...) - we have a brand new testing framework (still QUnit based) - kanban view moved to the web addon - calendar view (formerly web_calender) moved to web as well - the tree view was removed - all new code should be documented We hope that this code is the start of a new era for the Odoo web client, we want to have a high quality codebase, well documented, well tested, well designed. Work done by the framework team: mostly aab, ged, chm, dmo, qsm
Diffstat (limited to 'addons/web/static/test/testing.js')
-rw-r--r--addons/web/static/test/testing.js158
1 files changed, 0 insertions, 158 deletions
diff --git a/addons/web/static/test/testing.js b/addons/web/static/test/testing.js
deleted file mode 100644
index 927ca512060..00000000000
--- a/addons/web/static/test/testing.js
+++ /dev/null
@@ -1,158 +0,0 @@
-
-odoo.testing = {};
-
-odoo.testing.start_services = function () {
- var factories = odoo.__DEBUG__.factories;
- delete factories['mail.chat_manager'];
- var jobs = _.map(factories, function (factory, name) {
- return {
- name: name,
- factory: factory,
- deps: factory.deps,
- };
- });
- var services = Object.create({});
- return odoo.process_jobs(jobs, services);
-};
-
-odoo.testing.MockRPC = function (session) {
- this.clear();
-};
-
-odoo.testing.MockRPC.prototype.clear = function () {
- this.responses = {};
-};
-
-odoo.testing.MockRPC.prototype.interceptRPC = function (session) {
- session.rpc = this.rpc.bind(this);
-};
-
-odoo.testing.MockRPC.prototype.add = function (spec, handler, no_override) {
- if (no_override && (spec in this.responses)) {
- return;
- }
- this.responses[spec] = handler;
-};
-
-odoo.testing.MockRPC.prototype.rpc = function (url, rparams, options) {
- if (_.isString(url)) {
- url = {url: url};
- }
- var fn, params;
- var needle = rparams.model + ':' + rparams.method;
- if (url.url.substr(0, 20) === '/web/dataset/call_kw' && needle in this.responses) {
- fn = this.responses[needle];
- params = [
- rparams.args || [],
- rparams.kwargs || {}
- ];
- } else {
- fn = this.responses[url.url];
- params = [{params: rparams}];
- }
-
- if (!fn) {
- return $.Deferred().reject({}, 'failed',
- _.str.sprintf("Url %s not found in mock responses, with arguments %s",
- url.url, JSON.stringify(rparams))
- ).promise();
- }
- try {
- return $.when(fn.apply(null, params)).then(function (result) {
- // Wrap for RPC layer unwrapper thingy
- return result;
- });
- } catch (e) {
- // not sure why this looks like that
- return $.Deferred().reject({}, 'failed', String(e));
- }
-};
-
-odoo.testing.noop = function () {};
-
-odoo.define_section = function (name, section_deps) {
- var section_body, options, mock;
-
- if (typeof arguments[2] === 'function') {
- options = {};
- section_body = arguments[2];
- } else {
- options = arguments[2];
- section_body = arguments[3];
- }
-
- mock = new odoo.testing.MockRPC();
-
- function dummyfunc () {};
-
- function beforeEach(assert) {
- var services = odoo.testing.start_services();
- this.deps = services;
- this.getServiceDeps = function getServiceDeps(dep_names) {
- return _.map(dep_names, function (name) { return services[name]; })
- }
- services['web.core'].qweb.add_template(odoo.testing.templates);
- this.mock = mock;
- this.mock.interceptRPC(services['web.session']);
- this.assert = assert;
- (options.beforeEach || dummyfunc).apply(this, [assert].concat(this.getServiceDeps(section_deps)));
- }
- function afterEach(assert) {
- (options.afterEach || dummyfunc).apply(this, [assert].concat(this.getServiceDeps(section_deps)));
- this.mock.clear();
- }
-
- QUnit.module(name, {
- before: options.before,
- beforeEach: beforeEach,
- afterEach: afterEach,
- after: options.after
- });
-
- function test () {
- var name = arguments[0],
- dep_names = arguments[1] instanceof Array ? arguments[1] : [],
- body = arguments[arguments.length - 1];
-
- QUnit.test(name, function (assert) {
- var deps = this.getServiceDeps(section_deps.concat(dep_names));
- return body.apply(this, [assert].concat(deps));
- });
- }
-
- section_body(test, mock);
-};
-
-
-QUnit.done(function(result) {
- if (result.failed === 0) {
- console.log('ok');
- } else {
- console.log('error');
- }
-});
-
-QUnit.log(function(result) {
- if (!result.result) {
- console.log(result.name, 'in section', result.module, 'failed:', result.message);
- }
-});
-
-(new QWeb2.Engine()).load_xml("/web/webclient/qweb", function (err, xDoc) {
- odoo.testing.templates = xDoc;
- QUnit.start();
-});
-
-QUnit.config.autostart = false;
-
-
-localStorage.clear();
-QUnit.config.testTimeout = 1 * 60 * 1000;
-QUnit.moduleDone(function(result) {
- if (!result.failed) {
- console.log(result.name, "passed", result.total, "tests.");
- } else {
- console.log(result.name, "failed:", result.failed, "tests out of", result.total, ".");
- }
-
-});