2018-06-02 22:48:23 +03:00
|
|
|
var should = require('should'),
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
// Stuff we are testing
|
2019-06-19 12:30:28 +03:00
|
|
|
helpers = require('../../../frontend/helpers'),
|
2017-03-21 11:24:11 +03:00
|
|
|
moment = require('moment-timezone');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{date}} helper', function () {
|
|
|
|
it('creates properly formatted date strings', function () {
|
|
|
|
var testDates = [
|
2016-02-02 10:04:40 +03:00
|
|
|
'2013-12-31T11:28:58.593+02:00',
|
|
|
|
'2014-01-01T01:28:58.593+11:00',
|
|
|
|
'2014-02-20T01:28:58.593-04:00',
|
|
|
|
'2014-03-01T01:28:58.593+00:00'
|
2014-10-10 18:54:07 +04:00
|
|
|
],
|
2016-02-02 10:04:40 +03:00
|
|
|
timezones = 'Europe/Dublin',
|
2014-10-10 18:54:07 +04:00
|
|
|
format = 'MMM Do, YYYY',
|
|
|
|
context = {
|
|
|
|
hash: {
|
|
|
|
format: format
|
2016-02-02 10:04:40 +03:00
|
|
|
},
|
|
|
|
data: {
|
|
|
|
blog: {
|
|
|
|
timezone: 'Europe/Dublin'
|
|
|
|
}
|
2014-10-10 18:54:07 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
testDates.forEach(function (d) {
|
|
|
|
var rendered = helpers.date.call({published_at: d}, context);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
2017-04-04 19:07:35 +03:00
|
|
|
String(rendered).should.equal(moment(d).tz(timezones).format(format));
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates properly formatted time ago date strings', function () {
|
|
|
|
var testDates = [
|
2016-02-02 10:04:40 +03:00
|
|
|
'2013-12-31T23:58:58.593+02:00',
|
|
|
|
'2014-01-01T00:28:58.593+11:00',
|
|
|
|
'2014-11-20T01:28:58.593-04:00',
|
|
|
|
'2014-03-01T01:28:58.593+00:00'
|
2014-10-10 18:54:07 +04:00
|
|
|
],
|
2016-02-02 10:04:40 +03:00
|
|
|
timezones = 'Europe/Dublin',
|
|
|
|
timeNow = moment().tz('Europe/Dublin'),
|
2014-10-10 18:54:07 +04:00
|
|
|
context = {
|
|
|
|
hash: {
|
|
|
|
timeago: true
|
2016-02-02 10:04:40 +03:00
|
|
|
},
|
|
|
|
data: {
|
|
|
|
blog: {
|
|
|
|
timezone: 'Europe/Dublin'
|
|
|
|
}
|
2014-10-10 18:54:07 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
testDates.forEach(function (d) {
|
|
|
|
var rendered = helpers.date.call({published_at: d}, context);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
2017-04-04 19:07:35 +03:00
|
|
|
String(rendered).should.equal(moment(d).tz(timezones).from(timeNow));
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|