diff --git a/addons/mail/static/src/core/common/autoresize_input.js b/addons/mail/static/src/core/common/autoresize_input.js index f65038fae7c..1f12a37aac2 100644 --- a/addons/mail/static/src/core/common/autoresize_input.js +++ b/addons/mail/static/src/core/common/autoresize_input.js @@ -1,7 +1,5 @@ /* @odoo-module */ -import { onExternalClick } from "@mail/utils/common/hooks"; - import { Component, useRef, useState, onWillUpdateProps, onMounted } from "@odoo/owl"; import { useAutoresize } from "@web/core/utils/autoresize"; @@ -34,12 +32,6 @@ export class AutoresizeInput extends Component { this.state.value = nextProps.value; } }); - onExternalClick("input", async (ev, { downTarget }) => { - if (downTarget === this.inputRef.el) { - return; - } - this.onValidate(); - }); useAutoresize(this.inputRef); onMounted(() => { if (this.props.autofocus) { @@ -55,22 +47,12 @@ export class AutoresizeInput extends Component { onKeydownInput(ev) { switch (ev.key) { case "Enter": - this.onValidate(); this.inputRef.el.blur(); break; case "Escape": - this.onDiscard(); + this.state.value = this.props.value; this.inputRef.el.blur(); break; } } - - onValidate() { - this.props.onValidate(this.state.value); - this.state.value = this.props.value; - } - - onDiscard() { - this.state.value = this.props.value; - } } diff --git a/addons/mail/static/src/core/common/autoresize_input.xml b/addons/mail/static/src/core/common/autoresize_input.xml index e056444127f..3c42e7bf9b3 100644 --- a/addons/mail/static/src/core/common/autoresize_input.xml +++ b/addons/mail/static/src/core/common/autoresize_input.xml @@ -10,6 +10,7 @@ t-att-title="state.value" t-model="state.value" t-on-keydown="onKeydownInput" + t-on-blur="() => this.props.onValidate(this.state.value)" t-ref="input" type="text" /> diff --git a/addons/mail/static/tests/discuss_app/discuss_tests.js b/addons/mail/static/tests/discuss_app/discuss_tests.js index 0d140d1fb00..21eb3f09a36 100644 --- a/addons/mail/static/tests/discuss_app/discuss_tests.js +++ b/addons/mail/static/tests/discuss_app/discuss_tests.js @@ -10,6 +10,7 @@ import { start } from "@mail/../tests/helpers/test_utils"; import { editInput, makeDeferred, nextTick, triggerHotkey } from "@web/../tests/helpers/utils"; import { click, contains, createFile, focus, insertText, scroll } from "@web/../tests/utils"; +import { Deferred } from "@web/core/utils/concurrency"; QUnit.module("discuss"); @@ -39,23 +40,42 @@ QUnit.test("can change the thread name of #general [REQUIRE FOCUS]", async (asse channel_type: "channel", create_uid: pyEnv.currentUserId, }); + const def = new Deferred(); const { openDiscuss } = await start({ mockRPC(route, params) { if (route === "/web/dataset/call_kw/discuss.channel/channel_rename") { assert.step(route); + def.resolve(); } }, }); - openDiscuss(channelId); + await openDiscuss(channelId); await contains(".o-mail-Composer-input:focus"); await contains("input.o-mail-Discuss-threadName", { value: "general" }); await insertText("input.o-mail-Discuss-threadName:enabled", "special", { replace: true }); triggerHotkey("Enter"); await contains(".o-mail-DiscussSidebarChannel", { text: "special" }); await contains("input.o-mail-Discuss-threadName", { value: "special" }); + await def; assert.verifySteps(["/web/dataset/call_kw/discuss.channel/channel_rename"]); }); +QUnit.test("can active change thread from messaging menu", async (assert) => { + const pyEnv = await startServer(); + const [, teamId] = pyEnv["discuss.channel"].create([ + { name: "general", channel_type: "channel" }, + { name: "team", channel_type: "channel" }, + ]); + const { openDiscuss } = await start(); + await openDiscuss(teamId); + await contains(".o-mail-DiscussSidebar-item", { text: "general" }); + await contains(".o-mail-DiscussSidebar-item.o-active", { text: "team" }); + await click(".o_main_navbar i[aria-label='Messages']"); + await click(".o-mail-DiscussSidebar-item", { text: "general" }); + await contains(".o-mail-DiscussSidebar-item.o-active", { text: "general" }); + await contains(".o-mail-DiscussSidebar-item", { text: "team" }); +}); + QUnit.test("can change the thread description of #general [REQUIRE FOCUS]", async (assert) => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ @@ -64,14 +84,16 @@ QUnit.test("can change the thread description of #general [REQUIRE FOCUS]", asyn description: "General announcements...", create_uid: pyEnv.currentUserId, }); + const def = new Deferred(); const { openDiscuss } = await start({ mockRPC(route, params) { if (route === "/web/dataset/call_kw/discuss.channel/channel_change_description") { assert.step(route); + def.resolve(); } }, }); - openDiscuss(channelId); + await openDiscuss(channelId); await contains(".o-mail-Composer-input:focus"); await contains("input.o-mail-Discuss-threadDescription", { value: "General announcements...", @@ -83,6 +105,7 @@ QUnit.test("can change the thread description of #general [REQUIRE FOCUS]", asyn await contains("input.o-mail-Discuss-threadDescription", { value: "I want a burger today!", }); + await def; assert.verifySteps(["/web/dataset/call_kw/discuss.channel/channel_change_description"]); });