diff options
Diffstat (limited to 'addons/mail_bot/static')
9 files changed, 195 insertions, 0 deletions
diff --git a/addons/mail_bot/static/src/bugfix/bugfix.js b/addons/mail_bot/static/src/bugfix/bugfix.js new file mode 100644 index 00000000..bd676eb1 --- /dev/null +++ b/addons/mail_bot/static/src/bugfix/bugfix.js @@ -0,0 +1,10 @@ +/** + * This file allows introducing new JS modules without contaminating other files. + * This is useful when bug fixing requires adding such JS modules in stable + * versions of Odoo. Any module that is defined in this file should be isolated + * in its own file in master. + */ +odoo.define('mail_bot/static/src/bugfix/bugfix.js', function (require) { +'use strict'; + +}); diff --git a/addons/mail_bot/static/src/bugfix/bugfix.scss b/addons/mail_bot/static/src/bugfix/bugfix.scss new file mode 100644 index 00000000..c4272e52 --- /dev/null +++ b/addons/mail_bot/static/src/bugfix/bugfix.scss @@ -0,0 +1,6 @@ +/** +* This file allows introducing new styles without contaminating other files. +* This is useful when bug fixing requires adding new components for instance in +* stable versions of Odoo. Any style that is defined in this file should be isolated +* in its own file in master. +*/ diff --git a/addons/mail_bot/static/src/bugfix/bugfix.xml b/addons/mail_bot/static/src/bugfix/bugfix.xml new file mode 100644 index 00000000..c17906f7 --- /dev/null +++ b/addons/mail_bot/static/src/bugfix/bugfix.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<templates xml:space="preserve"> + +<!-- + This file allows introducing new static templates without contaminating other files. + This is useful when bug fixing requires adding new components for instance in stable + versions of Odoo. Any template that is defined in this file should be isolated + in its own file in master. +--> + +</templates> diff --git a/addons/mail_bot/static/src/bugfix/bugfix_tests.js b/addons/mail_bot/static/src/bugfix/bugfix_tests.js new file mode 100644 index 00000000..3aa5456b --- /dev/null +++ b/addons/mail_bot/static/src/bugfix/bugfix_tests.js @@ -0,0 +1,18 @@ +odoo.define('mail_bot/static/src/bugfix/bugfix_tests.js', function (require) { +'use strict'; + +/** + * This file allows introducing new QUnit test modules without contaminating + * other test files. This is useful when bug fixing requires adding new + * components for instance in stable versions of Odoo. Any test that is defined + * in this file should be isolated in its own file in master. + */ +QUnit.module('mail_bot', {}, function () { +QUnit.module('bugfix', {}, function () { +QUnit.module('bugfix_tests.js', { + +}); +}); +}); + +}); diff --git a/addons/mail_bot/static/src/models/messaging/messaging.js b/addons/mail_bot/static/src/models/messaging/messaging.js new file mode 100644 index 00000000..58923e8e --- /dev/null +++ b/addons/mail_bot/static/src/models/messaging/messaging.js @@ -0,0 +1,13 @@ +odoo.define('mail_bot/static/src/models/messaging/messaging.js', function (require) { +'use strict'; + +const { registerInstancePatchModel } = require('mail/static/src/model/model_core.js'); + +registerInstancePatchModel('mail.messaging', 'mail_bot/static/src/models/messaging/messaging.js', { + //---------------------------------------------------------------------- + // Public + //---------------------------------------------------------------------- + +}); + +}); diff --git a/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer.js b/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer.js new file mode 100644 index 00000000..9b06fbba --- /dev/null +++ b/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer.js @@ -0,0 +1,37 @@ +odoo.define('mail_bot/static/src/models/messaging_initializer/messaging_initializer.js', function (require) { +'use strict'; + +const { registerInstancePatchModel } = require('mail/static/src/model/model_core.js'); + +registerInstancePatchModel('mail.messaging_initializer', 'mail_bot/static/src/models/messaging_initializer/messaging_initializer.js', { + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + */ + async _initializeOdooBot() { + const data = await this.async(() => this.env.services.rpc({ + model: 'mail.channel', + method: 'init_odoobot', + })); + if (!data) { + return; + } + this.env.session.odoobot_initialized = true; + }, + + /** + * @override + */ + async start() { + await this.async(() => this._super()); + + if ('odoobot_initialized' in this.env.session && !this.env.session.odoobot_initialized) { + this._initializeOdooBot(); + } + }, +}); + +}); diff --git a/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js b/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js new file mode 100644 index 00000000..bfb97067 --- /dev/null +++ b/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js @@ -0,0 +1,56 @@ +odoo.define('mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js', function (require) { +"use strict"; + +const { afterEach, beforeEach, start } = require('mail/static/src/utils/test_utils.js'); + +QUnit.module('mail_bot', {}, function () { +QUnit.module('models', {}, function () { +QUnit.module('messaging_initializer', {}, function () { +QUnit.module('messaging_initializer_tests.js', { + beforeEach() { + beforeEach(this); + + this.start = async params => { + const { env, widget } = await start(Object.assign({}, params, { + data: this.data, + })); + this.env = env; + this.widget = widget; + }; + }, + afterEach() { + afterEach(this); + }, +}); + + +QUnit.test('OdooBot initialized at init', async function (assert) { + // TODO this test should be completed in combination with + // implementing _mockMailChannelInitOdooBot task-2300480 + assert.expect(2); + + await this.start({ + env: { + session: { + odoobot_initialized: false, + }, + }, + async mockRPC(route, args) { + if (args.method === 'init_odoobot') { + assert.step('init_odoobot'); + } + return this._super(...arguments); + }, + }); + + assert.verifySteps( + ['init_odoobot'], + "should have initialized OdooBot at init" + ); +}); + +}); +}); +}); + +}); diff --git a/addons/mail_bot/static/src/scss/odoobot_style.scss b/addons/mail_bot/static/src/scss/odoobot_style.scss new file mode 100644 index 00000000..aa5e187b --- /dev/null +++ b/addons/mail_bot/static/src/scss/odoobot_style.scss @@ -0,0 +1,8 @@ +.o_odoobot_command { + background-color: lightgray; + border-radius: 4px; + padding: 2px; + padding-left: 10px; + padding-right: 10px; + font-weight: bold; +} diff --git a/addons/mail_bot/static/tests/helpers/mock_server.js b/addons/mail_bot/static/tests/helpers/mock_server.js new file mode 100644 index 00000000..63de6c99 --- /dev/null +++ b/addons/mail_bot/static/tests/helpers/mock_server.js @@ -0,0 +1,36 @@ +odoo.define('mail_bot/static/tests/helpers/mock_server.js', function (require) { +"use strict"; + +const MockServer = require('web.MockServer'); + +MockServer.include({ + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + */ + async _performRpc(route, args) { + if (args.model === 'mail.channel' && args.method === 'init_odoobot') { + return this._mockMailChannelInitOdooBot(); + } + return this._super(...arguments); + }, + + //-------------------------------------------------------------------------- + // Private Mocked Methods + //-------------------------------------------------------------------------- + + /** + * Simulates `init_odoobot` on `mail.channel`. + * + * @private + */ + _mockMailChannelInitOdooBot() { + // TODO implement this mock task-2300480 + // and improve test "OdooBot initialized after 2 minutes" + }, +}); + +}); |
