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