summaryrefslogtreecommitdiff
path: root/addons/web/static/test
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-02-24 14:35:39 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commitda4e653695cceb1d3cbd9342b3cd830734c21fee (patch)
tree9bdf4df349b00c433ad84d53d4239a3e406c28c0 /addons/web/static/test
parent4a612171b3bf85f2902c582fcc658eea668a732e (diff)
[FIX] web: various fixes for date and datetime in client
The field_utils date method have been modified recently, and the idea behind those changes is that the BasicModel keeps at all time a moment instance as its internal representation of a date or datetime. But the parse and format methods did not properly support unset dates, so we have to slighlty change them to support the case where their values is not set.
Diffstat (limited to 'addons/web/static/test')
-rw-r--r--addons/web/static/test/fields/basic_fields_tests.js16
-rw-r--r--addons/web/static/test/views/basic_model_tests.js58
2 files changed, 71 insertions, 3 deletions
diff --git a/addons/web/static/test/fields/basic_fields_tests.js b/addons/web/static/test/fields/basic_fields_tests.js
index cdba48ceff3..62d8e0f8a86 100644
--- a/addons/web/static/test/fields/basic_fields_tests.js
+++ b/addons/web/static/test/fields/basic_fields_tests.js
@@ -479,6 +479,22 @@ QUnit.module('basic_fields', {
QUnit.module('FieldDate');
+ QUnit.test('date field is empty if no date is set', function (assert) {
+ assert.expect(2);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners"><field name="date"/></form>',
+ res_id: 4,
+ });
+ var $span = form.$('span.o_form_field');
+ assert.strictEqual($span.length, 1, "should have one span in the form view");
+ assert.strictEqual($span.text(), "", "and it should be empty");
+
+ });
+
QUnit.test('date field in edit mode', function (assert) {
assert.expect(7);
diff --git a/addons/web/static/test/views/basic_model_tests.js b/addons/web/static/test/views/basic_model_tests.js
index 2624fb77c8c..83bdfa752c2 100644
--- a/addons/web/static/test/views/basic_model_tests.js
+++ b/addons/web/static/test/views/basic_model_tests.js
@@ -23,7 +23,7 @@ QUnit.module('Views', {
},
records: [
{id: 1, foo: 'blip', bar: 1, product_id: 37, category: [12], display_name: "first partner", date: "2017-01-25"},
- {id: 2, foo: 'gnap', bar: 2, product_id: 41, display_name: "second partner", date: "2017-01-26"},
+ {id: 2, foo: 'gnap', bar: 2, product_id: 41, display_name: "second partner"},
],
onchanges: {},
},
@@ -718,9 +718,38 @@ QUnit.module('Views', {
});
- QUnit.test('dates are properly loaded and parsed', function (assert) {
- assert.expect(1);
+ QUnit.test('dates are properly loaded and parsed (record)', function (assert) {
+ assert.expect(2);
+
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ });
+
+ var params = {
+ fieldNames: ['date'],
+ fields: this.data.partner.fields,
+ modelName: 'partner',
+ res_id: 1,
+ };
+ model.load(params).then(function (resultID) {
+ var record = model.get(resultID);
+ assert.ok(record.data.date instanceof moment,
+ "fetched date field should have been formatted");
+ });
+
+ params.res_id = 2;
+
+ model.load(params).then(function (resultID) {
+ var record = model.get(resultID);
+ assert.strictEqual(record.data.date, false,
+ "unset date field should be false");
+ });
+ });
+
+ QUnit.test('dates are properly loaded and parsed (list)', function (assert) {
+ assert.expect(2);
var model = createModel({
Model: BasicModel,
@@ -737,8 +766,31 @@ QUnit.module('Views', {
model.load(params).then(function (resultID) {
var record = model.get(resultID);
var firstRecord = record.data[0];
+ var secondRecord = record.data[1];
assert.ok(firstRecord.data.date instanceof moment,
"fetched date field should have been formatted");
+ assert.strictEqual(secondRecord.data.date, false,
+ "if date is not set, it should be false");
+ });
+ });
+
+ QUnit.test('dates are properly loaded and parsed (default_get)', function (assert) {
+ assert.expect(1);
+
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ });
+
+ var params = {
+ fieldNames: ['date'],
+ fields: this.data.partner.fields,
+ modelName: 'partner',
+ };
+
+ model.makeDefaultRecord('partner', params).then(function (resultID) {
+ var record = model.get(resultID);
+ assert.strictEqual(record.data.date, false, "date default value should be false");
});
});