summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/helpers/test_env.js
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-03-11 09:38:27 +0000
committerJulien Mougenot <jum@odoo.com>2020-03-13 11:39:53 +0000
commit0a129284e4856b6485c48a194fd86c3ab5c736e7 (patch)
treedc0adb0c9528605019af5c915ad2c877f9aa1c57 /addons/web/static/tests/helpers/test_env.js
parent72f1633532a586e1ccee4d2a961d745553b9d8b8 (diff)
[IMP] web,*: Enhance test helpers
1. Test utils helpers adapted to properly instantiate the new Owl control panel 2. New file 'test_utils_control_panel' to create a control panel and use helpers 3. New helper: createComponent (creates a generic component, see jsdoc) 4. Use of the new helpers in the current tests (more in sibling commits) 5. Helper 'addMockEnvironment' is now asynchronous 6. Owl config mode set to 'dev' in test suite (props validation) Part of task 2196029 Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/tests/helpers/test_env.js')
-rw-r--r--addons/web/static/tests/helpers/test_env.js52
1 files changed, 16 insertions, 36 deletions
diff --git a/addons/web/static/tests/helpers/test_env.js b/addons/web/static/tests/helpers/test_env.js
index d934bd3ac84..68659e366c3 100644
--- a/addons/web/static/tests/helpers/test_env.js
+++ b/addons/web/static/tests/helpers/test_env.js
@@ -8,35 +8,6 @@ odoo.define('web.test_env', async function (require) {
const session = require('web.session');
/**
- * Wrap the target object in a Proxy, giving it a generic getter that will
- * throw an error instead of returning `undefined` in case the property has
- * not been set.
- *
- * @param {Object} target
- * @param {string} name
- * @returns {Proxy}
- */
- function _proxify(target, name) {
- for (const prop in target) {
- if (
- target.hasOwnProperty(prop) &&
- typeof target[prop] === 'object' &&
- target[prop] !== null
- ) {
- target[prop] = _proxify(target[prop], `${name}.${prop}`);
- }
- }
- return new Proxy(target, {
- get(object, property) {
- if (typeof property === 'string' && !(property in object)) {
- throw new Error(`Property "${property}" not implemented in "${name}".`);
- }
- return object[property];
- },
- });
- }
-
- /**
* 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.
@@ -46,18 +17,26 @@ odoo.define('web.test_env', async function (require) {
* @returns {Proxy}
*/
function makeTestEnvironment(env = {}, providedRPC = null) {
- const proxiedEnv = _proxify(env, 'env');
const RamStorageService = AbstractStorageService.extend({
storage: new RamStorage(),
});
+ const database = {
+ parameters: {
+ code: "en_US",
+ date_format: '%m/%d/%Y',
+ decimal_point: ".",
+ direction: 'ltr',
+ grouping: [],
+ thousands_sep: ",",
+ time_format: '%H:%M:%S',
+ },
+ };
let testEnv = {};
const defaultEnv = {
- _t: env._t || (s => s),
- _lt: env._lt || (s => s),
+ _t: env._t || Object.assign((s => s), { database }),
+ _lt: env._lt || Object.assign((s => s), { database }),
bus: new Bus(),
- device: Object.assign({
- isMobile: false,
- }, env.device),
+ device: Object.assign({ isMobile: false }, env.device),
isDebug: env.isDebug || (() => false),
qweb: new owl.QWeb({ templates: session.owlTemplates }),
services: Object.assign({
@@ -77,6 +56,7 @@ odoo.define('web.test_env', async function (require) {
},
local_storage: new RamStorageService(),
session_storage: new RamStorageService(),
+ notification: { notify() { } },
}, env.services),
session: Object.assign({
rpc(route, params, options) {
@@ -87,7 +67,7 @@ odoo.define('web.test_env', async function (require) {
},
}, env.session),
};
- testEnv = Object.assign(proxiedEnv, defaultEnv);
+ testEnv = Object.assign(env, defaultEnv);
return testEnv;
}