summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorDavid Monjoie <dmo@odoo.com>2017-03-14 10:57:49 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit93d09397af8c97a4e2092bfe0cc1215010a8fe0b (patch)
tree33be3f73b06c060705802d1ff7702b572c10f179 /addons/web/static
parent8992b7751c626a30fd188473400ed43951c26b35 (diff)
[ADD] web: add integer field tests and documentation
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js8
-rw-r--r--addons/web/static/test/fields/basic_fields_tests.js87
2 files changed, 93 insertions, 2 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index f4f5496006c..d3dab0fe647 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -383,8 +383,14 @@ var FieldBoolean = AbstractField.extend({
var FieldInteger = InputField.extend({
supportedFieldTypes: ['integer'],
+
+ /**
+ * For integer fields, 0 is a valid value.
+ *
+ * @override
+ */
isSet: function () {
- return this.value !== false;
+ return this.value === 0 || this._super.apply(this, arguments);
},
});
diff --git a/addons/web/static/test/fields/basic_fields_tests.js b/addons/web/static/test/fields/basic_fields_tests.js
index 1e79bdda753..b9f01d6a654 100644
--- a/addons/web/static/test/fields/basic_fields_tests.js
+++ b/addons/web/static/test/fields/basic_fields_tests.js
@@ -46,7 +46,7 @@ QUnit.module('basic_fields', {
display_name: "second record",
bar: true,
foo: "blip",
- int_field: 9,
+ int_field: 0,
qux: 13,
p: [],
timmy: [],
@@ -57,6 +57,7 @@ QUnit.module('basic_fields', {
display_name: "aaa",
foo: "abc",
sequence: 9,
+ int_field: false,
},
{id: 3, bar: true, foo: "gnap", int_field: 17, qux: -3, m2o: 1, m2m: []},
{id: 4, bar: false, foo: "blip", int_field: -4, qux: 9, m2o: 1, m2m: [1]}],
@@ -895,6 +896,90 @@ QUnit.module('basic_fields', {
list.destroy();
});
+
+ QUnit.module('FieldInteger');
+
+ QUnit.test('integer field when unset', function(assert) {
+ assert.expect(1);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners"><field name="int_field"/></form>',
+ res_id: 4,
+ });
+
+ assert.ok(form.$('.o_form_field').hasClass('o_form_field_empty'),
+ 'Non-set integer field should be recognized as unset.');
+
+ form.destroy();
+ });
+
+ QUnit.test('integer field in form view', function(assert) {
+ assert.expect(4);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners"><field name="int_field"/></form>',
+ res_id: 2,
+ });
+
+ assert.ok(!form.$('.o_form_field').hasClass('o_form_field_empty'),
+ 'Integer field should be considered set for value 0.');
+
+ form.$buttons.find('.o_form_button_edit').click();
+ assert.strictEqual(form.$('input.o_form_input').val(), '0',
+ 'The value should be rendered correctly in edit mode.')
+
+ form.$('input.o_form_input').val('-18').trigger('input');
+ assert.strictEqual(form.$('input.o_form_input').val(), '-18',
+ 'The value should be correctly displayed in the input.')
+
+ form.$buttons.find('.o_form_button_save').click();
+ assert.strictEqual(form.$('.o_form_field').text(), '-18',
+ 'The new value should be saved and displayed properly.')
+
+ form.destroy();
+ });
+
+ QUnit.test('integer field in editable list view', function (assert) {
+ assert.expect(4);
+
+ var list = createView({
+ View: ListView,
+ model: 'partner',
+ data: this.data,
+ arch: '<tree editable="bottom">' +
+ '<field name="int_field"/>' +
+ '</tree>',
+ });
+
+ var zeroValues = list.$('td').filter(function() {return $(this).text() === '0'});
+ assert.strictEqual(zeroValues.length, 1,
+ 'Unset integer values should not be rendered as zeros.');
+
+ // switch to edit mode
+ var $cell = list.$('tr.o_data_row td:not(.o_list_record_selector)').first();
+ $cell.click();
+
+ assert.strictEqual(list.$('input.o_form_input').length, 1,
+ 'The view should have 1 input for editable integer.')
+
+ list.$('input.o_form_input').val('-28').trigger('input');
+ assert.strictEqual(list.$('input.o_form_input').val(), '-28',
+ 'The value should be displayed properly in the input.')
+
+ list.$buttons.find('.o_list_button_save').click();
+ assert.strictEqual(list.$('td:not(.o_list_record_selector)').first().text(), '-28',
+ 'The new value should be saved and displayed properly.')
+
+ list.destroy();
+ });
+
+
QUnit.module('FieldDomain');
QUnit.test('basic domain field usage is ok', function (assert) {