3
0
Fork 0

[IMP] web_widget_dropdown_dynamic: black, isort, prettier

15.0-ocabot-merge-pr-2789-by-pedrobaeza-bump-patch
Thanakrit Pintana 2021-11-30 16:13:18 +07:00
parent b0df022207
commit 2788bb6aa1
3 changed files with 179 additions and 158 deletions

View File

@ -0,0 +1 @@
../../../../web_widget_dropdown_dynamic

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@ -1,173 +1,187 @@
odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", function ( odoo.define(
require "web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests",
) { function (require) {
"use strict"; "use strict";
/* global QUnit*/ /* global QUnit*/
var FormView = require("web.FormView"); var FormView = require("web.FormView");
var testUtils = require("web.test_utils"); var testUtils = require("web.test_utils");
QUnit.module("web_widget_dropdown_dynamic", {}, function () { QUnit.module("web_widget_dropdown_dynamic", {}, function () {
QUnit.test("values are fetched w/o context (char)", async function (assert) { QUnit.test(
assert.expect(2); "values are fetched w/o context (char)",
async function (assert) {
assert.expect(2);
var form = await testUtils.createView({ var form = await testUtils.createView({
View: FormView, View: FormView,
model: "demo_entry", model: "demo_entry",
data: { data: {
demo_entry: { demo_entry: {
fields: { fields: {
test_field: {string: "Test Field", type: "char"}, test_field: {string: "Test Field", type: "char"},
},
records: [{id: 1, test_field: ""}],
},
}, },
records: [{id: 1, test_field: ""}], arch:
}, "<form>" +
}, '<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
arch: "</form>",
"<form>" + mockRPC: function (route, args) {
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' + if (args.method === "_get_test_field_values") {
"</form>", return Promise.resolve([["value", "Title"]]);
mockRPC: function (route, args) { }
if (args.method === "_get_test_field_values") { return this._super.apply(this, arguments);
return Promise.resolve([["value", "Title"]]);
}
return this._super.apply(this, arguments);
},
});
assert.containsN(form, "option", 2);
assert.containsOnce(form, "option[value='\"value\"']");
form.destroy();
});
QUnit.test("values are fetched w/o context (integer)", async function (assert) {
assert.expect(2);
var form = await testUtils.createView({
View: FormView,
model: "demo_entry",
data: {
demo_entry: {
fields: {
test_field: {string: "Test Field", type: "integer"},
}, },
records: [{id: 1, test_field: 0}], });
},
},
arch:
"<form>" +
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
"</form>",
mockRPC: function (route, args) {
if (args.method === "_get_test_field_values") {
return Promise.resolve([[0, "Title"]]);
}
return this._super.apply(this, arguments);
},
});
assert.containsN(form, "option", 2); assert.containsN(form, "option", 2);
assert.containsOnce(form, "option[value='0']"); assert.containsOnce(form, "option[value='\"value\"']");
form.destroy(); form.destroy();
}); }
QUnit.test("values are fetched w/o context (selection)", async function (
assert
) {
assert.expect(2);
var form = await testUtils.createView({
View: FormView,
model: "demo_entry",
data: {
demo_entry: {
fields: {
test_field: {string: "Test Field", type: "selection"},
},
records: [{id: 1, test_field: ""}],
},
},
arch:
"<form>" +
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
"</form>",
mockRPC: function (route, args) {
if (args.method === "_get_test_field_values") {
return Promise.resolve([["value", "Title"]]);
}
return this._super.apply(this, arguments);
},
});
assert.containsN(form, "option", 2);
assert.containsOnce(form, "option[value='\"value\"']");
form.destroy();
});
QUnit.test("values are fetched with changing context", async function (assert) {
assert.expect(6);
var form = await testUtils.createView({
View: FormView,
model: "demo_entry",
data: {
demo_entry: {
fields: {
other_field: {string: "Other Field", type: "char"},
test_field: {string: "Test Field", type: "char"},
},
records: [{id: 1, other_field: "", test_field: ""}],
},
},
arch:
"<form>" +
'<field name="other_field" />' +
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values" context="{\'step\': other_field}"/>' +
"</form>",
mockRPC: function (route, args) {
if (args.method === "_get_test_field_values") {
if (args.kwargs.context.step === "step-1") {
return Promise.resolve([["value", "Title"]]);
} else if (args.kwargs.context.step === "step-2") {
return Promise.resolve([
["value", "Title"],
["value_2", "Title 2"],
]);
}
return Promise.resolve([]);
}
return this._super.apply(this, arguments);
},
});
await testUtils.fields.editAndTrigger(
form.$('.o_field_widget[name="other_field"]'),
"step-1",
["input"]
); );
assert.containsN(form, "option", 2);
assert.containsOnce(form, "option[value='\"value\"']");
await testUtils.fields.editAndTrigger( QUnit.test(
form.$('.o_field_widget[name="other_field"]'), "values are fetched w/o context (integer)",
"step-2", async function (assert) {
["input"] assert.expect(2);
var form = await testUtils.createView({
View: FormView,
model: "demo_entry",
data: {
demo_entry: {
fields: {
test_field: {string: "Test Field", type: "integer"},
},
records: [{id: 1, test_field: 0}],
},
},
arch:
"<form>" +
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
"</form>",
mockRPC: function (route, args) {
if (args.method === "_get_test_field_values") {
return Promise.resolve([[0, "Title"]]);
}
return this._super.apply(this, arguments);
},
});
assert.containsN(form, "option", 2);
assert.containsOnce(form, "option[value='0']");
form.destroy();
}
); );
assert.containsN(form, "option", 3);
assert.containsOnce(form, "option[value='\"value\"']");
assert.containsOnce(form, "option[value='\"value_2\"']");
await testUtils.fields.editAndTrigger( QUnit.test(
form.$('.o_field_widget[name="other_field"]'), "values are fetched w/o context (selection)",
"step-other", async function (assert) {
["input"] assert.expect(2);
var form = await testUtils.createView({
View: FormView,
model: "demo_entry",
data: {
demo_entry: {
fields: {
test_field: {
string: "Test Field",
type: "selection",
},
},
records: [{id: 1, test_field: ""}],
},
},
arch:
"<form>" +
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
"</form>",
mockRPC: function (route, args) {
if (args.method === "_get_test_field_values") {
return Promise.resolve([["value", "Title"]]);
}
return this._super.apply(this, arguments);
},
});
assert.containsN(form, "option", 2);
assert.containsOnce(form, "option[value='\"value\"']");
form.destroy();
}
); );
assert.containsN(form, "option", 1);
form.destroy(); QUnit.test(
"values are fetched with changing context",
async function (assert) {
assert.expect(6);
var form = await testUtils.createView({
View: FormView,
model: "demo_entry",
data: {
demo_entry: {
fields: {
other_field: {string: "Other Field", type: "char"},
test_field: {string: "Test Field", type: "char"},
},
records: [{id: 1, other_field: "", test_field: ""}],
},
},
arch:
"<form>" +
'<field name="other_field" />' +
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values" context="{\'step\': other_field}"/>' +
"</form>",
mockRPC: function (route, args) {
if (args.method === "_get_test_field_values") {
if (args.kwargs.context.step === "step-1") {
return Promise.resolve([["value", "Title"]]);
} else if (args.kwargs.context.step === "step-2") {
return Promise.resolve([
["value", "Title"],
["value_2", "Title 2"],
]);
}
return Promise.resolve([]);
}
return this._super.apply(this, arguments);
},
});
await testUtils.fields.editAndTrigger(
form.$('.o_field_widget[name="other_field"]'),
"step-1",
["input"]
);
assert.containsN(form, "option", 2);
assert.containsOnce(form, "option[value='\"value\"']");
await testUtils.fields.editAndTrigger(
form.$('.o_field_widget[name="other_field"]'),
"step-2",
["input"]
);
assert.containsN(form, "option", 3);
assert.containsOnce(form, "option[value='\"value\"']");
assert.containsOnce(form, "option[value='\"value_2\"']");
await testUtils.fields.editAndTrigger(
form.$('.o_field_widget[name="other_field"]'),
"step-other",
["input"]
);
assert.containsN(form, "option", 1);
form.destroy();
}
);
}); });
}); }
}); );