From 0954f0284c38e4ae4942276630a9fc0ccd3c6b9c Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Tue, 6 Sep 2022 13:20:27 +0000 Subject: [PATCH] [FIX] mail: fix chatter attachment drop test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The chatter drop attachment test fails in an indeterministic manner. This is because we're assuming that the next render will be the one corresponding to the file uploading. In order to be sure this render is really the one we're expecting, the `o-file-uploader-upload` event is added. closes odoo/odoo#99652 Signed-off-by: Sébastien Theys (seb) --- .../mail/static/src/models/file_uploader.js | 1 + .../components/chatter_tests.js | 38 ++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) 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,