web/test/jstests/test_utils.js
branchstable
changeset 7363 2293c49b290a
parent 7362 b9813c9d32ac
child 7365 5cd0dbc26882
equal deleted inserted replaced
7362:b9813c9d32ac 7363:2293c49b290a
     1 $(document).ready(function() {
       
     2 
       
     3   module("datetime");
       
     4 
       
     5   test("test full datetime", function() {
       
     6       equals(cw.utils.toISOTimestamp(new Date(1986, 3, 18, 10, 30, 0, 0)),
       
     7 	     '1986-04-18 10:30:00');
       
     8   });
       
     9 
       
    10   test("test only date", function() {
       
    11       equals(cw.utils.toISOTimestamp(new Date(1986, 3, 18)), '1986-04-18 00:00:00');
       
    12   });
       
    13 
       
    14   test("test null", function() {
       
    15       equals(cw.utils.toISOTimestamp(null), null);
       
    16   });
       
    17 
       
    18   module("parsing");
       
    19   test("test basic number parsing", function() {
       
    20       var d = strptime('2008/08/08', '%Y/%m/%d');
       
    21       same(datetuple(d), [2008, 8, 8, 0, 0]);
       
    22       d = strptime('2008/8/8', '%Y/%m/%d');
       
    23       same(datetuple(d), [2008, 8, 8, 0, 0]);
       
    24       d = strptime('8/8/8', '%Y/%m/%d');
       
    25       same(datetuple(d), [8, 8, 8, 0, 0]);
       
    26       d = strptime('0/8/8', '%Y/%m/%d');
       
    27       same(datetuple(d), [0, 8, 8, 0, 0]);
       
    28       d = strptime('-10/8/8', '%Y/%m/%d');
       
    29       same(datetuple(d), [-10, 8, 8, 0, 0]);
       
    30       d = strptime('-35000', '%Y');
       
    31       same(datetuple(d), [-35000, 1, 1, 0, 0]);
       
    32   });
       
    33 
       
    34   test("test custom format parsing", function() {
       
    35       var d = strptime('2008-08-08', '%Y-%m-%d');
       
    36       same(datetuple(d), [2008, 8, 8, 0, 0]);
       
    37       d = strptime('2008 - !  08: 08', '%Y - !  %m: %d');
       
    38       same(datetuple(d), [2008, 8, 8, 0, 0]);
       
    39       d = strptime('2008-08-08 12:14', '%Y-%m-%d %H:%M');
       
    40       same(datetuple(d), [2008, 8, 8, 12, 14]);
       
    41       d = strptime('2008-08-08 1:14', '%Y-%m-%d %H:%M');
       
    42       same(datetuple(d), [2008, 8, 8, 1, 14]);
       
    43       d = strptime('2008-08-08 01:14', '%Y-%m-%d %H:%M');
       
    44       same(datetuple(d), [2008, 8, 8, 1, 14]);
       
    45   });
       
    46 
       
    47   module("sliceList");
       
    48   test("test slicelist", function() {
       
    49       var list = ['a', 'b', 'c', 'd', 'e', 'f'];
       
    50       same(sliceList(list, 2),  ['c', 'd', 'e', 'f']);
       
    51       same(sliceList(list, 2, -2), ['c', 'd']);
       
    52       same(sliceList(list, -3), ['d', 'e', 'f']);
       
    53       same(sliceList(list, 0, -2), ['a', 'b', 'c', 'd']);
       
    54       same(sliceList(list),  list);
       
    55   });
       
    56 
       
    57   module("formContents", {
       
    58     setup: function() {
       
    59       $('#main').append('<form id="test-form"></form>');
       
    60     }
       
    61   });
       
    62   // XXX test fckeditor
       
    63   test("test formContents", function() {
       
    64       $('#test-form').append('<input name="input-text" ' +
       
    65 			     'type="text" value="toto" />');
       
    66       $('#test-form').append('<textarea rows="10" cols="30" '+
       
    67 			     'name="mytextarea">Hello World!</textarea> ');
       
    68       $('#test-form').append('<input name="choice" type="radio" ' +
       
    69 			     'value="yes" />');
       
    70       $('#test-form').append('<input name="choice" type="radio" ' +
       
    71 			     'value="no" checked="checked"/>');
       
    72       $('#test-form').append('<input name="check" type="checkbox" ' +
       
    73 			     'value="yes" />');
       
    74       $('#test-form').append('<input name="check" type="checkbox" ' +
       
    75 			     'value="no" checked="checked"/>');
       
    76       $('#test-form').append('<select id="theselect" name="theselect" ' +
       
    77 			     'multiple="multiple" size="2"></select>');
       
    78       $('#theselect').append('<option selected="selected" ' +
       
    79 			     'value="foo">foo</option>' +
       
    80   			     '<option value="bar">bar</option>');
       
    81       //Append an unchecked radio input : should not be in formContents list
       
    82       $('#test-form').append('<input name="unchecked-choice" type="radio" ' +
       
    83 			     'value="one" />');
       
    84       $('#test-form').append('<input name="unchecked-choice" type="radio" ' +
       
    85 			     'value="two"/>');
       
    86       same(formContents($('#test-form')[0]), [
       
    87 	['input-text', 'mytextarea', 'choice', 'check', 'theselect'],
       
    88 	['toto', 'Hello World!', 'no', 'no', 'foo']
       
    89       ]);
       
    90   });
       
    91 });
       
    92