diff --git a/addons/mail/static/src/core/web/chatter.js b/addons/mail/static/src/core/web/chatter.js index 0294e22744f..b02cfc86457 100644 --- a/addons/mail/static/src/core/web/chatter.js +++ b/addons/mail/static/src/core/web/chatter.js @@ -165,6 +165,14 @@ export class Chatter extends Component { } } }); + useEffect( + () => { + if (this.attachments.length === 0) { + this.state.isAttachmentBoxOpened = false; + } + }, + () => [this.attachments] + ); useEffect( (opened) => { if (opened) { diff --git a/addons/mail/static/tests/web/attachment_box_tests.js b/addons/mail/static/tests/web/attachment_box_tests.js index 28489b58e19..ad41557278d 100644 --- a/addons/mail/static/tests/web/attachment_box_tests.js +++ b/addons/mail/static/tests/web/attachment_box_tests.js @@ -5,30 +5,6 @@ import { click, contains, scroll, start, startServer } from "@mail/../tests/help QUnit.module("attachment box"); -QUnit.test("base empty rendering", async () => { - const pyEnv = await startServer(); - const partnerId = pyEnv["res.partner"].create({}); - const views = { - "res.partner,false,form": ` -
- -
- -
-
- `, - }; - const { openView } = await start({ serverData: { views } }); - openView({ - res_id: partnerId, - res_model: "res.partner", - views: [[false, "form"]], - }); - await contains(".o-mail-AttachmentBox"); - await contains("button", { text: "Attach files" }); - await contains(".o-mail-Chatter .o-mail-AttachmentImage", { count: 0 }); -}); - QUnit.test("base non-empty rendering", async () => { const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({}); @@ -200,3 +176,36 @@ QUnit.test("attachment box should order attachments from newest to oldest", asyn await contains(".o-mail-AttachmentCard:eq(1) div", { text: "B.txt" }); await contains(".o-mail-AttachmentCard:eq(2) div", { text: "A.txt" }); }); + +QUnit.test("attachment box auto-closed on switch to record wih no attachments", async (assert) => { + const pyEnv = await startServer(); + const [partnerId_1, partnerId_2] = pyEnv["res.partner"].create([ + { display_name: "first partner" }, + { display_name: "second partner" }, + ]); + pyEnv["ir.attachment"].create([ + { + mimetype: "text/plain", + name: "Blah.txt", + res_id: partnerId_1, + res_model: "res.partner", + }, + ]); + const views = { + "res.partner,false,form": ` +
+ +
+ +
+
+ `, + }; + const { openFormView } = await start({ serverData: { views } }); + await openFormView("res.partner", partnerId_1, { + props: { resIds: [partnerId_1, partnerId_2] }, + }); + await contains(".o-mail-AttachmentBox"); + await click(".o_pager_next"); + await contains(".o-mail-AttachmentBox", { count: 0 }); +});