summaryrefslogtreecommitdiff
path: root/addons/web/static/tests
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2019-08-23 13:19:24 +0000
committerVincent Schippefilt <vsc@odoo.com>2019-12-09 11:09:10 +0000
commit29726e8fd000cb09075f9b6b2a6a8d2ddaf4ef58 (patch)
tree91718f6edc90cc069ee5ff3b44c4beb823d31104 /addons/web/static/tests
parent3b4592acfcd67f2b3e467c5e3f82d7b524b96843 (diff)
[ADD] web: add owl 1.0.0-beta1 to odoo
With this commit, we properly introduce the Owl library into our beloved codebase. More information on the Owl library can be found in the project repository: https://github.com/odoo/owl/ Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Julien Mougenot <jum@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/tests')
-rw-r--r--addons/web/static/tests/component_extension_tests.js47
-rw-r--r--addons/web/static/tests/helpers/test_env.js82
-rw-r--r--addons/web/static/tests/main_tests.js14
3 files changed, 143 insertions, 0 deletions
diff --git a/addons/web/static/tests/component_extension_tests.js b/addons/web/static/tests/component_extension_tests.js
new file mode 100644
index 00000000000..c9fd5906a9f
--- /dev/null
+++ b/addons/web/static/tests/component_extension_tests.js
@@ -0,0 +1,47 @@
+odoo.define('web.component_extension_tests', function (require) {
+ "use strict";
+
+ const makeTestEnvironment = require("web.test_env");
+ const testUtils = require("web.test_utils");
+
+ const { Component, tags } = owl;
+ const { xml } = tags;
+
+ QUnit.module("web", function () {
+ QUnit.module("Component Extension");
+
+ QUnit.test("Component destroyed while performing successful RPC", async function (assert) {
+ assert.expect(1);
+
+ class Parent extends Component {}
+ Parent.env = makeTestEnvironment({}, () => Promise.resolve());
+ Parent.template = xml`<div/>`;
+
+ const parent = new Parent();
+
+ parent.rpc({}).then(() => { throw new Error(); });
+ parent.destroy();
+
+ await testUtils.nextTick();
+
+ assert.ok(true, "Promise should still be pending");
+ });
+
+ QUnit.test("Component destroyed while performing failed RPC", async function (assert) {
+ assert.expect(1);
+
+ class Parent extends Component {}
+ Parent.env = makeTestEnvironment({}, () => Promise.reject());
+ Parent.template = xml`<div/>`;
+
+ const parent = new Parent();
+
+ parent.rpc({}).catch(() => { throw new Error(); });
+ parent.destroy();
+
+ await testUtils.nextTick();
+
+ assert.ok(true, "Promise should still be pending");
+ });
+ });
+});
diff --git a/addons/web/static/tests/helpers/test_env.js b/addons/web/static/tests/helpers/test_env.js
new file mode 100644
index 00000000000..65263497221
--- /dev/null
+++ b/addons/web/static/tests/helpers/test_env.js
@@ -0,0 +1,82 @@
+odoo.define('web.test_env', async function (require) {
+ "use strict";
+
+ const { buildQuery } = require("web.rpc");
+ const Bus = require("web.Bus");
+ 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.
+ *
+ * @param {Object} [env={}]
+ * @param {Function} [providedRPC=null]
+ * @returns {Proxy}
+ */
+ function makeTestEnvironment(env = {}, providedRPC = null) {
+ const proxiedEnv = _proxify(env, 'env');
+ const defaultEnv = {
+ _t: env._t || (s => s),
+ bus: new Bus(),
+ qweb: new owl.QWeb({ templates: session.owlTemplates }),
+ services: Object.assign({
+ rpc(params, options) {
+ const query = buildQuery(params);
+ return testEnv.session.rpc(query.route, query.params, options);
+ },
+ }, env.services),
+ session: Object.assign({
+ rpc(route, params, options) {
+ if (providedRPC) {
+ return providedRPC(route, params, options);
+ }
+ throw new Error(`No method to perform RPC`);
+ },
+ }, env.session),
+ device: Object.assign({
+ isMobile: false,
+ }, env.device),
+ };
+ const testEnv = Object.assign(proxiedEnv, defaultEnv);
+ return testEnv;
+ }
+
+ /**
+ * Before each test, we want owl.Component.env to be a fresh test environment.
+ */
+ QUnit.on('OdooBeforeTestHook', function () {
+ owl.Component.env = makeTestEnvironment();
+ });
+
+ return makeTestEnvironment;
+});
diff --git a/addons/web/static/tests/main_tests.js b/addons/web/static/tests/main_tests.js
new file mode 100644
index 00000000000..079a14573d2
--- /dev/null
+++ b/addons/web/static/tests/main_tests.js
@@ -0,0 +1,14 @@
+// define the 'web.web_client' module because some other modules require it
+odoo.define('web.web_client', async function (require) {
+ "use strict";
+
+ const session = require("web.session");
+ const WebClient = require('web.WebClient');
+
+ const webClient = new WebClient();
+
+ await session.is_bound;
+ session.owlTemplates = session.owlTemplates.replace(/t-transition/g, 'transition');
+
+ return webClient;
+});