Files
odoo_source/addons/web/static/tests/views/basic_view_tests.js
T
yograj tandelandMohammed Shekha ef62df2bfd [IMP] web: consider FieldDependencies given on custom widget
With this commit we support adding FieldDependencies on custom widget, consider
FieldDependencies given on custom widget and add it to fieldInfo so that when
modal does calls to server to fetch data it consider those fields while reading

this will let us to design custom widget which may have some other fields in
dependency, say for example weekly recurrence widget which uses sun, mon etc.
fields, so with this we can fetch data of those dependent fields without adding
it to view.

task-2335399

closes odoo/odoo#60277

Related: odoo/upgrade#2021
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Co-authored-by: Mohammed Shekha <msh@odoo.com>
2021-03-26 12:25:44 +00:00

79 lines
2.5 KiB
JavaScript

odoo.define('web.basic_view_tests', function (require) {
"use strict";
const BasicView = require('web.BasicView');
const BasicRenderer = require("web.BasicRenderer");
const testUtils = require('web.test_utils');
const widgetRegistryOwl = require('web.widgetRegistry');
const { xml } = owl.tags;
const createView = testUtils.createView;
QUnit.module('Views', {
beforeEach: function () {
this.data = {
fake_model: {
fields: {},
record: [],
},
foo: {
fields: {
foo: { string: "Foo", type: "char" },
bar: { string: "Bar", type: "boolean" },
},
records: [
{ id: 1, bar: true, foo: "yop" },
{ id: 2, bar: true, foo: "blip" },
]
},
};
},
}, function () {
QUnit.module('BasicView');
QUnit.test('fields given in fieldDependencies of custom widget are loaded', async function (assert) {
assert.expect(1);
const basicView = BasicView.extend({
viewType: "test",
config: Object.assign({}, BasicView.prototype.config, {
Renderer: BasicRenderer,
})
});
class MyWidget extends owl.Component {}
MyWidget.fieldDependencies = {
foo: { type: 'char' },
bar: { type: 'boolean' },
};
MyWidget.template = xml/* xml */`
<div class="custom-widget">Hello World!</div>
`;
widgetRegistryOwl.add('testWidget', MyWidget);
const view = await createView({
View: basicView,
data: this.data,
model: "foo",
arch:
`<test>
<widget name="testWidget"/>
</test>`,
mockRPC: function (route, args) {
if (route === "/web/dataset/search_read") {
assert.deepEqual(args.fields, ["foo", "bar"],
"search_read should be called with dependent fields");
return Promise.resolve();
}
return this._super.apply(this, arguments);
}
});
view.destroy();
delete widgetRegistryOwl.map.testWidget;
});
});
});