diff options
| author | Xavier Dubuc <xdu@odoo.com> | 2020-07-08 13:52:53 +0000 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2020-07-15 16:18:53 +0000 |
| commit | c767df5e978f218cd0c1c7dc9219d3655e320fab (patch) | |
| tree | e2139569a76bbc8b10ccf2ec47a887c2f50c6791 /addons/mail | |
| parent | 04a757d59615c622ba808e4d5b0efc0ecf3190d0 (diff) | |
[FIX] mail: set full composer subject and recipients
task-2291887
task-2291893
task-2291898
closes odoo/odoo#54531
X-original-commit: 26170ad9ab09d75de2e0af98fb7daedc2ed57e50
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail')
| -rw-r--r-- | addons/mail/static/src/components/composer/composer.js | 30 | ||||
| -rw-r--r-- | addons/mail/static/src/models/composer/composer.js | 38 | ||||
| -rw-r--r-- | addons/mail/static/tests/tours/mail_full_composer_test_tour.js | 62 | ||||
| -rw-r--r-- | addons/mail/tests/__init__.py | 1 | ||||
| -rw-r--r-- | addons/mail/tests/test_mail_full_composer.py | 25 | ||||
| -rw-r--r-- | addons/mail/views/assets.xml | 3 |
6 files changed, 131 insertions, 28 deletions
diff --git a/addons/mail/static/src/components/composer/composer.js b/addons/mail/static/src/components/composer/composer.js index cd47385e019..b81a4664708 100644 --- a/addons/mail/static/src/components/composer/composer.js +++ b/addons/mail/static/src/components/composer/composer.js @@ -15,7 +15,6 @@ const { isEventHandled, markEventHandled, } = require('mail/static/src/utils/utils.js'); -const mailUtils = require('mail.utils'); const { Component } = owl; const { useRef } = owl.hooks; @@ -227,33 +226,8 @@ class Composer extends Component { * * @private */ - async _onClickFullComposer() { - const attachmentIds = this.composer.attachments.map(attachment => attachment.res_id); - - const context = { - // default_parent_id: this.id, - default_body: mailUtils.escapeAndCompactTextContent(this.composer.textInputContent), - default_attachment_ids: attachmentIds, - // default_partner_ids: partnerIds, - default_is_log: this.composer.isLog, - mail_post_autofollow: true, - }; - - // if (this.context.default_model && this.context.default_res_id) { - // context.default_model = this.context.default_model; - // context.default_res_id = this.context.default_res_id; - // } - - const action = { - type: 'ir.actions.act_window', - res_model: 'mail.compose.message', - view_mode: 'form', - views: [[false, 'form']], - target: 'new', - context: context, - }; - await this.env.bus.trigger('do-action', { action }); - this.trigger('o-full-composer-opened'); + _onClickFullComposer() { + this.composer.openFullComposer(); } /** diff --git a/addons/mail/static/src/models/composer/composer.js b/addons/mail/static/src/models/composer/composer.js index b4469043634..78e1ad4e505 100644 --- a/addons/mail/static/src/models/composer/composer.js +++ b/addons/mail/static/src/models/composer/composer.js @@ -4,6 +4,7 @@ odoo.define('mail/static/src/models/composer/composer.js', function (require) { const emojis = require('mail.emojis'); const { registerNewModel } = require('mail/static/src/model/model_core.js'); const { attr, many2many, many2one, one2one } = require('mail/static/src/model/model_field.js'); +const mailUtils = require('mail.utils'); const { addLink, @@ -82,6 +83,43 @@ function factory(dependencies) { } /** + * Open the full composer modal. + */ + async openFullComposer() { + const attachmentIds = this.attachments.map(attachment => attachment.res_id); + + const context = { + default_attachment_ids: attachmentIds, + default_body: mailUtils.escapeAndCompactTextContent(this.textInputContent), + default_is_log: this.isLog, + default_model: this.thread.model, + /* FIXME would need to use suggested_partners here task-2280157 */ + // default_partner_ids: partnerIds, + default_res_id: this.thread.id, + mail_post_autofollow: true, + }; + + const action = { + type: 'ir.actions.act_window', + res_model: 'mail.compose.message', + view_mode: 'form', + views: [[false, 'form']], + target: 'new', + context: context, + }; + const options = { + on_close: () => { + if (!this.constructor.get(this)) { + return; + } + this._reset(); + this.thread.loadNewMessages(); + }, + }; + await this.env.bus.trigger('do-action', { action, options }); + } + + /** * Post a message in provided composer's thread based on current composer fields values. */ async postMessage() { diff --git a/addons/mail/static/tests/tours/mail_full_composer_test_tour.js b/addons/mail/static/tests/tours/mail_full_composer_test_tour.js new file mode 100644 index 00000000000..c188fde1d96 --- /dev/null +++ b/addons/mail/static/tests/tours/mail_full_composer_test_tour.js @@ -0,0 +1,62 @@ +odoo.define('mail/static/tests/tours/mail_full_composer_test_tour.js', function (require) { +"use strict"; + +const tour = require('web_tour.tour'); + +/** + * This tour depends on data created by python test in charge of launching it. + * It is not intended to work when launched from interface. It is needed to test + * an action (action manager) which is not possible to test with QUnit. + * @see mail/tests/test_mail_full_composer.py + */ +tour.register('mail/static/tests/tours/mail_full_composer_test_tour.js', { + test: true, +}, [{ + content: "Click on Send Message", + trigger: '.o_ChatterTopbar_buttonSendMessage', +}, { + content: "Write something in composer", + trigger: '.o_ComposerTextInput_textarea', + run: 'text blahblah', +}, { + content: "Open full composer", + trigger: '.o_Composer_buttonFullComposer', +}, { + content: "Check subject is autofilled", + trigger: 'input[name="subject"]', + run: () => { + const subjectValue = document.querySelector('input[name="subject"]').value; + if (subjectValue !== "Re: Test User") { + console.error( + `Full composer should have "Re: Test User" in subject input (actual: ${subjectValue})` + ); + } + }, +}, { + content: "Check composer content is kept", + trigger: '.oe_form_field[name="body"]', + run: () => { + const bodyContent = document.querySelector('.oe_form_field[name="body"] textarea').textContent; + if (!bodyContent.includes("blahblah")) { + console.error( + `Full composer should contain text from small composer ("blahblah") in body input (actual: ${bodyContent})` + ); + } + }, +}, { + content: "Open templates", + trigger: '.o_field_widget[name="template_id"] input', +}, { + content: "Check a template is listed", + in_modal: false, + trigger: '.ui-autocomplete .ui-menu-item a:contains("Test template")', + run: () => {}, +}, { + content: "Send message", + trigger: '.o_mail_send', +}, { + content: "Check message is shown", + trigger: '.o_Message:contains("blahblah")', +}]); + +}); diff --git a/addons/mail/tests/__init__.py b/addons/mail/tests/__init__.py index 15ce69a9bd7..4a5e1461878 100644 --- a/addons/mail/tests/__init__.py +++ b/addons/mail/tests/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from . import common +from . import test_mail_full_composer from . import test_res_partner from . import test_update_notification diff --git a/addons/mail/tests/test_mail_full_composer.py b/addons/mail/tests/test_mail_full_composer.py new file mode 100644 index 00000000000..35dea3ae581 --- /dev/null +++ b/addons/mail/tests/test_mail_full_composer.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests.common import tagged, HttpCase + + +@tagged('-at_install', 'post_install') +class TestMailFullComposer(HttpCase): + + def test_full_composer_tour(self): + self.env['mail.template'].create({ + 'name': 'Test template', + 'partner_to': '${object.id}', + 'lang': '${object.lang}', + 'auto_delete': True, + 'model_id': self.ref('base.model_res_partner'), + }) + testuser = self.env['res.users'].create({ + 'email': 'testuser@testuser.com', + 'groups_id': [(6, 0, [self.ref('base.group_user'), self.ref('base.group_partner_manager')])], + 'name': 'Test User', + 'login': 'testuser', + 'password': 'testuser', + }) + self.start_tour("/web#id=%d&model=res.partner" % testuser.partner_id, 'mail/static/tests/tours/mail_full_composer_test_tour.js', login='testuser') diff --git a/addons/mail/views/assets.xml b/addons/mail/views/assets.xml index 806f183d23c..7a6447651be 100644 --- a/addons/mail/views/assets.xml +++ b/addons/mail/views/assets.xml @@ -219,6 +219,9 @@ </template> <template id="assets_tests" name="Mail Assets Tests" inherit_id="web.assets_tests"> + <xpath expr="." position="inside"> + <script type="text/javascript" src="/mail/static/tests/tours/mail_full_composer_test_tour.js"/> + </xpath> </template> <template id="tests_assets" name="mail_tests_assets" inherit_id="web.tests_assets"> |
