/** @odoo-module **/
import { FileSelectorControlPanel } from '@web_editor/components/media_dialog/file_selector';
import { getFixture, patchWithCleanup } from "@web/../tests/helpers/utils";
import { HtmlField } from '@web_editor/js/backend/html_field';
import {registry} from '@web/core/registry';
import testUtils from 'web.test_utils';
import { uploadService } from '@web_editor/components/upload_progress_toast/upload_service';
import { unsplashService } from '@web_unsplash/services/unsplash_service';
import { createWebClient, doAction } from "@web/../tests/webclient/helpers";
import weTestUtils from 'web_editor.test_utils';
import Wysiwyg from 'web_editor.wysiwyg';
const { useEffect } = owl;
QUnit.module('field html file upload', {
beforeEach: function () {
this.data = weTestUtils.wysiwygData({
'mail.compose.message': {
fields: {
display_name: {
string: "Displayed name",
type: "char"
},
body: {
string: "Message Body inline (to send)",
type: "html"
},
attachment_ids: {
string: "Attachments",
type: "many2many",
relation: "ir.attachment",
}
},
records: [{
id: 1,
display_name: "Some Composer",
body: "Hello",
attachment_ids: [],
}],
},
});
},
}, function () {
QUnit.test('media dialog: upload', async function (assert) {
assert.expect(4);
const onAttachmentChangeTriggered = testUtils.makeTestPromise();
patchWithCleanup(HtmlField.prototype, {
'_onAttachmentChange': function (event) {
this._super(event);
onAttachmentChangeTriggered.resolve(true);
}
});
const defFileSelector = testUtils.makeTestPromise();
const onChangeTriggered = testUtils.makeTestPromise();
patchWithCleanup(FileSelectorControlPanel.prototype, {
setup() {
this._super();
useEffect(() => {
defFileSelector.resolve(true);
}, () => []);
},
async onChangeFileInput() {
this._super();
onChangeTriggered.resolve(true);
}
});
// create and load form view
const serviceRegistry = registry.category("services");
serviceRegistry.add("upload", uploadService);
serviceRegistry.add("unsplash", unsplashService);
const serverData = {
models: this.data,
};
serverData.actions = {
1: {
id: 1,
name: "test",
res_model: "mail.compose.message",
type: "ir.actions.act_window",
views: [[false, "form"]],
},
};
serverData.views = {
"mail.compose.message,false,search": "