[FIX] mass_mailing: HtmlField: do not crash if destroyed

Go to Email Marketing, open a record with status "draft". Directly
when the record opens, and before the html field is loaded, click
on another menu or on the breadcrumb to leave the view. Before this
commit, it crashed because the HtmlField tried to perform an RPC
after being destroyed.

opw~3297859

closes odoo/odoo#123381

X-original-commit: 3e8d2c7006b16738cdab7442a7135ae7f1c60da9
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Aaron Bohy
2023-06-02 12:04:18 +02:00
parent 854153a68c
commit 48082dcfa7
2 changed files with 46 additions and 3 deletions
@@ -19,6 +19,7 @@ const {
onWillStart,
useSubEnv,
onWillUpdateProps,
status,
} = owl;
export class MassMailingHtmlField extends HtmlField {
@@ -148,6 +149,10 @@ export class MassMailingHtmlField extends HtmlField {
const assets = await getBundle("mass_mailing.assets_wysiwyg");
await loadBundle(assets);
if (status(this) === "destroyed") {
return;
}
await this._resetIframe();
}
@@ -3,8 +3,15 @@
import * as ajax from "web.ajax";
import weTestUtils from "web_editor.test_utils";
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
import * as testUtils from "@web/../tests/helpers/utils";
import {
editInput,
getFixture,
makeDeferred,
nextTick,
patchWithCleanup,
} from "@web/../tests/helpers/utils";
import * as legacyTestUtils from "web.test_utils";
import { assets } from "@web/core/assets";
let serverData;
let fixture;
@@ -12,7 +19,7 @@ let fixture;
QUnit.module('mass_mailing', {}, function () {
QUnit.module('field html', (hooks) => {
hooks.beforeEach(() => {
fixture = testUtils.getFixture();
fixture = getFixture();
const models = weTestUtils.wysiwygData({
'mailing.mailing': {
fields: {
@@ -91,12 +98,43 @@ QUnit.module('field html', (hooks) => {
' />'+
'</form>',
});
await testUtils.nextTick();
await nextTick();
let fieldReadonly = fixture.querySelector('.o_field_widget[name="body_html"]');
let fieldEdit = fixture.querySelector('.o_field_widget[name="body_arch"]');
assert.strictEqual($(fieldReadonly).css('display'), 'none', "should hide the readonly mode");
assert.strictEqual($(fieldEdit).css('display'), 'block', "should display the edit mode");
});
QUnit.test('component destroyed while loading', async function (assert) {
const def = makeDeferred();
patchWithCleanup(assets, {
loadBundle() {
assert.step("loadBundle");
return def;
}
})
await makeView({
type: "form",
resModel: 'mailing.mailing',
resId: 1,
serverData,
arch: `
<form>
<field name="display_name"/>
<field name="body_arch" widget="mass_mailing_html" attrs="{'invisible': [['display_name', '=', 'hide']]}"/>
</form>`,
});
assert.containsOnce(fixture, ".o_field_widget[name=body_arch]");
await editInput(fixture, ".o_field_widget[name=display_name] input", "hide");
assert.containsNone(fixture, ".o_field_widget[name=body_arch]");
def.resolve();
await nextTick();
assert.containsNone(fixture, ".o_field_widget[name=body_arch]");
assert.verifySteps(["loadBundle"]);
});
});
});