diff --git a/addons/mail/static/src/models/file_uploader.js b/addons/mail/static/src/models/file_uploader.js index 1c505169f68..644172d380b 100644 --- a/addons/mail/static/src/models/file_uploader.js +++ b/addons/mail/static/src/models/file_uploader.js @@ -46,6 +46,7 @@ registerModel({ if (this.chatterOwner && !this.chatterOwner.attachmentBoxView) { this.chatterOwner.openAttachmentBoxView(); } + this.messaging.messagingBus.trigger('o-file-uploader-upload', { files }); }, /** * Create an HTML element that will serve as file input. diff --git a/addons/mail/static/tests/qunit_suite_tests/components/chatter_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/chatter_tests.js index 67503bbd8a8..3f2450cf8c2 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/chatter_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/chatter_tests.js @@ -231,13 +231,13 @@ QUnit.test('chatter: drop attachments', async function (assert) { const pyEnv = await startServer(); const resPartnerId1 = pyEnv['res.partner'].create({}); - const { openView } = await start(); + const { afterEvent, openView } = await start(); await openView({ res_id: resPartnerId1, res_model: 'res.partner', views: [[false, 'form']], }); - const files = [ + let files = [ await createFile({ content: 'hello, world', contentType: 'text/plain', @@ -260,9 +260,12 @@ QUnit.test('chatter: drop attachments', async function (assert) { "should have no attachment before files are dropped" ); - await afterNextRender(() => - dropFiles(document.querySelector('.o_Chatter_dropZone'), files) - ); + await afterNextRender(() => afterEvent({ + eventName: 'o-file-uploader-upload', + func: () => dropFiles(document.querySelector('.o_Chatter_dropZone'), files), + message: "should wait until files are uploaded", + predicate: ({ files: uploadedFiles }) => uploadedFiles === files, + })); assert.strictEqual( document.querySelectorAll(`.o_AttachmentBox .o_AttachmentCard`).length, 2, @@ -270,18 +273,19 @@ QUnit.test('chatter: drop attachments', async function (assert) { ); await afterNextRender(() => dragenterFiles(document.querySelector('.o_Chatter'))); - await afterNextRender(async () => - dropFiles( - document.querySelector('.o_Chatter_dropZone'), - [ - await createFile({ - content: 'hello, world', - contentType: 'text/plain', - name: 'text3.txt', - }) - ] - ) - ); + files = [ + await createFile({ + content: 'hello, world', + contentType: 'text/plain', + name: 'text3.txt', + }) + ]; + await afterNextRender(() => afterEvent({ + eventName: 'o-file-uploader-upload', + func: () => dropFiles(document.querySelector('.o_Chatter_dropZone'), files), + message: "should wait until files are uploaded", + predicate: ({ files: uploadedFiles }) => uploadedFiles === files, + })); assert.strictEqual( document.querySelectorAll(`.o_AttachmentBox .o_AttachmentCard`).length, 3,