add date separator constant, update tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export default {
|
||||
DEFAULT_SETTING_TIMEOUT: 10000,
|
||||
DEFAULT_SETTING_DATE_SEPARATOR: '-',
|
||||
DEFAULT_SETTING_INTERVAL: 'week',
|
||||
DEFAULT_SETTING_DOCTYPE: 'esqueue',
|
||||
};
|
||||
|
||||
@@ -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,50 +30,58 @@ 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);
|
||||
const separators = ['a', 'B', 'YYYY'];
|
||||
separators.forEach(customSep => {
|
||||
const fn = () => indexTimestamp('minute', customSep);
|
||||
expect(fn).to.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user