summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-06-08 11:50:24 +0000
committerAaron Bohy <aab@odoo.com>2020-07-13 12:55:07 +0000
commitaf85bb5e13b9c97d022a721bd782a37d718e4496 (patch)
tree731c1983542ec3fc07b3b70832659d5ad803252d /addons/mail/static/src/js
parentce3c7d8714c330b8344ffb76245c364045cbf62f (diff)
[IMP] web,*: do not deploy services in tests
*mail,point_of_sale,web_editor,website In the tests, required services are deployed for each test independently. There is no need to have, in additon, all services deployed globally. Worse, it could conflict and lead to unexpected results. This commit ensures services are no longer deployed globally in tests. It turns the module 'web.env' into a declarative module with no side-effect, by moving the service deployment to main.js, which isn't added to the tests page. Task 2287397 closes odoo/odoo#53817 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/mail/static/src/js')
-rw-r--r--addons/mail/static/src/js/main.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/addons/mail/static/src/js/main.js b/addons/mail/static/src/js/main.js
new file mode 100644
index 00000000000..95c8c4153b1
--- /dev/null
+++ b/addons/mail/static/src/js/main.js
@@ -0,0 +1,104 @@
+odoo.define('mail/static/src/js/main.js', function (require) {
+'use strict';
+
+const ModelManager = require('mail/static/src/model/model_manager.js');
+
+const env = require('web.commonEnv');
+
+const { Store } = owl;
+const { EventBus } = owl.core;
+
+/**
+ * Messaging store
+ */
+const store = new Store({
+ env,
+ state: {},
+});
+
+/**
+ * Registry of models.
+ */
+env.models = {};
+/**
+ * Environment keys used in messaging.
+ */
+Object.assign(env, {
+ autofetchPartnerImStatus: true,
+ destroyMessaging() {
+ if (env.modelManager) {
+ env.modelManager.deleteAll();
+ env.messaging = undefined;
+ }
+ },
+ disableAnimation: false,
+ isMessagingInitialized() {
+ if (!this.messaging) {
+ return false;
+ }
+ return this.messaging.isInitialized;
+ },
+ loadingBaseDelayDuration: 400,
+ messaging: undefined,
+ messagingBus: new EventBus(),
+ modelManager: new ModelManager(),
+ store,
+});
+
+/**
+ * Components cannot use web.bus, because they cannot use
+ * EventDispatcherMixin, and webclient cannot easily access env.
+ * Communication between webclient and components by core.bus
+ * (usable by webclient) and messagingBus (usable by components), which
+ * the messaging service acts as mediator since it can easily use both
+ * kinds of buses.
+ */
+env.bus.on(
+ 'hide_home_menu',
+ null,
+ () => env.messagingBus.trigger('hide_home_menu')
+);
+env.bus.on(
+ 'show_home_menu',
+ null,
+ () => env.messagingBus.trigger('show_home_menu')
+);
+env.bus.on(
+ 'will_hide_home_menu',
+ null,
+ () => env.messagingBus.trigger('will_hide_home_menu')
+);
+env.bus.on(
+ 'will_show_home_menu',
+ null,
+ () => env.messagingBus.trigger('will_show_home_menu')
+);
+
+(async function start() {
+ await new Promise(resolve => {
+ /**
+ * Called when all JS resources are loaded. This is useful in order
+ * to do some processing after other JS files have been parsed, for
+ * example new models or patched models that are coming from
+ * other modules, because some of those patches might need to be
+ * applied before messaging initialization.
+ */
+ window.addEventListener('load', resolve);
+ });
+ /**
+ * All JS resources are loaded, but not necessarily processed.
+ * We assume no messaging-related modules return any Promise,
+ * therefore they should be processed *at most* asynchronously at
+ * "Promise time".
+ */
+ await new Promise(resolve => setTimeout(resolve));
+
+ env.modelManager.start(env);
+ /**
+ * Create the messaging singleton record.
+ */
+ env.messaging = env.models['mail.messaging'].create();
+ await env.messaging.start();
+})();
+
+});