Files
odoo_source/addons/web/static/tests/helpers/test_env.js
T
3fea5b2136 [REF] mail, *: refactor messaging with OWL
This commit is a significant rewriting of client-side discuss, chatter,
chat window, and messaging menu using OWL. The behavior should be broadly
the same, with some slight functional changes here and there.

From a technical standpoint, the code of messaging is mainly organized in 2
main groups of modules:

- models, which are logical entities that depict the client-side state of
  messaging as a whole.
- components, which are in charge of displaying information from models.

This refactoring also introduces new JS guidelines regarding folder structure
(/static) and naming rules for JS modules.

Community PR: https://github.com/odoo/odoo/pull/39023
Enterprise PR: https://github.com/odoo/enterprise/pull/6249

Task-1914207

This PR is a collaborative work by Alexandre, Julien, Sébastien and Xavier,
with the precious help of Lucas to speed it up towards the end.

closes odoo/odoo#39023

Related: odoo/enterprise#6249
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Co-authored-by: Alexandre Kühn <aku@odoo.com>
Co-authored-by: Julien Giannone <jgi@odoo.com>
Co-authored-by: Lucas Perais <lpe@odoo.com>
Co-authored-by: Sébastien Theys <seb@odoo.com>
Co-authored-by: Xavier Dubuc <xdu@odoo.com>
2020-06-15 18:12:21 +00:00

82 lines
3.0 KiB
JavaScript

odoo.define('web.test_env', async function (require) {
"use strict";
const Bus = require('web.Bus');
const { buildQuery } = require('web.rpc');
const session = require('web.session');
/**
* Creates a test environment with the given environment object.
* Any access to a key that has not been explicitly defined in the given environment object
* will result in an error.
*
* @param {Object} [env={}]
* @param {Function} [providedRPC=null]
* @returns {Proxy}
*/
function makeTestEnvironment(env = {}, providedRPC = null) {
const database = {
parameters: {
code: "en_US",
date_format: '%m/%d/%Y',
decimal_point: ".",
direction: 'ltr',
grouping: [],
thousands_sep: ",",
time_format: '%H:%M:%S',
},
};
const defaultEnv = {
_t: env._t || Object.assign((s => s), { database }),
browser: Object.assign({
setTimeout: window.setTimeout.bind(window),
clearTimeout: window.clearTimeout.bind(window),
setInterval: window.setInterval.bind(window),
clearInterval: window.clearInterval.bind(window),
requestAnimationFrame: window.requestAnimationFrame.bind(window),
Date: window.Date,
fetch: (window.fetch || (() => { })).bind(window),
}, env.browser),
bus: env.bus || new Bus(),
device: Object.assign({ isMobile: false }, env.device),
isDebug: env.isDebug || (() => false),
qweb: new owl.QWeb({ templates: session.owlTemplates }),
services: Object.assign({
ajax: {
rpc() {
return env.session.rpc(...arguments); // Compatibility Legacy Widgets
}
},
getCookie() {},
httpRequest(/* route, params = {}, readMethod = 'json' */) {
return Promise.resolve('');
},
rpc(params, options) {
const query = buildQuery(params);
return env.session.rpc(query.route, query.params, options);
},
notification: { notify() { } },
}, env.services),
session: Object.assign({
rpc(route, params, options) {
if (providedRPC) {
return providedRPC(route, params, options);
}
throw new Error(`No method to perform RPC`);
},
url: session.url,
}, env.session),
};
return Object.assign(env, defaultEnv);
}
/**
* Before each test, we want owl.Component.env to be a fresh test environment.
*/
QUnit.on('OdooBeforeTestHook', function () {
owl.Component.env = makeTestEnvironment();
});
return makeTestEnvironment;
});