[FIX] mail: traceback while going to close dialog

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) <aku@odoo.com>
This commit is contained in:
Hiral Bhavsar
2020-08-07 14:34:35 +00:00
committed by Alexandre Kühn
parent dda65902c2
commit 8bf5381d13
5 changed files with 110 additions and 5 deletions
@@ -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"
);
});
});
});
});
@@ -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"
);
});
});
});
});
@@ -9,7 +9,7 @@
<h4 class="modal-title">
Edit Subscription of <t t-esc="followerSubtypeList.follower.name"/>
</h4>
<i class="close fa fa-times" aria-label="Close" t-on-click="_onClickCancel"/>
<i class="o_FollowerSubtypeList_closeButton close fa fa-times" aria-label="Close" t-on-click="_onClickCancel"/>
</header>
<main class="modal-body">
<div class="o_FollowerSubtypeList_subtypes">
@@ -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();
}
}
}
@@ -59,7 +59,7 @@ function factory(dependencies) {
* Close subtypes dialog
*/
closeSubtypes() {
this.env.messaging.dialogManager.close(this._subtypesListDialog);
this._subtypesListDialog.delete();
this._subtypesListDialog = undefined;
}