2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
// Stuff we are testing
|
|
|
|
const helpers = require('../../../core/frontend/helpers');
|
|
|
|
|
|
|
|
const moment = require('moment-timezone');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{date}} helper', function () {
|
|
|
|
it('creates properly formatted date strings', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const testDates = [
|
|
|
|
'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'
|
|
|
|
];
|
|
|
|
|
|
|
|
const timezones = 'Europe/Dublin';
|
|
|
|
const format = 'MMM Do, YYYY';
|
|
|
|
|
|
|
|
const context = {
|
|
|
|
hash: {
|
|
|
|
format: format
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
site: {
|
|
|
|
timezone: 'Europe/Dublin'
|
2014-10-10 18:54:07 +04:00
|
|
|
}
|
2020-04-29 18:44:27 +03:00
|
|
|
}
|
|
|
|
};
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
testDates.forEach(function (d) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.date.call({published_at: d}, context);
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
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 () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const testDates = [
|
|
|
|
'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'
|
|
|
|
];
|
|
|
|
|
|
|
|
const timezones = 'Europe/Dublin';
|
|
|
|
const timeNow = moment().tz('Europe/Dublin');
|
|
|
|
|
|
|
|
const context = {
|
|
|
|
hash: {
|
|
|
|
timeago: true
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
site: {
|
|
|
|
timezone: 'Europe/Dublin'
|
2014-10-10 18:54:07 +04:00
|
|
|
}
|
2020-04-29 18:44:27 +03:00
|
|
|
}
|
|
|
|
};
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
testDates.forEach(function (d) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.date.call({published_at: d}, context);
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|