[FIX] web: momentjs warnings

* Without an explicit format string, moment() should be called with
  ISO date(times).
* Correctly destroy all test locales (`zz` was not destroyed at all,
  and `englishForTest` was double-destroyed instead of destroying
  `frenchForTests`).
* Avoid creating a moment object from the value `false` in date(time)
  fields.
* Disable the warning entirely in dates_tests, the contents are super
  messy and weird.
This commit is contained in:
Xavier Morel
2021-06-29 05:34:16 +00:00
parent 29de1ef72b
commit 053285afdc
5 changed files with 22 additions and 16 deletions
@@ -64,8 +64,8 @@ odoo.define('hr_holidays.leave_stats_widget_tests', function (require) {
id: 13,
employee_id: 100,
department_id: 11,
date_from: "2016-10-2 09:00:00",
date_to: "2016-10-2 18:00:00",
date_from: "2016-10-02 09:00:00",
date_to: "2016-10-02 18:00:00",
holiday_status_id: 55,
state: 'validate',
number_of_days: 1,
@@ -926,8 +926,8 @@ var FieldDate = InputField.extend({
* @returns {boolean}
*/
_isSameValue: function (value) {
if (value === false) {
return this.value === false;
if (this.value === false || value === false) {
return this.value === value;
}
return value.isSame(this.value, 'day');
},
@@ -1005,8 +1005,8 @@ var FieldDateTime = FieldDate.extend({
* @private
*/
_isSameValue: function (value) {
if (value === false) {
return this.value === false;
if (this.value === false || value === false) {
return this.value === value;
}
return value.isSame(this.value);
},
@@ -59,7 +59,11 @@ function runTestSet(assert, testSet, options) {
}
}
QUnit.module("utils", () => {
QUnit.module("utils", {
before() {moment.suppressDeprecationWarnings = true;},
after() {moment.suppressDeprecationWarnings = false;},
}, () => {
QUnit.module("dates");
QUnit.test("formatDateTime", async (assert) => {
@@ -15,9 +15,10 @@ odoo.define('web.datepicker_tests', function (require) {
assert.expect(8);
const picker = await createComponent(DatePicker, {
props: { date: moment('01/09/1997') },
props: { date: moment('1997-01-09') },
});
assert.containsOnce(picker, 'input.o_input.o_datepicker_input');
assert.containsOnce(picker, 'span.o_datepicker_button');
assert.containsNone(document.body, 'div.bootstrap-datetimepicker-widget');
@@ -46,7 +47,7 @@ odoo.define('web.datepicker_tests', function (require) {
assert.expect(5);
const picker = await createComponent(DatePicker, {
props: { date: moment('01/09/1997') },
props: { date: moment('1997-01-09') },
intercepts: {
'datetime-changed': ev => {
assert.step('datetime-changed');
@@ -106,7 +107,7 @@ odoo.define('web.datepicker_tests', function (require) {
assert.verifySteps(['datetime-changed']);
moment.locale(originalLocale);
moment.updateLocale('englishForTest', null);
moment.updateLocale('frenchForTests', null);
picker.destroy();
});
@@ -115,7 +116,7 @@ odoo.define('web.datepicker_tests', function (require) {
assert.expect(5);
const picker = await createComponent(DatePicker, {
props: { date: moment('01/09/1997') },
props: { date: moment('1997-01-09') },
intercepts: {
'datetime-changed': ev => {
assert.step('datetime-changed');
@@ -148,7 +149,7 @@ odoo.define('web.datepicker_tests', function (require) {
testUtils.patch(time, { getLangDateFormat: () => "YYYY/MM/DD" });
const picker = await createComponent(DatePicker, {
props: { date: moment('01/09/1997') },
props: { date: moment('1997-01-09') },
});
const input = picker.el.querySelector('.o_datepicker_input');
@@ -169,7 +170,7 @@ odoo.define('web.datepicker_tests', function (require) {
assert.expect(11);
const picker = await createComponent(DateTimePicker, {
props: { date: moment('01/09/1997 12:30:01') },
props: { date: moment('1997-01-09 12:30:01') },
});
assert.containsOnce(picker, 'input.o_input.o_datepicker_input');
@@ -204,7 +205,7 @@ odoo.define('web.datepicker_tests', function (require) {
assert.expect(5);
const picker = await createComponent(DateTimePicker, {
props: { date: moment('01/09/1997 12:30:01') },
props: { date: moment('1997-01-09 12:30:01') },
intercepts: {
'datetime-changed': ev => {
assert.step('datetime-changed');
@@ -292,7 +293,7 @@ odoo.define('web.datepicker_tests', function (require) {
assert.expect(9);
const picker = await createComponent(DateTimePicker, {
props: { date: moment('01/09/1997 12:30:01') },
props: { date: moment('1997-01-09 12:30:01') },
intercepts: {
'datetime-changed': ev => {
assert.step('datetime-changed');
@@ -332,7 +333,7 @@ odoo.define('web.datepicker_tests', function (require) {
testUtils.patch(time, { getLangDatetimeFormat: () => "hh:mm:ss YYYY/MM/DD" });
const picker = await createComponent(DateTimePicker, {
props: { date: moment('01/09/1997 12:30:01') },
props: { date: moment('1997-01-09 12:30:01') },
});
const input = picker.el.querySelector('.o_datepicker_input');
@@ -3369,6 +3369,7 @@ QUnit.module('Views', {
'The day should be in the given locale specific format');
moment.locale(initialLocale);
moment.defineLocale('zz', null);
calendar.destroy();
});