diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-02-22 15:40:41 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 274a0aadc672be502b65ad693d5fe2a036ae06ab (patch) | |
| tree | 4bb0debc58e90a3ad5923122ffa7200aa98ba1ab /addons/web/static | |
| parent | 136292f6890ff730b5a9fd70eb503d4f6a0f9c4a (diff) | |
[ADD] web: add domain and field selectors tests
Create a new folder "widgets" in the "test" folder and add basic tests
for the domain and field selector widgets.
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/test/widgets/domain_selector_tests.js | 152 | ||||
| -rw-r--r-- | addons/web/static/test/widgets/model_field_selector_tests.js | 129 |
2 files changed, 281 insertions, 0 deletions
diff --git a/addons/web/static/test/widgets/domain_selector_tests.js b/addons/web/static/test/widgets/domain_selector_tests.js new file mode 100644 index 00000000000..89d36b4bcf2 --- /dev/null +++ b/addons/web/static/test/widgets/domain_selector_tests.js @@ -0,0 +1,152 @@ +odoo.define('web.domain_selector_tests', function (require) { +"use strict"; + +var DomainSelector = require("web.DomainSelector"); +var testUtils = require("web.test_utils"); + +QUnit.module('widgets', {}, function () { + +QUnit.module('DomainSelector', { + beforeEach: function () { + this.data = { + partner: { + fields: { + foo: {string: "Foo", type: "char", searchable: true}, + bar: {string: "Bar", type: "boolean", searchable: true}, + product_id: {string: "Product", type: "many2one", relation: "product", searchable: true}, + }, + records: [{ + id: 1, + foo: "yop", + bar: true, + product_id: 37, + }, { + id: 2, + foo: "blip", + bar: true, + product_id: false, + }, { + id: 4, + foo: "abc", + bar: false, + product_id: 41, + }], + onchanges: {}, + }, + product: { + fields: { + name: {string: "Product Name", type: "char", searchable: true} + }, + records: [{ + id: 37, + display_name: "xphone", + }, { + id: 41, + display_name: "xpad", + }] + }, + }; + }, +}, function () { + + QUnit.test("creating a domain from scratch", function (assert) { + assert.expect(13); + + var $target = $("#qunit-fixture"); + + // Create the domain selector and its mock environment + var domainSelector = new DomainSelector(null, "partner", [], { + readonly: false, + debugMode: true, + }); + testUtils.addMockEnvironment(domainSelector, {data: this.data}); + domainSelector.appendTo($target); + + // As we gave an empty domain, there should be a visible button to add + // the first domain part + var $domainAddFirstNodeButton = domainSelector.$(".o_domain_add_first_node_button:visible"); + assert.strictEqual($domainAddFirstNodeButton.length, 1, + "there should be a button to create first domain element"); + + // Clicking on the button should add a visible field selector in the + // widget so that the user can change the field chain + $domainAddFirstNodeButton.click(); + var $fieldSelector = domainSelector.$(".o_field_selector:visible"); + assert.strictEqual($fieldSelector.length, 1, + "there should be a field selector"); + + // Focusing the field selector input should open a field selector popover + $fieldSelector.find("> input").focus(); + var $fieldSelectorPopover = $fieldSelector.find(".o_field_selector_popover:visible"); + assert.strictEqual($fieldSelectorPopover.length, 1, + "field selector popover should be visible"); + + // The field selector popover should contain the list of "partner" + // fields. "Bar" should be among them. + var $lis = $fieldSelectorPopover.find("li"); + var $barLi = $(); + $lis.each(function () { + var $li = $(this); + if ($li.html().indexOf("Bar") >= 0) { + $barLi = $li; + } + }); + assert.strictEqual($barLi.length, 1, + "field selector popover should contain the 'Bar' field"); + + // Clicking the "Bar" field should change the internal domain and this + // should be displayed in the debug input + $barLi.click(); + assert.strictEqual( + domainSelector.$(".o_domain_debug_input").val(), + '[["bar","=",True]]', + "the domain input should contain a domain with 'bar'" + ); + + // There should be a "+" button to add a domain part; clicking on it + // should add the default "['id', '=', 1]" domain + var $plus = domainSelector.$(".fa-plus"); + assert.strictEqual($plus.length, 1, "there should be a '+' button"); + $plus.click(); + assert.strictEqual( + domainSelector.$(".o_domain_debug_input").val(), + '["&",["bar","=",True],["id","=",1]]', + "the domain input should contain a domain with 'bar' and 'id'"); + + // There should be two "..." buttons to add a domain group; clicking on + // the first one, should add this group with defaults "['id', '=', 1]" + // domains and the "|" operator + var $dots = domainSelector.$(".fa-ellipsis-h"); + assert.strictEqual($dots.length, 2, "there should be two '...' buttons"); + $dots.first().click(); + assert.strictEqual( + domainSelector.$(".o_domain_debug_input").val(), + '["&","&",["bar","=",True],"|",["id","=",1],["id","=",1],["id","=",1]]', + "the domain input should contain a domain with 'bar', 'id' and a subgroup" + ); + + // Changing the domain input to update the subgroup to use the "foo" + // field instead of "id" should rerender the widget and adapt the + // widget suggestions + domainSelector.$(".o_domain_debug_input").val('["&","&",["bar","=",True],"|",["foo","=","hello"],["id","=",1],["id","=",1]]').change(); + assert.strictEqual(domainSelector.$(".o_field_selector").eq(1).find("input").val(), "foo", + "the second field selector should now contain the 'foo' value"); + assert.ok(domainSelector.$(".o_domain_leaf_operator_select").eq(1).html().indexOf("contains") >= 0, + "the second operator selector should now contain the 'contains' operator"); + + // There should be five "-" buttons to remove domain part; clicking on + // the two last ones, should leave a domain with only the "bar" and + // "foo" fields, with the initial "&" operator + var $minus = domainSelector.$(".fa-minus"); + assert.strictEqual($minus.length, 5, "there should be five '-' buttons"); + $minus.last().click(); + domainSelector.$(".fa-minus").last().click(); + assert.strictEqual( + domainSelector.$(".o_domain_debug_input").val(), + '["&",["bar","=",True],["foo","=","hello"]]', + "the domain input should contain a domain with 'bar' and 'foo'" + ); + }); +}); +}); +}); diff --git a/addons/web/static/test/widgets/model_field_selector_tests.js b/addons/web/static/test/widgets/model_field_selector_tests.js new file mode 100644 index 00000000000..18fb5662d96 --- /dev/null +++ b/addons/web/static/test/widgets/model_field_selector_tests.js @@ -0,0 +1,129 @@ +odoo.define('web.model_field_selector_tests', function (require) { +"use strict"; + +var ModelFieldSelector = require("web.ModelFieldSelector"); +var testUtils = require("web.test_utils"); + +QUnit.module('widgets', {}, function () { + +QUnit.module('ModelFieldSelector', { + beforeEach: function () { + this.data = { + partner: { + fields: { + foo: {string: "Foo", type: "char", searchable: true}, + bar: {string: "Bar", type: "boolean", searchable: true}, + product_id: {string: "Product", type: "many2one", relation: "product", searchable: true}, + }, + records: [{ + id: 1, + foo: "yop", + bar: true, + product_id: 37, + }, { + id: 2, + foo: "blip", + bar: true, + product_id: false, + }, { + id: 4, + foo: "abc", + bar: false, + product_id: 41, + }], + onchanges: {}, + }, + product: { + fields: { + name: {string: "Product Name", type: "char", searchable: true} + }, + records: [{ + id: 37, + display_name: "xphone", + }, { + id: 41, + display_name: "xpad", + }] + }, + }; + }, +}, function () { + + QUnit.test("creating a field chain from scratch", function (assert) { + assert.expect(10); + + var $target = $("#qunit-fixture"); + + // Create the field selector and its mock environment + var fieldSelector = new ModelFieldSelector(null, "partner", "", { + debugMode: true, + }); + testUtils.addMockEnvironment(fieldSelector, {data: this.data}); + fieldSelector.appendTo($target); + + // Focusing the field selector input should open a field selector popover + var $input = fieldSelector.$("> input"); + $input.focus(); + var $fieldSelectorPopover = fieldSelector.$(".o_field_selector_popover:visible"); + assert.strictEqual($fieldSelectorPopover.length, 1, + "field selector popover should be visible"); + + // The field selector popover should contain the list of "partner" + // fields. "Bar" should be among them. + var $lis = $fieldSelectorPopover.find("li"); + var $barLi = $(); + $lis.each(function () { + var $li = $(this); + if ($li.html().indexOf("Bar") >= 0) { + $barLi = $li; + } + }); + assert.strictEqual($barLi.length, 1, + "field selector popover should contain the 'Bar' field"); + + // Clicking the "Bar" field should close the popover and set the field + // chain to "bar" as it is a basic field + $barLi.click(); + assert.notOk($fieldSelectorPopover.is("visible"), + "field selector popover should be closed now"); + assert.strictEqual($input.val(), "bar", + "field selector input value should be 'bar'"); + + // Focusing the input again should open the same popover + $input.focus(); + assert.ok($fieldSelectorPopover.is(":visible"), + "field selector popover should be visible"); + + // The field selector popover should contain the list of "partner" + // fields. "Product" should be among them. + $lis = $fieldSelectorPopover.find("li"); + var $productLi = $(); + $lis.each(function () { + var $li = $(this); + if ($li.html().indexOf("Product") >= 0) { + $productLi = $li; + } + }); + assert.strictEqual($productLi.length, 1, + "field selector popover should contain the 'Product' field"); + + // Clicking on the "Product" field should update the popover to show + // the product fields (so only "Product Name" should be there) + $productLi.click(); + $lis = $fieldSelectorPopover.find("li"); + assert.strictEqual($lis.length, 1, + "there should be only one field proposition for 'product' model"); + assert.ok($lis.first().html().indexOf("Product Name") >= 0, + "the name of the only suggestion should be 'Product Name'"); + + // Clicking on "Product Name" should close the popover and set the chain + // to "product_id.name" + $lis.first().click(); + assert.notOk($fieldSelectorPopover.is("visible"), + "field selector popover should be closed now"); + assert.strictEqual($input.val(), "product_id.name", + "field selector input value should be 'product_id.name'"); + }); +}); +}); +}); |
