diff -r b9813c9d32ac -r 2293c49b290a testfunc/test/jstests/test_utils.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testfunc/test/jstests/test_utils.js Wed May 11 12:04:56 2011 +0200 @@ -0,0 +1,92 @@ +$(document).ready(function() { + + module("datetime"); + + test("test full datetime", function() { + equals(cw.utils.toISOTimestamp(new Date(1986, 3, 18, 10, 30, 0, 0)), + '1986-04-18 10:30:00'); + }); + + test("test only date", function() { + equals(cw.utils.toISOTimestamp(new Date(1986, 3, 18)), '1986-04-18 00:00:00'); + }); + + test("test null", function() { + equals(cw.utils.toISOTimestamp(null), null); + }); + + module("parsing"); + test("test basic number parsing", function() { + var d = strptime('2008/08/08', '%Y/%m/%d'); + same(datetuple(d), [2008, 8, 8, 0, 0]); + d = strptime('2008/8/8', '%Y/%m/%d'); + same(datetuple(d), [2008, 8, 8, 0, 0]); + d = strptime('8/8/8', '%Y/%m/%d'); + same(datetuple(d), [8, 8, 8, 0, 0]); + d = strptime('0/8/8', '%Y/%m/%d'); + same(datetuple(d), [0, 8, 8, 0, 0]); + d = strptime('-10/8/8', '%Y/%m/%d'); + same(datetuple(d), [-10, 8, 8, 0, 0]); + d = strptime('-35000', '%Y'); + same(datetuple(d), [-35000, 1, 1, 0, 0]); + }); + + test("test custom format parsing", function() { + var d = strptime('2008-08-08', '%Y-%m-%d'); + same(datetuple(d), [2008, 8, 8, 0, 0]); + d = strptime('2008 - ! 08: 08', '%Y - ! %m: %d'); + same(datetuple(d), [2008, 8, 8, 0, 0]); + d = strptime('2008-08-08 12:14', '%Y-%m-%d %H:%M'); + same(datetuple(d), [2008, 8, 8, 12, 14]); + d = strptime('2008-08-08 1:14', '%Y-%m-%d %H:%M'); + same(datetuple(d), [2008, 8, 8, 1, 14]); + d = strptime('2008-08-08 01:14', '%Y-%m-%d %H:%M'); + same(datetuple(d), [2008, 8, 8, 1, 14]); + }); + + module("sliceList"); + test("test slicelist", function() { + var list = ['a', 'b', 'c', 'd', 'e', 'f']; + same(sliceList(list, 2), ['c', 'd', 'e', 'f']); + same(sliceList(list, 2, -2), ['c', 'd']); + same(sliceList(list, -3), ['d', 'e', 'f']); + same(sliceList(list, 0, -2), ['a', 'b', 'c', 'd']); + same(sliceList(list), list); + }); + + module("formContents", { + setup: function() { + $('#main').append('
'); + } + }); + // XXX test fckeditor + test("test formContents", function() { + $('#test-form').append(''); + $('#test-form').append(' '); + $('#test-form').append(''); + $('#test-form').append(''); + $('#test-form').append(''); + $('#test-form').append(''); + $('#test-form').append(''); + $('#theselect').append('' + + ''); + //Append an unchecked radio input : should not be in formContents list + $('#test-form').append(''); + $('#test-form').append(''); + same(formContents($('#test-form')[0]), [ + ['input-text', 'mytextarea', 'choice', 'check', 'theselect'], + ['toto', 'Hello World!', 'no', 'no', 'foo'] + ]); + }); +}); +