From 8bf5381d136f168d9bd5a562960afef7c7c35175 Mon Sep 17 00:00:00 2001 From: Hiral Bhavsar Date: Fri, 7 Aug 2020 11:44:25 +0000 Subject: [PATCH] [FIX] mail: traceback while going to close dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit: Traceback appearing while going to close subtypes dialog from followers or closing the attachment viewer dialog. This is happening because the dialog manager doesn't have a close function after https://github.com/odoo/odoo/commit/9216bdcb6f0bbb20900a33bbf7283e6e4fda1b2c After this commit: Able to close the dialog without any traceback as fix it by call the delete function. LINKS Task-2314898 closes odoo/odoo#55636 X-original-commit: f2186ceefe23cd1a45adc72089c8e828e9b75cc8 Signed-off-by: Alexandre Kühn (aku) --- .../components/attachment/attachment_tests.js | 40 ++++++++++- .../src/components/follower/follower_tests.js | 69 ++++++++++++++++++- .../follower_subtype_list.xml | 2 +- .../attachment_viewer/attachment_viewer.js | 2 +- .../static/src/models/follower/follower.js | 2 +- 5 files changed, 110 insertions(+), 5 deletions(-) diff --git a/addons/mail/static/src/components/attachment/attachment_tests.js b/addons/mail/static/src/components/attachment/attachment_tests.js index 4757e4a4e11..ec78a18d705 100644 --- a/addons/mail/static/src/components/attachment/attachment_tests.js +++ b/addons/mail/static/src/components/attachment/attachment_tests.js @@ -563,7 +563,6 @@ QUnit.test('view attachment', async function (assert) { isDownloadable: false, isEditable: false, }); - assert.containsOnce( document.body, '.o_Attachment_image', @@ -582,6 +581,45 @@ QUnit.test('view attachment', async function (assert) { ); }); +QUnit.test('close attachment viewer', async function (assert) { + assert.expect(3); + + await this.start({ hasDialog: true }); + const attachment = this.env.models['mail.attachment'].create({ + filename: "test.png", + id: 750, + mimetype: 'image/png', + name: "test.png", + }); + + await this.createAttachmentComponent(attachment, { + detailsMode: 'hover', + isDownloadable: false, + isEditable: false, + }); + assert.containsOnce( + document.body, + '.o_Attachment_image', + "attachment should have an image part" + ); + + await afterNextRender(() => document.querySelector('.o_Attachment_image').click()); + assert.containsOnce( + document.body, + '.o_AttachmentViewer', + "an attachment viewer should have been opened once attachment image is clicked", + ); + + await afterNextRender(() => + document.querySelector('.o_AttachmentViewer_headerItemButtonClose').click() + ); + assert.containsNone( + document.body, + '.o_Dialog', + "attachment viewer should be closed after clicking on close button" + ); +}); + }); }); }); diff --git a/addons/mail/static/src/components/follower/follower_tests.js b/addons/mail/static/src/components/follower/follower_tests.js index 87e09dda2df..b4dc89981c6 100644 --- a/addons/mail/static/src/components/follower/follower_tests.js +++ b/addons/mail/static/src/components/follower/follower_tests.js @@ -339,7 +339,6 @@ QUnit.test('click on edit follower', async function (assert) { ['fetch_subtypes'], "clicking on edit follower should fetch subtypes" ); - assert.containsOnce( document.body, '.o_FollowerSubtypeList', @@ -347,6 +346,74 @@ QUnit.test('click on edit follower', async function (assert) { ); }); +QUnit.test('edit follower and close subtype dialog', async function (assert) { + assert.expect(6); + + await this.start({ + hasDialog: true, + async mockRPC(route, args) { + if (route.includes('/mail/read_subscription_data')) { + assert.step('fetch_subtypes'); + return [{ + default: true, + followed: true, + internal: false, + id: 1, + name: "Dummy test", + res_model: 'res.partner' + }]; + } + return this._super(...arguments); + }, + }); + const thread = this.env.models['mail.thread'].create({ + id: 100, + model: 'res.partner', + }); + const follower = await this.env.models['mail.follower'].create({ + followedThread: [['link', thread]], + id: 2, + isActive: true, + isEditable: true, + partner: [['insert', { + email: "bla@bla.bla", + id: this.env.session.partner_id, + name: "François Perusse", + }]], + }); + await this.createFollowerComponent(follower); + assert.containsOnce( + document.body, + '.o_Follower', + "should have follower component" + ); + assert.containsOnce( + document.body, + '.o_Follower_editButton', + "should display an edit button" + ); + + await afterNextRender(() => document.querySelector('.o_Follower_editButton').click()); + assert.verifySteps( + ['fetch_subtypes'], + "clicking on edit follower should fetch subtypes" + ); + assert.containsOnce( + document.body, + '.o_FollowerSubtypeList', + "dialog allowing to edit follower subtypes should have been created" + ); + + await afterNextRender( + () => document.querySelector('.o_FollowerSubtypeList_closeButton').click() + ); + assert.containsNone( + document.body, + '.o_DialogManager_dialog', + "follower subtype dialog should be closed after clicking on close button" + ); +}); + }); }); }); diff --git a/addons/mail/static/src/components/follower_subtype_list/follower_subtype_list.xml b/addons/mail/static/src/components/follower_subtype_list/follower_subtype_list.xml index 9ab73328a9e..ad477d9d3f0 100644 --- a/addons/mail/static/src/components/follower_subtype_list/follower_subtype_list.xml +++ b/addons/mail/static/src/components/follower_subtype_list/follower_subtype_list.xml @@ -9,7 +9,7 @@ - +
diff --git a/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js b/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js index ae5c20ad592..8a96946c87d 100644 --- a/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js +++ b/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js @@ -18,7 +18,7 @@ function factory(dependencies) { close() { const dialog = this.env.models['mail.dialog'].find(dialog => dialog.record === this); if (dialog) { - this.env.messaging.dialogManager.close(dialog); + dialog.delete(); } } } diff --git a/addons/mail/static/src/models/follower/follower.js b/addons/mail/static/src/models/follower/follower.js index 4c44b788d4d..e5be843d7ce 100644 --- a/addons/mail/static/src/models/follower/follower.js +++ b/addons/mail/static/src/models/follower/follower.js @@ -59,7 +59,7 @@ function factory(dependencies) { * Close subtypes dialog */ closeSubtypes() { - this.env.messaging.dialogManager.close(this._subtypesListDialog); + this._subtypesListDialog.delete(); this._subtypesListDialog = undefined; }