From faeb705deed9d3276be41e3295f50e89556421b0 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 22 Aug 2016 11:09:16 -0700 Subject: [PATCH] add date separator constant, update tests --- src/constants/default_settings.js | 1 + test/src/helpers/index_timestamp.js | 35 +++++++++++++++++++---------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/constants/default_settings.js b/src/constants/default_settings.js index 2c8205c..af4caf3 100644 --- a/src/constants/default_settings.js +++ b/src/constants/default_settings.js @@ -1,5 +1,6 @@ export default { DEFAULT_SETTING_TIMEOUT: 10000, + DEFAULT_SETTING_DATE_SEPARATOR: '-', DEFAULT_SETTING_INTERVAL: 'week', DEFAULT_SETTING_DOCTYPE: 'esqueue', }; diff --git a/test/src/helpers/index_timestamp.js b/test/src/helpers/index_timestamp.js index cb4bce1..251afbc 100644 --- a/test/src/helpers/index_timestamp.js +++ b/test/src/helpers/index_timestamp.js @@ -1,6 +1,7 @@ import expect from 'expect.js'; import sinon from 'sinon'; import moment from 'moment'; +import constants from '../../../lib/constants'; import indexTimestamp from '../../../lib/helpers/index_timestamp'; const anchor = '2016-04-02T01:02:03.456'; // saturday @@ -15,8 +16,10 @@ describe('Index timestamp interval', function () { describe('timestamps', function () { let clock; + let separator; beforeEach(function () { + separator = constants.DEFAULT_SETTING_DATE_SEPARATOR; clock = sinon.useFakeTimers(moment(anchor).valueOf()); }); @@ -27,49 +30,57 @@ describe('Index timestamp interval', function () { describe('formats', function () { it('should return the year', function () { const timestamp = indexTimestamp('year'); - expect(timestamp).to.equal('2016'); + const str = `2016`; + expect(timestamp).to.equal(str); }); it('should return the year and month', function () { const timestamp = indexTimestamp('month'); - expect(timestamp).to.equal('2016-04'); + const str = `2016${separator}04`; + expect(timestamp).to.equal(str); }); it('should return the year, month, and first day of the week', function () { const timestamp = indexTimestamp('week'); - expect(timestamp).to.equal('2016-03-27'); + const str = `2016${separator}03${separator}27`; + expect(timestamp).to.equal(str); }); it('should return the year, month, and day of the week', function () { const timestamp = indexTimestamp('day'); - expect(timestamp).to.equal('2016-04-02'); + const str = `2016${separator}04${separator}02`; + expect(timestamp).to.equal(str); }); it('should return the year, month, day and hour', function () { const timestamp = indexTimestamp('hour'); - expect(timestamp).to.equal('2016-04-02-01'); + const str = `2016${separator}04${separator}02${separator}01`; + expect(timestamp).to.equal(str); }); it('should return the year, month, day, hour and minute', function () { const timestamp = indexTimestamp('minute'); - expect(timestamp).to.equal('2016-04-02-01-02'); + const str = `2016${separator}04${separator}02${separator}01${separator}02`; + expect(timestamp).to.equal(str); }); }); describe('date separator', function () { it('should be customizable', function () { const separators = ['-', '.', '_']; - separators.forEach(separator => { - const str = `2016${separator}04${separator}02${separator}01${separator}02`; - const timestamp = indexTimestamp('minute', separator); + separators.forEach(customSep => { + const str = `2016${customSep}04${customSep}02${customSep}01${customSep}02`; + const timestamp = indexTimestamp('minute', customSep); expect(timestamp).to.equal(str); }); }); it('should throw if a letter is used', function () { - const separator = 'a'; - const fn = () => indexTimestamp('minute', separator); - expect(fn).to.throwException(); + const separators = ['a', 'B', 'YYYY']; + separators.forEach(customSep => { + const fn = () => indexTimestamp('minute', customSep); + expect(fn).to.throwException(); + }); }); }); });