From 764f752ffb011c3cdafbb398f9c56144210f122d Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Thu, 8 Dec 2016 15:59:38 -0500 Subject: [PATCH 1/3] add unit test for datepicker setDate with string --- test/datepicker-moment-test.js | 14 +++++++++++++- test/datepicker-test.js | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/test/datepicker-moment-test.js b/test/datepicker-moment-test.js index bd1ebdb58..70c2f5c4e 100644 --- a/test/datepicker-moment-test.js +++ b/test/datepicker-moment-test.js @@ -129,7 +129,7 @@ define( function ( require ) { assert.equal( date1, date2, "getValue alias matches getDate" ); } ); - QUnit.test( "should set new date using setDate method", function( assert ) { + QUnit.test( "should set new date using setDate method passing a Date object", function( assert ) { var $datepicker = $( html ).datepicker(); var newDate = new Date( 1987, 2, 31 ); var datepickerDate; @@ -140,6 +140,18 @@ define( function ( require ) { assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" ); } ); + QUnit.test( "should set new date using setDate method passing a ISO string", function( assert ) { + var $datepicker = $( html ).datepicker(); + var dateString = '2015-05-29T04:00:00.000Z'; + var newDate = new Date(dateString); + var datepickerDate; + + $datepicker.datepicker( "setDate", dateString); + datepickerDate = $datepicker.datepicker( "getDate" ); + + assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" ); + } ); + QUnit.test( "should enable/disable datepicker", function( assert ) { var $datepicker = $( html ).datepicker(); var $datepickerInput = $datepicker.find( "input" ); diff --git a/test/datepicker-test.js b/test/datepicker-test.js index 0022e44a0..05c8fb0e5 100644 --- a/test/datepicker-test.js +++ b/test/datepicker-test.js @@ -75,7 +75,7 @@ define(function( require ) { assert.equal( date1, date2, "getValue alias matches getDate" ); } ); - QUnit.test( "should set new date using setDate method", function( assert ) { + QUnit.test( "should set new date using setDate method passing a Date object", function( assert ) { var $datepicker = $( html ).datepicker(); var newDate = new Date( 1987, 2, 31 ); var datepickerDate; @@ -86,6 +86,18 @@ define(function( require ) { assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" ); } ); + QUnit.test( "should set new date using setDate method passing a ISO string", function( assert ) { + var $datepicker = $( html ).datepicker(); + var dateString = '2015-05-29T04:00:00.000Z'; + var newDate = new Date(dateString); + var datepickerDate; + + $datepicker.datepicker( "setDate", dateString); + datepickerDate = $datepicker.datepicker( "getDate" ); + + assert.equal( datepickerDate.getTime(), newDate.getTime(), "setDate method works" ); + } ); + QUnit.test( "should enable/disable datepicker", function( assert ) { var $datepicker = $( html ).datepicker(); var $datepickerInput = $datepicker.find( "input" ); From 8c1b2775af96f3919e9cb9c50d210b2724593dc7 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Thu, 8 Dec 2016 16:02:11 -0500 Subject: [PATCH 2/3] datepicker parseDate was passing the failed parse results to the second parse try. fixed it. --- js/datepicker.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/datepicker.js b/js/datepicker.js index 2c0045009..dfa74d676 100644 --- a/js/datepicker.js +++ b/js/datepicker.js @@ -395,13 +395,13 @@ return (true === md.isValid()) ? md.toDate() : BAD_DATE; }; - tryMomentParseAll = function (d, parseFunc1, parseFunc2) { - var pd = parseFunc1(d); + tryMomentParseAll = function (rawDateString, parseFunc1, parseFunc2) { + var pd = parseFunc1(rawDateString); if (!self.isInvalidDate(pd)) { return pd; } - pd = parseFunc2(pd); + pd = parseFunc2(rawDateString); if (!self.isInvalidDate(pd)) { return pd; } From 36e097f4d57fbcf1a1c878ba1cc97d0666c4c43b Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Thu, 8 Dec 2016 16:38:03 -0500 Subject: [PATCH 3/3] build before testing because test tests dist --- grunt/tasks/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grunt/tasks/test.js b/grunt/tasks/test.js index 43b49cb13..8e23ab146 100644 --- a/grunt/tasks/test.js +++ b/grunt/tasks/test.js @@ -18,7 +18,7 @@ module.exports = function test (grunt) { ['connect:testServer', 'jshint', 'saucelabs-qunit:defaultBrowsers']); grunt.registerTask('travisci', 'Tests to run when in Travis CI environment', - ['browserify:commonjs', 'test', 'dist', 'qunit:dist']); + ['browserify:commonjs', 'dist', 'test', 'qunit:dist']); // if you've already accidentally added your files for commit, this will at least unstage them. If you haven't, this will wipe them out. grunt.registerTask('resetdist', 'resets changes to dist to keep them from being checked in', function resetdist () {