add tests for custom date separator

This commit is contained in:
2016-08-22 11:03:06 -07:00
parent 10003e147d
commit 2693c40423

View File

@@ -5,15 +5,15 @@ import indexTimestamp from '../../../lib/helpers/index_timestamp';
const anchor = '2016-04-02T01:02:03.456'; // saturday const anchor = '2016-04-02T01:02:03.456'; // saturday
describe('Index interval', function () { describe('Index timestamp interval', function () {
describe('indexTimestamp construction', function () { describe('construction', function () {
it('should throw given an invalid interval', function () { it('should throw given an invalid interval', function () {
const init = () => indexTimestamp('bananas'); const init = () => indexTimestamp('bananas');
expect(init).to.throwException(/invalid.+interval/i); expect(init).to.throwException(/invalid.+interval/i);
}); });
}); });
describe('indexTimestamp timestamps', function () { describe('timestamps', function () {
let clock; let clock;
beforeEach(function () { beforeEach(function () {
@@ -24,34 +24,53 @@ describe('Index interval', function () {
clock.restore(); clock.restore();
}); });
it('should return the year', function () { describe('formats', function () {
const timestamp = indexTimestamp('year'); it('should return the year', function () {
expect(timestamp).to.equal('2016'); const timestamp = indexTimestamp('year');
expect(timestamp).to.equal('2016');
});
it('should return the year and month', function () {
const timestamp = indexTimestamp('month');
expect(timestamp).to.equal('2016-04');
});
it('should return the year, month, and first day of the week', function () {
const timestamp = indexTimestamp('week');
expect(timestamp).to.equal('2016-03-27');
});
it('should return the year, month, and day of the week', function () {
const timestamp = indexTimestamp('day');
expect(timestamp).to.equal('2016-04-02');
});
it('should return the year, month, day and hour', function () {
const timestamp = indexTimestamp('hour');
expect(timestamp).to.equal('2016-04-02-01');
});
it('should return the year, month, day, hour and minute', function () {
const timestamp = indexTimestamp('minute');
expect(timestamp).to.equal('2016-04-02-01-02');
});
}); });
it('should return the year and month', function () { describe('date separator', function () {
const timestamp = indexTimestamp('month'); it('should be customizable', function () {
expect(timestamp).to.equal('2016-04'); const separators = ['-', '.', '_'];
}); separators.forEach(separator => {
const str = `2016${separator}04${separator}02${separator}01${separator}02`;
const timestamp = indexTimestamp('minute', separator);
expect(timestamp).to.equal(str);
});
});
it('should return the year, month, and first day of the week', function () { it('should throw if a letter is used', function () {
const timestamp = indexTimestamp('week'); const separator = 'a';
expect(timestamp).to.equal('2016-03-27'); const fn = () => indexTimestamp('minute', separator);
}); expect(fn).to.throwException();
});
it('should return the year, month, and day of the week', function () {
const timestamp = indexTimestamp('day');
expect(timestamp).to.equal('2016-04-02');
});
it('should return the year, month, day and hour', function () {
const timestamp = indexTimestamp('hour');
expect(timestamp).to.equal('2016-04-02-01');
});
it('should return the year, month, day, hour and minute', function () {
const timestamp = indexTimestamp('minute');
expect(timestamp).to.equal('2016-04-02-01-02');
}); });
}); });
}); });