web/test/jstests/test_utils.js
author Rémi Cardona <remi.cardona@logilab.fr>
Wed, 20 May 2015 17:04:43 +0200
changeset 10428 c961a301a90b
parent 10427 7677c0401864
child 10429 98ea2b865210
permissions -rw-r--r--
[devtools] qunit: stop using global variables test -> QUnit.test module -> QUnit.module Related to #5533333.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
$(document).ready(function() {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
10428
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
     3
  QUnit.module("datetime");
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
10428
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
     5
  QUnit.test("test full datetime", function() {
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
     6
      equal(cw.utils.toISOTimestamp(new Date(1986, 3, 18, 10, 30, 0, 0)),
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
	     '1986-04-18 10:30:00');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
  });
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
10428
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
    10
  QUnit.test("test only date", function() {
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    11
      equal(cw.utils.toISOTimestamp(new Date(1986, 3, 18)), '1986-04-18 00:00:00');
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
  });
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
10428
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
    14
  QUnit.test("test null", function() {
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    15
      equal(cw.utils.toISOTimestamp(null), null);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
  });
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
10428
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
    18
  QUnit.module("parsing");
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
    19
  QUnit.test("test basic number parsing", function() {
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
      var d = strptime('2008/08/08', '%Y/%m/%d');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    21
      deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
      d = strptime('2008/8/8', '%Y/%m/%d');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    23
      deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
      d = strptime('8/8/8', '%Y/%m/%d');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    25
      deepEqual(datetuple(d), [8, 8, 8, 0, 0]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
      d = strptime('0/8/8', '%Y/%m/%d');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    27
      deepEqual(datetuple(d), [0, 8, 8, 0, 0]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
      d = strptime('-10/8/8', '%Y/%m/%d');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    29
      deepEqual(datetuple(d), [-10, 8, 8, 0, 0]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
      d = strptime('-35000', '%Y');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    31
      deepEqual(datetuple(d), [-35000, 1, 1, 0, 0]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
  });
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
10428
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
    34
  QUnit.test("test custom format parsing", function() {
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
      var d = strptime('2008-08-08', '%Y-%m-%d');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    36
      deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
      d = strptime('2008 - !  08: 08', '%Y - !  %m: %d');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    38
      deepEqual(datetuple(d), [2008, 8, 8, 0, 0]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
      d = strptime('2008-08-08 12:14', '%Y-%m-%d %H:%M');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    40
      deepEqual(datetuple(d), [2008, 8, 8, 12, 14]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
      d = strptime('2008-08-08 1:14', '%Y-%m-%d %H:%M');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    42
      deepEqual(datetuple(d), [2008, 8, 8, 1, 14]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
      d = strptime('2008-08-08 01:14', '%Y-%m-%d %H:%M');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    44
      deepEqual(datetuple(d), [2008, 8, 8, 1, 14]);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
  });
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
10428
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
    47
  QUnit.module("sliceList");
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
    48
  QUnit.test("test slicelist", function() {
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
      var list = ['a', 'b', 'c', 'd', 'e', 'f'];
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    50
      deepEqual(cw.utils.sliceList(list, 2),  ['c', 'd', 'e', 'f']);
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    51
      deepEqual(cw.utils.sliceList(list, 2, -2), ['c', 'd']);
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    52
      deepEqual(cw.utils.sliceList(list, -3), ['d', 'e', 'f']);
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    53
      deepEqual(cw.utils.sliceList(list, 0, -2), ['a', 'b', 'c', 'd']);
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    54
      deepEqual(cw.utils.sliceList(list),  list);
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
  });
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    56
10428
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
    57
  QUnit.module("formContents", {
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    58
    setup: function() {
10427
7677c0401864 [devtools] qunit: update to 1.18.0 (closes #5533333)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10426
diff changeset
    59
      $('#qunit-fixture').append('<form id="test-form"></form>');
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    61
  });
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
  // XXX test fckeditor
10428
c961a301a90b [devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10427
diff changeset
    63
  QUnit.test("test formContents", function() {
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
      $('#test-form').append('<input name="input-text" ' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    65
			     'type="text" value="toto" />');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    66
      $('#test-form').append('<textarea rows="10" cols="30" '+
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    67
			     'name="mytextarea">Hello World!</textarea> ');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    68
      $('#test-form').append('<input name="choice" type="radio" ' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    69
			     'value="yes" />');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    70
      $('#test-form').append('<input name="choice" type="radio" ' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    71
			     'value="no" checked="checked"/>');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    72
      $('#test-form').append('<input name="check" type="checkbox" ' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
			     'value="yes" />');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    74
      $('#test-form').append('<input name="check" type="checkbox" ' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
			     'value="no" checked="checked"/>');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
      $('#test-form').append('<select id="theselect" name="theselect" ' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
			     'multiple="multiple" size="2"></select>');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
      $('#theselect').append('<option selected="selected" ' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    79
			     'value="foo">foo</option>' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
  			     '<option value="bar">bar</option>');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    81
      //Append an unchecked radio input : should not be in formContents list
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
      $('#test-form').append('<input name="unchecked-choice" type="radio" ' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    83
			     'value="one" />');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    84
      $('#test-form').append('<input name="unchecked-choice" type="radio" ' +
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    85
			     'value="two"/>');
10426
ce213d6858f1 [devtools] qunit: stop using deprecated assert functions
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9259
diff changeset
    86
      deepEqual(cw.utils.formContents($('#test-form')[0]), [
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    87
	['input-text', 'mytextarea', 'choice', 'check', 'theselect'],
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    88
	['toto', 'Hello World!', 'no', 'no', 'foo']
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    89
      ]);
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    90
  });
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    91
});
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    92