web/test/jstests/test_utils.js
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Fri, 25 Jul 2014 17:10:05 +0200
changeset 10433 523a7f098066
parent 10429 98ea2b865210
permissions -rw-r--r--
[js] lint : make it explicit that typeof is an operator, not a function. Also, use === / !== except for null / undefined comparison
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
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
     5
  QUnit.test("test full datetime", function (assert) {
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
     6
      assert.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
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    10
  QUnit.test("test only date", function (assert) {
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    11
      assert.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
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    14
  QUnit.test("test null", function (assert) {
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    15
      assert.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");
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    19
  QUnit.test("test basic number parsing", function (assert) {
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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    21
      assert.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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    23
      assert.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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    25
      assert.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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    27
      assert.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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    29
      assert.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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    31
      assert.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
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    34
  QUnit.test("test custom format parsing", function (assert) {
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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    36
      assert.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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    38
      assert.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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    40
      assert.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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    42
      assert.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');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    44
      assert.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");
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    48
  QUnit.test("test slicelist", function (assert) {
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'];
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    50
      assert.deepEqual(cw.utils.sliceList(list, 2),  ['c', 'd', 'e', 'f']);
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    51
      assert.deepEqual(cw.utils.sliceList(list, 2, -2), ['c', 'd']);
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    52
      assert.deepEqual(cw.utils.sliceList(list, -3), ['d', 'e', 'f']);
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    53
      assert.deepEqual(cw.utils.sliceList(list, 0, -2), ['a', 'b', 'c', 'd']);
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    54
      assert.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
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    63
  QUnit.test("test formContents", function (assert) {
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"/>');
10429
98ea2b865210 [devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10428
diff changeset
    86
      assert.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