| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|---|
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|---|
| 4 | <head> |
|---|
| 5 | <title>script.aculo.us Unit test file</title> |
|---|
| 6 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
|---|
| 7 | <script src="../../lib/prototype.js" type="text/javascript"></script> |
|---|
| 8 | <script src="../../src/scriptaculous.js" type="text/javascript"></script> |
|---|
| 9 | <script src="../../src/unittest.js" type="text/javascript"></script> |
|---|
| 10 | <link rel="stylesheet" href="../test.css" type="text/css" /> |
|---|
| 11 | <style type="text/css" media="screen"> |
|---|
| 12 | /* <![CDATA[ */ |
|---|
| 13 | #testcss1 { font-size:11px; color: #f00; } |
|---|
| 14 | #testcss2 { font-size:12px; color: #0f0; display: none; } |
|---|
| 15 | /* ]]> */ |
|---|
| 16 | </style> |
|---|
| 17 | </head> |
|---|
| 18 | <body> |
|---|
| 19 | <h1>script.aculo.us Unit test file</h1> |
|---|
| 20 | <p> |
|---|
| 21 | This is a preliminary version mostly for testing the unittest library. |
|---|
| 22 | </p> |
|---|
| 23 | |
|---|
| 24 | <!-- Log output --> |
|---|
| 25 | <div id="testlog"> </div> |
|---|
| 26 | |
|---|
| 27 | <!-- Test elements follow --> |
|---|
| 28 | <div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div> |
|---|
| 29 | |
|---|
| 30 | <div id="test_2"> <span> </span> |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | <div><div></div> </div><span> </span> |
|---|
| 35 | </div> |
|---|
| 36 | |
|---|
| 37 | <ul id="tlist"><li id="tlist_1">x1</li><li id="tlist_2">x2</li></ul> |
|---|
| 38 | <ul id="tlist2"><li class="a" id="tlist2_1">x1</li><li id="tlist2_2">x2</li></ul> |
|---|
| 39 | |
|---|
| 40 | <div id="testmoveby" style="background-color:#333;width:100px;">XXXX</div> |
|---|
| 41 | |
|---|
| 42 | <div id="testcss1">testcss1<span id="testcss1_span" style="display:none;">blah</span></div><div id="testcss2">testcss1</div> |
|---|
| 43 | |
|---|
| 44 | <!-- Tests follow --> |
|---|
| 45 | <script type="text/javascript" language="javascript" charset="utf-8"> |
|---|
| 46 | // <![CDATA[ |
|---|
| 47 | |
|---|
| 48 | var testObj = { |
|---|
| 49 | isNice: function(){ |
|---|
| 50 | return true; |
|---|
| 51 | }, |
|---|
| 52 | isBroken: function(){ |
|---|
| 53 | return false; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | new Test.Unit.Runner({ |
|---|
| 58 | |
|---|
| 59 | testAssertEqual: function() { with(this) { |
|---|
| 60 | assertEqual(0, 0); |
|---|
| 61 | assertEqual(0, 0, "test"); |
|---|
| 62 | |
|---|
| 63 | assertEqual(0,'0'); |
|---|
| 64 | assertEqual(65.0, 65); |
|---|
| 65 | |
|---|
| 66 | assertEqual("a", "a"); |
|---|
| 67 | assertEqual("a", "a", "test"); |
|---|
| 68 | |
|---|
| 69 | assertNotEqual(0, 1); |
|---|
| 70 | assertNotEqual("a","b"); |
|---|
| 71 | assertNotEqual({},{}); |
|---|
| 72 | assertNotEqual([],[]); |
|---|
| 73 | assertNotEqual([],{}); |
|---|
| 74 | }}, |
|---|
| 75 | |
|---|
| 76 | testAssertRespondsTo: function() { with(this) { |
|---|
| 77 | assertRespondsTo('isNice', testObj); |
|---|
| 78 | assertRespondsTo('isBroken', testObj); |
|---|
| 79 | }}, |
|---|
| 80 | |
|---|
| 81 | testAssertIndentical: function() { with(this) { |
|---|
| 82 | assertIdentical(0, 0); |
|---|
| 83 | assertIdentical(0, 0, "test"); |
|---|
| 84 | assertIdentical(1, 1); |
|---|
| 85 | assertIdentical('a', 'a'); |
|---|
| 86 | assertIdentical('a', 'a', "test"); |
|---|
| 87 | assertIdentical('', ''); |
|---|
| 88 | assertIdentical(undefined, undefined); |
|---|
| 89 | assertIdentical(null, null); |
|---|
| 90 | assertIdentical(true, true); |
|---|
| 91 | assertIdentical(false, false); |
|---|
| 92 | |
|---|
| 93 | var obj = {a:'b'}; |
|---|
| 94 | assertIdentical(obj, obj); |
|---|
| 95 | |
|---|
| 96 | assertNotIdentical({1:2,3:4},{1:2,3:4}); |
|---|
| 97 | |
|---|
| 98 | assertIdentical(1, 1.0); // both are typeof == 'number' |
|---|
| 99 | |
|---|
| 100 | assertNotIdentical(1, '1'); |
|---|
| 101 | assertNotIdentical(1, '1.0'); |
|---|
| 102 | }}, |
|---|
| 103 | |
|---|
| 104 | testAssertMatch: function() { with(this) { |
|---|
| 105 | assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg'); |
|---|
| 106 | assertMatch(/Fuc/, 'Thomas Fuchs'); |
|---|
| 107 | assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95'); |
|---|
| 108 | assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330'); |
|---|
| 109 | 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'); |
|---|
| 110 | 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'); |
|---|
| 111 | |
|---|
| 112 | }}, |
|---|
| 113 | |
|---|
| 114 | testAssertInstanceOf: function() { with(this) { |
|---|
| 115 | assertInstanceOf(Effect.Opacity, new Effect.Opacity('testcss1',{sync:true})); |
|---|
| 116 | assertNotInstanceOf(String, new Effect.Opacity('testcss1',{sync:true})); |
|---|
| 117 | |
|---|
| 118 | // note: fails with firefox 1.0.X (bug, fixed in Deer Park) |
|---|
| 119 | assertNotInstanceOf(Effect.Parallel, new Effect.Opacity('testcss1',{sync:true}), "(note: fails with firefox 1.0.X, fixed in Deer Park)"); |
|---|
| 120 | }}, |
|---|
| 121 | |
|---|
| 122 | testAssertReturns: function() { with(this) { |
|---|
| 123 | |
|---|
| 124 | assertReturnsTrue('isNice',testObj); |
|---|
| 125 | assertReturnsFalse('isBroken',testObj); |
|---|
| 126 | |
|---|
| 127 | assertReturnsTrue('nice',testObj); |
|---|
| 128 | assertReturnsFalse('broken',testObj); |
|---|
| 129 | |
|---|
| 130 | }}, |
|---|
| 131 | |
|---|
| 132 | testAssertVisible: function() { with(this) { |
|---|
| 133 | assertVisible('testcss1'); |
|---|
| 134 | assertNotVisible('testcss1_span'); |
|---|
| 135 | assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari."); |
|---|
| 136 | |
|---|
| 137 | Element.hide('testcss1'); |
|---|
| 138 | assertNotVisible('testcss1'); |
|---|
| 139 | assertNotVisible('testcss1_span'); |
|---|
| 140 | Element.show('testcss1'); |
|---|
| 141 | assertVisible('testcss1'); |
|---|
| 142 | assertNotVisible('testcss1_span'); |
|---|
| 143 | |
|---|
| 144 | Element.show('testcss1_span'); |
|---|
| 145 | assertVisible('testcss1_span'); |
|---|
| 146 | Element.hide('testcss1'); |
|---|
| 147 | assertNotVisible('testcss1_span'); // hidden by parent |
|---|
| 148 | }} |
|---|
| 149 | |
|---|
| 150 | }, "testlog"); |
|---|
| 151 | // ]]> |
|---|
| 152 | </script> |
|---|
| 153 | </body> |
|---|
| 154 | </html> |
|---|