From 4d8d23830d8951b0d53f8fa5c98537bd0fe63334 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 14 Feb 2017 15:47:36 +0300 Subject: [PATCH] utils tests --- test/utils.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/utils.js b/test/utils.js index 11b867e2a2..95f3040df4 100644 --- a/test/utils.js +++ b/test/utils.js @@ -135,5 +135,41 @@ describe('Utility Methods', function () { done(); }); + it('escape html', function (done) { + var escaped = utils.escapeHTML('&<>'); + assert.equal(escaped, '&<>'); + done(); + }); + + it('should escape regex chars', function (done) { + var escaped = utils.escapeRegexChars('some text {}'); + assert.equal(escaped, 'some\\ text\\ \\{\\}'); + done(); + }); + + it('should get hours array', function (done) { + var currentHour = new Date().getHours(); + var hours = utils.getHoursArray(); + var index = hours.length - 1; + for (var i = currentHour, ii = currentHour - 24; i > ii; i--) { + var hour = i < 0 ? 24 + i : i; + assert.equal(hours[index], hour + ':00'); + -- index; + } + done(); + }); + + it('should get days array', function (done) { + var currentDay = new Date(Date.now()).getTime(); + var days = utils.getDaysArray(); + var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + var index = 0; + for(var x = 29; x >= 0; x--) { + var tmpDate = new Date(currentDay - (1000 * 60 * 60 * 24 * x)); + assert.equal(months[tmpDate.getMonth()] + ' ' + tmpDate.getDate(), days[index]); + ++ index; + } + done(); + }); });