diff --git a/addons/web/static/tests/helpers/test_utils_mock.js b/addons/web/static/tests/helpers/test_utils_mock.js index 5f567e714bc..8758d162a7b 100644 --- a/addons/web/static/tests/helpers/test_utils_mock.js +++ b/addons/web/static/tests/helpers/test_utils_mock.js @@ -446,7 +446,13 @@ function patchDate(year, month, day, hours, minutes, seconds) { } // Copy "native" methods explicitly; they may be non-enumerable - Date.now = NativeDate.now; + // exception: 'now' uses fake date as reference + Date.now = function () { + var date = new NativeDate(); + var time = date.getTime(); + time -= timeInterval; + return time; + }; Date.UTC = NativeDate.UTC; Date.prototype = NativeDate.prototype; Date.prototype.constructor = Date; diff --git a/addons/web/static/tests/helpers/test_utils_tests.js b/addons/web/static/tests/helpers/test_utils_tests.js new file mode 100644 index 00000000000..d4f386625f7 --- /dev/null +++ b/addons/web/static/tests/helpers/test_utils_tests.js @@ -0,0 +1,36 @@ +odoo.define('web.testUtilsTests', function (require) { +"use strict"; + +var testUtils = require('web.test_utils'); + +QUnit.module('web', {}, function () { +QUnit.module('testUtils', {}, function () { + +QUnit.module('patch date'); + +QUnit.test('new date', function (assert) { + assert.expect(5); + const unpatchDate = testUtils.mock.patchDate(2018, 9, 23, 14, 50, 0); + + const date = new Date(); + + assert.strictEqual(date.getFullYear(), 2018); + assert.strictEqual(date.getMonth(), 9); + assert.strictEqual(date.getDate(), 23); + assert.strictEqual(date.getHours(), 14); + assert.strictEqual(date.getMinutes(), 50); + unpatchDate(); +}); + +QUnit.test('new moment', function (assert) { + assert.expect(1); + const unpatchDate = testUtils.mock.patchDate(2018, 9, 23, 14, 50, 0); + + const m = moment(); + assert.strictEqual(m.format('YYYY-MM-DD HH:mm'), '2018-10-23 14:50'); + unpatchDate(); +}); + +}); +}); +}); \ No newline at end of file diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml index 623ce4e2f86..8f18c4cfcdf 100644 --- a/addons/web/views/webclient_templates.xml +++ b/addons/web/views/webclient_templates.xml @@ -704,6 +704,8 @@ + +