/** @odoo-module **/
import weTestUtils from "@web_editor/../tests/test_utils";
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
import {
editInput,
getFixture,
makeDeferred,
nextTick,
patchWithCleanup,
} from "@web/../tests/helpers/utils";
import { assets } from "@web/core/assets";
import { Wysiwyg } from '@web_editor/js/wysiwyg/wysiwyg';
let serverData;
let fixture;
QUnit.module('mass_mailing', {}, function () {
QUnit.module('field html', (hooks) => {
hooks.beforeEach(() => {
fixture = getFixture();
const models = weTestUtils.wysiwygData({
'mailing.mailing': {
fields: {
display_name: {
string: "Displayed name",
type: "char"
},
body_html: {
string: "Message Body inline (to send)",
type: "html"
},
body_arch: {
string: "Message Body for edition",
type: "html"
},
},
records: [{
id: 1,
display_name: "first record",
body_html: "
",
body_arch: "",
}],
},
});
serverData = { models };
setupViewRegistries();
patchWithCleanup(Wysiwyg.prototype, {
async _getColorpickerTemplate() {
return weTestUtils.COLOR_PICKER_TEMPLATE;
},
async _getAssets() {
return [{
cssLibs: [],
jsLibs: [],
cssContents: ['.field_body {background-color: red;}'],
jsContents: ['window.odoo = {define: function(){}}; // inline asset'],
}];
},
});
});
QUnit.test('save arch and html', async function (assert) {
assert.expect(2);
await makeView({
type: "form",
resModel: 'mailing.mailing',
resId: 1,
serverData,
arch: '',
});
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: `
`,
});
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"]);
});
});
});