summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/helpers/test_utils.js
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2018-08-14 11:01:06 +0200
committerMathieu Duckerts-Antoine <dam@odoo.com>2018-08-14 12:30:51 +0200
commit3523694b6cdce621585893100c7cfbe9495c9eff (patch)
treee7eb308b3c738408a0a023ea7221fc112ba0e747 /addons/web/static/tests/helpers/test_utils.js
parentb46156d4a2d3410f28826379ba9768d596e5d062 (diff)
[IMP] web: add a patchDate function in testUtils
This function allows to properly mock Dates in js Tests
Diffstat (limited to 'addons/web/static/tests/helpers/test_utils.js')
-rw-r--r--addons/web/static/tests/helpers/test_utils.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js
index 767f0de6dbc..a8ff1743436 100644
--- a/addons/web/static/tests/helpers/test_utils.js
+++ b/addons/web/static/tests/helpers/test_utils.js
@@ -249,6 +249,35 @@ function createAsyncView(params) {
});
}
+// Months are indexed starting at zero
+function patchDate (year, month, day, hours, minutes, seconds) {
+
+ var RealDate = window.Date;
+ var actualDate = new RealDate();
+ var fakeDate = new RealDate(year, month, day, hours, minutes, seconds);
+ var timeInterval = actualDate.getTime() - (fakeDate.getTime());
+
+ window.Date = function Date() {
+ if (arguments.length > 0) {
+ return RealDate.apply(this, arguments);
+ } else {
+ // months are indexed from 0!
+ var date = new RealDate();
+ var time = date.getTime();
+ time -= timeInterval;
+ date.setTime(time);
+ return date;
+ }
+ };
+
+ _.mapObject(RealDate, function (val, key) {
+ window.Date[key] = val;
+ });
+ window.Date.prototype = RealDate.prototype;
+
+ return function () {window.Date = RealDate;};
+}
+
/**
* Add a mock environment to a widget. This helper function can simulate
* various kind of side effects, such as mocking RPCs, changing the session,
@@ -823,6 +852,7 @@ return $.when(
intercept: intercept,
observe: observe,
patch: patch,
+ patchDate: patchDate,
removeSrcAttribute: removeSrcAttribute,
triggerKeypressEvent: triggerKeypressEvent,
triggerMouseEvent: triggerMouseEvent,