Skip to content

Commit f589d84

Browse files
committed
Tests for splitDateTime, except for error paths.
1 parent ff99363 commit f589d84

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/jquery-ui-timepicker-addon_spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,51 @@ describe('datetimepicker', function() {
195195
expect(timepicker.timezone_select.val()).toBe(timezoneOffset);
196196
});
197197
});
198+
199+
describe('splitDateTime', function() {
200+
var expectedDateString = '3/6/1967',
201+
expectedTimeString = '07:32';
202+
203+
it('splits a date and time into its parts using the default separator', function() {
204+
var inputDateTimeString = expectedDateString + $.timepicker._defaults.separator + expectedTimeString,
205+
result;
206+
207+
result = $.timepicker._util._splitDateTime('', inputDateTimeString, {}, {});
208+
209+
expect(result).toEqual([expectedDateString, expectedTimeString]);
210+
});
211+
212+
it('splits a date and time into its parts using a supplied separator', function() {
213+
var separator = '-',
214+
inputDateTimeString = expectedDateString + separator + expectedTimeString,
215+
result;
216+
217+
result = $.timepicker._util._splitDateTime('', inputDateTimeString, {}, {separator: separator});
218+
219+
expect(result).toEqual([expectedDateString, expectedTimeString]);
220+
});
221+
222+
it('splits a date and time into its parts when there are multiple separators in the time format', function() {
223+
var timeFormat = 'hh mm tt',
224+
separator = ' ',
225+
alternateTimeString = '07 32 am',
226+
inputDateTimeString = expectedDateString + separator + alternateTimeString,
227+
timeSettings = {separator: separator, timeFormat: timeFormat},
228+
result;
229+
230+
result = $.timepicker._util._splitDateTime('', inputDateTimeString, {}, timeSettings);
231+
232+
expect(result).toEqual([expectedDateString, alternateTimeString]);
233+
});
234+
235+
it('splits only a date into itself', function() {
236+
var result = $.timepicker._util._splitDateTime('', expectedDateString, {}, {});
237+
238+
expect(result).toEqual([expectedDateString, '']);
239+
});
240+
241+
// TODO: Should test the error path, but not sure what throws the error or what the message looks like.
242+
});
198243
});
199244

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

0 commit comments

Comments
 (0)