summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/ajax/scriptaculous/test/unit/unit_test.html
blob: 39c078959ca93a6de59b084c1c4ecbb0a7016dd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>script.aculo.us Unit test file</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <script src="../../lib/prototype.js" type="text/javascript"></script>
  <script src="../../src/scriptaculous.js" type="text/javascript"></script>
  <script src="../../src/unittest.js" type="text/javascript"></script>
  <link rel="stylesheet" href="../test.css" type="text/css" />
  <style type="text/css" media="screen">
  /* <![CDATA[ */
    #testcss1 { font-size:11px; color: #f00; }
    #testcss2 { font-size:12px; color: #0f0; display: none; }
  /* ]]> */
  </style>
</head>
<body>
<h1>script.aculo.us Unit test file</h1>
<p>
  This is a preliminary version mostly for testing the unittest library.
</p>

<!-- Log output -->
<div id="testlog"> </div>

<!-- Test elements follow -->
<div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>

<div id="test_2"> <span> </span> 



<div><div></div> </div><span> </span>
</div>

<ul id="tlist"><li id="tlist_1">x1</li><li id="tlist_2">x2</li></ul>
<ul id="tlist2"><li class="a" id="tlist2_1">x1</li><li id="tlist2_2">x2</li></ul>

<div id="testmoveby" style="background-color:#333;width:100px;">XXXX</div>

<div id="testcss1">testcss1<span id="testcss1_span" style="display:none;">blah</span></div><div id="testcss2">testcss1</div>

<!-- Tests follow -->
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[

  var testObj = {
    isNice: function(){
      return true;
    },
    isBroken: function(){
      return false;
    }
  }

  new Test.Unit.Runner({
    
    testAssertEqual: function() { with(this) {
      assertEqual(0, 0);
      assertEqual(0, 0, "test");
      
      assertEqual(0,'0');
      assertEqual(65.0, 65);
      
      assertEqual("a", "a");
      assertEqual("a", "a", "test");
      
      assertNotEqual(0, 1);
      assertNotEqual("a","b");
      assertNotEqual({},{});
      assertNotEqual([],[]);
      assertNotEqual([],{});
    }},
    
    testAssertRespondsTo: function() { with(this) {
      assertRespondsTo('isNice', testObj);
      assertRespondsTo('isBroken', testObj);
    }},
    
    testAssertIndentical: function() { with(this) { 
      assertIdentical(0, 0); 
      assertIdentical(0, 0, "test"); 
      assertIdentical(1, 1); 
      assertIdentical('a', 'a'); 
      assertIdentical('a', 'a', "test"); 
      assertIdentical('', ''); 
      assertIdentical(undefined, undefined); 
      assertIdentical(null, null); 
      assertIdentical(true, true); 
      assertIdentical(false, false); 
      
      var obj = {a:'b'};
      assertIdentical(obj, obj);
      
      assertNotIdentical({1:2,3:4},{1:2,3:4});
      
      assertIdentical(1, 1.0); // both are typeof == 'number'
      
      assertNotIdentical(1, '1');
      assertNotIdentical(1, '1.0');
    }},
    
    testAssertMatch: function() { with(this) {
      assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
      assertMatch(/Fuc/, 'Thomas Fuchs');
      assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
      assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
           assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
      assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
      
    }},
    
    testAssertInstanceOf: function() { with(this) {
      assertInstanceOf(Effect.Opacity, new Effect.Opacity('testcss1',{sync:true}));
      assertNotInstanceOf(String, new Effect.Opacity('testcss1',{sync:true}));
      
      // note: fails with firefox 1.0.X (bug, fixed in Deer Park)
      assertNotInstanceOf(Effect.Parallel, new Effect.Opacity('testcss1',{sync:true}), "(note: fails with firefox 1.0.X, fixed in Deer Park)");   
    }},
    
    testAssertReturns: function() { with(this) {
      
      assertReturnsTrue('isNice',testObj);
      assertReturnsFalse('isBroken',testObj);
      
      assertReturnsTrue('nice',testObj);
      assertReturnsFalse('broken',testObj);
      
    }},
  
    testAssertVisible: function() { with(this) {
      assertVisible('testcss1');
      assertNotVisible('testcss1_span');
      assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
      
      Element.hide('testcss1');
      assertNotVisible('testcss1');
      assertNotVisible('testcss1_span');
      Element.show('testcss1');
      assertVisible('testcss1');
      assertNotVisible('testcss1_span');
      
      Element.show('testcss1_span');
      assertVisible('testcss1_span');
      Element.hide('testcss1');
      assertNotVisible('testcss1_span'); // hidden by parent
    }}
      
  }, "testlog");
// ]]>
</script>
</body>
</html>