Skip to content

Commit 1cc967a

Browse files
committed
Tests for parseDateTimeInternal(). The exception test found a bug.
1 parent b2633f1 commit 1cc967a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/jquery-ui-timepicker-addon_spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,50 @@ describe('datetimepicker', function() {
240240

241241
// TODO: Should test the error path, but not sure what throws the error or what the message looks like.
242242
});
243+
244+
describe('parseDateTimeInternal', function() {
245+
it('should return only a date if there is no time component', function() {
246+
var inputDateString = '9/11/2001',
247+
expectedDate = new Date(inputDateString),
248+
result;
249+
250+
result = $.timepicker._util._parseDateTimeInternal('mm/dd/yy', undefined, inputDateString, undefined, undefined);
251+
252+
expect(result.date).toEqual(expectedDate);
253+
expect(result.timeObj).toBeUndefined();
254+
});
255+
256+
it('should return a date and a parsed time if a time is included', function() {
257+
var expectedDateString = '7/4/1976',
258+
expectedParsedTime = {
259+
hour: 1,
260+
minute: 23,
261+
second: 45,
262+
millisec: 678,
263+
microsec: 0
264+
},
265+
inputDateTimeString = expectedDateString + ' '
266+
+ expectedParsedTime.hour + ':'
267+
+ expectedParsedTime.minute + ':'
268+
+ expectedParsedTime.second + '.'
269+
+ expectedParsedTime.millisec,
270+
expectedDate = new Date(expectedDateString),
271+
result;
272+
273+
result = $.timepicker._util._parseDateTimeInternal('mm/dd/yy', 'H:m:s.l', inputDateTimeString, undefined, undefined);
274+
275+
expect(result.date).toEqual(expectedDate);
276+
expect(result.timeObj).toEqual(expectedParsedTime);
277+
});
278+
279+
it('should throw an exception if it cannot parse the time', function() {
280+
var inputDateString = '4/17/2008 11:22:33';
281+
282+
expect(function() {
283+
$.timepicker._util._parseDateTimeInternal('mm/dd/yy', 'q', inputDateString, undefined, undefined);
284+
}).toThrow('Wrong time format');
285+
});
286+
});
243287
});
244288

245289
describe('timepicker functions', function() {

0 commit comments

Comments
 (0)