From 9e2d158332ae070a2c905bfa66f4db976d4b09d1 Mon Sep 17 00:00:00 2001 From: Dmitry Filimonov Date: Mon, 21 Dec 2015 09:16:22 +0300 Subject: [PATCH] added more tests --- tasks/website.babel.js | 2 ++ test/array-utils.coffee | 9 +++++++++ test/moment-iterator.coffee | 23 +++++++++++++++++++++++ test/period.coffee | 6 ++++++ 4 files changed, 40 insertions(+) create mode 100644 test/array-utils.coffee create mode 100644 test/moment-iterator.coffee create mode 100644 test/period.coffee diff --git a/tasks/website.babel.js b/tasks/website.babel.js index 28e9895..c278c77 100644 --- a/tasks/website.babel.js +++ b/tasks/website.babel.js @@ -69,12 +69,14 @@ gulp.task('serve', ['html', 'styles', 'scripts'], () => { gulp.watch([ '{src,website}/scripts/**/*.coffee', + 'test/**/*.coffee', 'src/templates/**/*.html', 'website/**/*.html', '**/*.md' ]).on('change', reload); gulp.watch('{src,website}/styles/**/*.scss', ['styles']); + gulp.watch('test/**/*.coffee', ['scripts']); gulp.watch('{src,website}/scripts/**/*.coffee', ['scripts']); gulp.watch('src/templates/**/*.html', ['scripts']); gulp.watch('website/**/*.html', ['html']); diff --git a/test/array-utils.coffee b/test/array-utils.coffee new file mode 100644 index 0000000..8e73843 --- /dev/null +++ b/test/array-utils.coffee @@ -0,0 +1,9 @@ +describe 'ArrayUtils', -> + ArrayUtils = $.fn.daterangepicker.ArrayUtils + describe '##rotateArray()', -> + it 'should work', () -> + assert.sameMembers(ArrayUtils.rotateArray([1, 2, 3, 4], 2), [3, 4, 1, 2]) + + describe '##uniqArray()', -> + it 'should work', () -> + assert.sameMembers(ArrayUtils.uniqArray([1, 2, 3, 1, 2, 4]), [1, 2, 3, 4]) diff --git a/test/moment-iterator.coffee b/test/moment-iterator.coffee new file mode 100644 index 0000000..4ab57dd --- /dev/null +++ b/test/moment-iterator.coffee @@ -0,0 +1,23 @@ +describe 'MomentIterator', -> + MomentIterator = $.fn.daterangepicker.MomentIterator + fmt = 'YYYY-MM-DD' + describe '#next()', -> + it 'should work', () -> + iter = new MomentIterator(moment.utc([2015, 1, 1]), 'month') + assert.equal(iter.next().format(fmt), '2015-02-01') + assert.equal(iter.next().format(fmt), '2015-03-01') + + describe '##array()', -> + it 'should work', () -> + arr = MomentIterator.array(moment.utc([2015, 1, 1]), 6, 'month') + + expectations = [ + '2015-02-01', + '2015-03-01', + '2015-04-01', + '2015-05-01', + '2015-06-01', + '2015-07-01' + ] + + assert.sameMembers(arr.map((x) -> x.format(fmt)), expectations) diff --git a/test/period.coffee b/test/period.coffee new file mode 100644 index 0000000..5533f55 --- /dev/null +++ b/test/period.coffee @@ -0,0 +1,6 @@ +describe 'Period', -> + Period = $.fn.daterangepicker.Period + describe '##extendObservable()', -> + it 'should work', () -> + observable = Period.extendObservable(ko.observable('quarter')) + assert.equal(observable.format(), Period.format('quarter'))