From 2788bb6aa14c391e655a44e2d62aacdc244d8427 Mon Sep 17 00:00:00 2001 From: Thanakrit Pintana Date: Tue, 30 Nov 2021 16:13:18 +0700 Subject: [PATCH] [IMP] web_widget_dropdown_dynamic: black, isort, prettier --- .../odoo/addons/web_widget_dropdown_dynamic | 1 + setup/web_widget_dropdown_dynamic/setup.py | 6 + .../web_widget_dropdown_dynamic_tests.js | 330 +++++++++--------- 3 files changed, 179 insertions(+), 158 deletions(-) create mode 120000 setup/web_widget_dropdown_dynamic/odoo/addons/web_widget_dropdown_dynamic create mode 100644 setup/web_widget_dropdown_dynamic/setup.py diff --git a/setup/web_widget_dropdown_dynamic/odoo/addons/web_widget_dropdown_dynamic b/setup/web_widget_dropdown_dynamic/odoo/addons/web_widget_dropdown_dynamic new file mode 120000 index 000000000..df3532d14 --- /dev/null +++ b/setup/web_widget_dropdown_dynamic/odoo/addons/web_widget_dropdown_dynamic @@ -0,0 +1 @@ +../../../../web_widget_dropdown_dynamic \ No newline at end of file diff --git a/setup/web_widget_dropdown_dynamic/setup.py b/setup/web_widget_dropdown_dynamic/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_widget_dropdown_dynamic/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_widget_dropdown_dynamic/static/tests/web_widget_dropdown_dynamic_tests.js b/web_widget_dropdown_dynamic/static/tests/web_widget_dropdown_dynamic_tests.js index 494e64e4e..152927895 100644 --- a/web_widget_dropdown_dynamic/static/tests/web_widget_dropdown_dynamic_tests.js +++ b/web_widget_dropdown_dynamic/static/tests/web_widget_dropdown_dynamic_tests.js @@ -1,173 +1,187 @@ -odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", function ( - require -) { - "use strict"; +odoo.define( + "web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", + function (require) { + "use strict"; - /* global QUnit*/ + /* global QUnit*/ - var FormView = require("web.FormView"); - var testUtils = require("web.test_utils"); + var FormView = require("web.FormView"); + var testUtils = require("web.test_utils"); - QUnit.module("web_widget_dropdown_dynamic", {}, function () { - QUnit.test("values are fetched w/o context (char)", async function (assert) { - assert.expect(2); + QUnit.module("web_widget_dropdown_dynamic", {}, function () { + QUnit.test( + "values are fetched w/o context (char)", + 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: "char"}, + var form = await testUtils.createView({ + View: FormView, + model: "demo_entry", + data: { + demo_entry: { + fields: { + test_field: {string: "Test Field", type: "char"}, + }, + records: [{id: 1, test_field: ""}], + }, }, - records: [{id: 1, test_field: ""}], - }, - }, - arch: - "
" + - '' + - "", - 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 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"}, + arch: + "
" + + '' + + "", + mockRPC: function (route, args) { + if (args.method === "_get_test_field_values") { + return Promise.resolve([["value", "Title"]]); + } + return this._super.apply(this, arguments); }, - records: [{id: 1, test_field: 0}], - }, - }, - arch: - "
" + - '' + - "", - 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']"); + assert.containsN(form, "option", 2); + assert.containsOnce(form, "option[value='\"value\"']"); - 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: - "
" + - '' + - "", - 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: - "
" + - '' + - '' + - "", - 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"] + form.destroy(); + } ); - 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"] + 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: + "
" + + '' + + "", + 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( - form.$('.o_field_widget[name="other_field"]'), - "step-other", - ["input"] + 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: + "
" + + '' + + "", + 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: + "
" + + '' + + '' + + "", + 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(); + } + ); }); - }); -}); + } +);