diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-05-18 09:36:14 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-05-18 13:55:46 +0200 |
| commit | 94c91374e33f80256398f7ac2f892500aaf7e685 (patch) | |
| tree | ad086e6c0b5bb751021ede9be38b8f3b1f0c03af /addons/web/static/tests/fields | |
| parent | 3dd97db07fcf22bf1dd7fcaa912a20438483bc7c (diff) | |
[FIX] web: selection field with value 0
The server doesn't make a distinction between an unset selection
field, and a value 0 (integer). So when 0 is a valid key for the
field, the server returns false as value if the field is unset, or
if its value is 0, which is not really convenient.
As a consequence, when the value is 0, it appears as unset in the
interface. To circumvent this, we automatically converts false
value of selection fields to 0, if 0 is a key of the selection.
Diffstat (limited to 'addons/web/static/tests/fields')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 2c6d35bc915..a6abf4be4b3 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -4004,6 +4004,65 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('unset selection field with 0 as key', function (assert) { + // The server doesn't make a distinction between false value (the field + // is unset), and selection 0, as in that case the value it returns is + // false. So the client must convert false to value 0 if it exists. + assert.expect(2); + + this.data.partner.fields.selection = { + type: "selection", + selection: [[0, "Value O"], [1, "Value 1"]], + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="selection"/>' + + '</form>', + res_id: 1, + }); + + assert.strictEqual(form.$('.o_field_widget').text(), 'Value O', + "the displayed value should be 'Value O'"); + assert.notOk(form.$('.o_field_widget').hasClass('o_field_empty'), + "should not have class o_field_empty"); + + form.destroy(); + }); + + QUnit.test('unset selection field with string keys', function (assert) { + // The server doesn't make a distinction between false value (the field + // is unset), and selection 0, as in that case the value it returns is + // false. So the client must convert false to value 0 if it exists. In + // this test, it doesn't exist as keys are strings. + assert.expect(2); + + this.data.partner.fields.selection = { + type: "selection", + selection: [['0', "Value O"], ['1', "Value 1"]], + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="selection"/>' + + '</form>', + res_id: 1, + }); + + assert.strictEqual(form.$('.o_field_widget').text(), '', + "there should be no displayed value"); + assert.ok(form.$('.o_field_widget').hasClass('o_field_empty'), + "should have class o_field_empty"); + + form.destroy(); + }); + QUnit.module('FieldMany2ManyTags'); QUnit.test('fieldmany2many tags: rendering and edition', function (assert) { |
