Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
michael@0 | 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
michael@0 | 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
michael@0 | 4 | <head> |
michael@0 | 5 | <title>script.aculo.us Unit test file</title> |
michael@0 | 6 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
michael@0 | 7 | <script src="../../lib/prototype.js" type="text/javascript"></script> |
michael@0 | 8 | <script src="../../src/scriptaculous.js" type="text/javascript"></script> |
michael@0 | 9 | <script src="../../src/unittest.js" type="text/javascript"></script> |
michael@0 | 10 | <link rel="stylesheet" href="../test.css" type="text/css" /> |
michael@0 | 11 | <style type="text/css" media="screen"> |
michael@0 | 12 | #rotfl { |
michael@0 | 13 | color: red; |
michael@0 | 14 | font-family: serif; |
michael@0 | 15 | font-style: italic; |
michael@0 | 16 | font-size: 40px; |
michael@0 | 17 | background: #fed; |
michael@0 | 18 | padding: 1em; |
michael@0 | 19 | width: 400px; |
michael@0 | 20 | } |
michael@0 | 21 | .final { |
michael@0 | 22 | color: #fff; |
michael@0 | 23 | font-style: italic; |
michael@0 | 24 | font-size: 20px; |
michael@0 | 25 | background: #000; |
michael@0 | 26 | opacity: 0.5; |
michael@0 | 27 | } |
michael@0 | 28 | </style> |
michael@0 | 29 | </head> |
michael@0 | 30 | <body> |
michael@0 | 31 | <h1>script.aculo.us Unit test file</h1> |
michael@0 | 32 | <p> |
michael@0 | 33 | Tests for effects.js |
michael@0 | 34 | </p> |
michael@0 | 35 | |
michael@0 | 36 | <!-- generated elements go in here --> |
michael@0 | 37 | <div id="sandbox"></div> |
michael@0 | 38 | |
michael@0 | 39 | <!-- Log output --> |
michael@0 | 40 | <div id="testlog"> </div> |
michael@0 | 41 | |
michael@0 | 42 | <div class="morphing blub" style="font-size:25px;color:#f00">Well</div> |
michael@0 | 43 | <div class="morphing">You know</div> |
michael@0 | 44 | <div id="blah" style="border:1px solid black;width:100px">Whoo-hoo!</div> |
michael@0 | 45 | |
michael@0 | 46 | <div id="error_message">ERROR MESSAGE</div> |
michael@0 | 47 | <div id="error_message_2">SECOND ERROR MESSAGE</div> |
michael@0 | 48 | <div id="error_message_3" style="border:1px solid red; width:100px; color: #f00">THIRD ERROR MESSAGE</div> |
michael@0 | 49 | |
michael@0 | 50 | <ul class="error-list" id="error_test_ul"> |
michael@0 | 51 | <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</li> |
michael@0 | 52 | <li>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li> |
michael@0 | 53 | <li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris</li> |
michael@0 | 54 | <li>nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in</li> |
michael@0 | 55 | <li>reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</li> |
michael@0 | 56 | </ul> |
michael@0 | 57 | |
michael@0 | 58 | <div id="rotfl">ROTFL</div> |
michael@0 | 59 | |
michael@0 | 60 | <!-- Tests follow --> |
michael@0 | 61 | <script type="text/javascript" language="javascript" charset="utf-8"> |
michael@0 | 62 | // <![CDATA[ |
michael@0 | 63 | |
michael@0 | 64 | var TAGS = |
michael@0 | 65 | ['div','span','ol','ul','table','p','h1','h2','h3','h4','h5','h6']; |
michael@0 | 66 | |
michael@0 | 67 | var COMBINED_EFFECTS = |
michael@0 | 68 | ['Fade','Appear','BlindUp','BlindDown','Puff','SwitchOff','DropOut','Shake', |
michael@0 | 69 | 'SlideUp','SlideDown','Pulsate','Squish','Fold','Grow','Shrink']; |
michael@0 | 70 | |
michael@0 | 71 | var COMBINED_RJS_EFFECTS = $w('fade appear blind_up blind_down puff switch_off '+ |
michael@0 | 72 | 'drop_out shake slide_up slide_down pulsate squish fold grow shrink'); |
michael@0 | 73 | |
michael@0 | 74 | var tmp, tmp2; |
michael@0 | 75 | |
michael@0 | 76 | new Test.Unit.Runner({ |
michael@0 | 77 | |
michael@0 | 78 | setup: function() { with (this) { |
michael@0 | 79 | $('sandbox').innerHTML = ""; |
michael@0 | 80 | }}, |
michael@0 | 81 | |
michael@0 | 82 | teardown: function() { with(this) { |
michael@0 | 83 | // remove all queued effects |
michael@0 | 84 | Effect.Queue.each(function(e) { e.cancel() }); |
michael@0 | 85 | }}, |
michael@0 | 86 | |
michael@0 | 87 | testBackwardsCompat: function() { with(this) { |
michael@0 | 88 | assertInstanceOf(Effect.Opacity, new Effect2.Fade('sandbox')); |
michael@0 | 89 | }}, |
michael@0 | 90 | |
michael@0 | 91 | testExceptionOnNonExistingElement: function() { with(this) { |
michael@0 | 92 | assertRaise('ElementDoesNotExistError', |
michael@0 | 93 | function(){new Effect.Opacity('nothing-to-see-here')}); |
michael@0 | 94 | assertRaise('ElementDoesNotExistError', |
michael@0 | 95 | function(){new Effect.Move('nothing-to-see-here')}); |
michael@0 | 96 | assertRaise('ElementDoesNotExistError', |
michael@0 | 97 | function(){new Effect.Scale('nothing-to-see-here')}); |
michael@0 | 98 | assertRaise('ElementDoesNotExistError', |
michael@0 | 99 | function(){new Effect.Highlight('nothing-to-see-here')}); |
michael@0 | 100 | }}, |
michael@0 | 101 | |
michael@0 | 102 | testEffectsQueue: function() { with(this) { |
michael@0 | 103 | var e1 = new Effect.Highlight('sandbox'); |
michael@0 | 104 | var e2 = new Effect.Appear('sandbox'); |
michael@0 | 105 | |
michael@0 | 106 | assertEqual(2, Effect.Queue.effects.length); |
michael@0 | 107 | |
michael@0 | 108 | tmp = 0; |
michael@0 | 109 | Effect.Queue.each(function(e) { tmp++ }); |
michael@0 | 110 | assertEqual(2, tmp); |
michael@0 | 111 | |
michael@0 | 112 | // the internal interval timer should be active |
michael@0 | 113 | assertNotNull(Effect.Queue.interval); |
michael@0 | 114 | e1.cancel(); |
michael@0 | 115 | e2.cancel(); |
michael@0 | 116 | assertEqual(0, Effect.Queue.effects.length); |
michael@0 | 117 | |
michael@0 | 118 | // should be inactive after all effects are removed from queue |
michael@0 | 119 | assertNull(Effect.Queue.interval); |
michael@0 | 120 | |
michael@0 | 121 | // should be in e3,e1,e2 order |
michael@0 | 122 | var e1 = new Effect.Highlight('sandbox'); |
michael@0 | 123 | var e2 = new Effect.Appear('sandbox',{queue:'end'}); |
michael@0 | 124 | var e3 = new Effect.Fade('sandbox',{queue:'front'}); |
michael@0 | 125 | assert(e2.startOn > e1.startOn); |
michael@0 | 126 | assert(e3.startOn < e1.startOn); |
michael@0 | 127 | assert(e3.startOn < e2.startOn); |
michael@0 | 128 | assertEqual(3, Effect.Queue.effects.length); |
michael@0 | 129 | |
michael@0 | 130 | Effect.Queue.each(function(e) { e.cancel() }); |
michael@0 | 131 | assertEqual(0, Effect.Queue.effects.length); |
michael@0 | 132 | }}, |
michael@0 | 133 | |
michael@0 | 134 | testScopedEffectsQueue: function() { with(this) { |
michael@0 | 135 | var e1 = new Effect.Highlight('sandbox', {queue: {scope:'myscope'} } ); |
michael@0 | 136 | var e2 = new Effect.Appear('sandbox', {queue: {scope:'myscope'} } ); |
michael@0 | 137 | var e3 = new Effect.Highlight('sandbox', {queue: {scope:'secondscope'} } ); |
michael@0 | 138 | var e4 = new Effect.Appear('sandbox'); |
michael@0 | 139 | |
michael@0 | 140 | assertEqual(2, Effect.Queues.get('myscope').effects.length); |
michael@0 | 141 | assertEqual(1, Effect.Queues.get('secondscope').effects.length); |
michael@0 | 142 | assertEqual(1, Effect.Queues.get('global').effects.length); |
michael@0 | 143 | assertEqual(Effect.Queue.effects.length, Effect.Queues.get('global').effects.length); |
michael@0 | 144 | |
michael@0 | 145 | var tmp = 0; |
michael@0 | 146 | Effect.Queues.get('myscope').effects.each(function(e) { tmp++ }); |
michael@0 | 147 | assertEqual(2, tmp); |
michael@0 | 148 | |
michael@0 | 149 | // the internal interval timer should be active |
michael@0 | 150 | assertNotNull(Effect.Queues.get('myscope').interval); |
michael@0 | 151 | assertNotNull(Effect.Queues.get('secondscope').interval); |
michael@0 | 152 | assertNotNull(Effect.Queues.get('global').interval); |
michael@0 | 153 | |
michael@0 | 154 | e1.cancel(); e2.cancel(); e3.cancel(); e4.cancel(); |
michael@0 | 155 | |
michael@0 | 156 | assertEqual(0, Effect.Queues.get('myscope').effects.length); |
michael@0 | 157 | assertEqual(0, Effect.Queues.get('secondscope').effects.length); |
michael@0 | 158 | assertEqual(0, Effect.Queues.get('global').effects.length); |
michael@0 | 159 | |
michael@0 | 160 | // should be inactive after all effects are removed from queues |
michael@0 | 161 | assertNull(Effect.Queues.get('myscope').interval); |
michael@0 | 162 | assertNull(Effect.Queues.get('secondscope').interval); |
michael@0 | 163 | assertNull(Effect.Queues.get('global').interval); |
michael@0 | 164 | |
michael@0 | 165 | // should be in e3 and e4 together and then e1,e2 order |
michael@0 | 166 | var e1 = new Effect.Highlight('sandbox', {queue: {scope:'myscope'} } ); |
michael@0 | 167 | var e2 = new Effect.Appear('sandbox', {queue: {position: 'end', scope:'myscope'} } ); |
michael@0 | 168 | var e3 = new Effect.Fade('sandbox', {queue: {position: 'front', scope:'myscope'} } ); |
michael@0 | 169 | var e4 = new Effect.Appear('sandbox'); |
michael@0 | 170 | assert(e2.startOn > e1.startOn); |
michael@0 | 171 | assert(e3.startOn < e1.startOn); |
michael@0 | 172 | assert(e3.startOn < e2.startOn); |
michael@0 | 173 | assert(e3.startOn = e4.startOn); |
michael@0 | 174 | assertEqual(3, Effect.Queues.get('myscope').effects.length); |
michael@0 | 175 | |
michael@0 | 176 | Effect.Queues.get('myscope').each(function(e) { e.cancel() }); |
michael@0 | 177 | assertEqual(0, Effect.Queues.get('myscope').effects.length); |
michael@0 | 178 | |
michael@0 | 179 | Effect.Queues.get('global').each(function(e) { e.cancel() }); |
michael@0 | 180 | assertEqual(0, Effect.Queues.get('global').effects.length); |
michael@0 | 181 | |
michael@0 | 182 | // should only allow the first two effects and ignore the third |
michael@0 | 183 | var e1 = new Effect.Highlight('sandbox', {queue: {scope:'myscope', limit: 2} } ); |
michael@0 | 184 | var e2 = new Effect.Appear('sandbox', {queue: {position: 'end', scope:'myscope', limit: 2} } ); |
michael@0 | 185 | var e3 = new Effect.Fade('sandbox', {queue: {position: 'front', scope:'myscope', limit: 2} } ); |
michael@0 | 186 | |
michael@0 | 187 | assertEqual(2, Effect.Queues.get('myscope').effects.length); |
michael@0 | 188 | }}, |
michael@0 | 189 | |
michael@0 | 190 | testEffectMultiple: function() { with(this) { |
michael@0 | 191 | $('sandbox').appendChild(Builder.node('div',{id:'test_1'})); |
michael@0 | 192 | $('sandbox').appendChild(Builder.node('div',{id:'test_2'},[Builder.node('div',{id:'test_2a'})])); |
michael@0 | 193 | $('sandbox').appendChild(Builder.node('div',{id:'test_3'})); |
michael@0 | 194 | |
michael@0 | 195 | // only direct child elements |
michael@0 | 196 | Effect.multiple('sandbox',Effect.Fade); |
michael@0 | 197 | assertEqual(3, Effect.Queue.effects.length); |
michael@0 | 198 | |
michael@0 | 199 | Effect.Queue.each(function(e) { e.cancel() }); |
michael@0 | 200 | assertEqual(0, Effect.Queue.effects.length); |
michael@0 | 201 | |
michael@0 | 202 | // call with array |
michael@0 | 203 | Effect.multiple(['test_1','test_3'],Effect.Puff); |
michael@0 | 204 | assertEqual(2, Effect.Queue.effects.length); |
michael@0 | 205 | }}, |
michael@0 | 206 | |
michael@0 | 207 | testEffectTagifyText: function() { with(this) { |
michael@0 | 208 | $('sandbox').innerHTML = "Blah<strong>bleb</strong> Blub"; |
michael@0 | 209 | assertEqual(3, $('sandbox').childNodes.length); |
michael@0 | 210 | Effect.tagifyText('sandbox'); |
michael@0 | 211 | assertEqual(10, $('sandbox').childNodes.length); |
michael@0 | 212 | |
michael@0 | 213 | Effect.multiple('sandbox', Effect.Fade); |
michael@0 | 214 | assertEqual(10, Effect.Queue.effects.length); |
michael@0 | 215 | }}, |
michael@0 | 216 | |
michael@0 | 217 | // test if all combined effects correctly initialize themselves |
michael@0 | 218 | testCombinedEffectsInitialize: function() { with(this) { |
michael@0 | 219 | COMBINED_EFFECTS.each(function(fx,idx){ |
michael@0 | 220 | info('Effect.'+fx); |
michael@0 | 221 | $('sandbox').innerHTML = ""; |
michael@0 | 222 | $('sandbox').appendChild( |
michael@0 | 223 | Builder.node('div',{id:'test_element'}, |
michael@0 | 224 | Builder.node('span','test'))); //some effects require a child element |
michael@0 | 225 | |
michael@0 | 226 | // should work with new Effect.Blah syntax |
michael@0 | 227 | var effect = new Effect[fx]('test_element'); |
michael@0 | 228 | assertEqual(0, effect.currentFrame); |
michael@0 | 229 | |
michael@0 | 230 | // and without the 'new' |
michael@0 | 231 | var effect = Effect[fx]('test_element'); |
michael@0 | 232 | assertEqual(0, effect.currentFrame); |
michael@0 | 233 | |
michael@0 | 234 | // and, for visualEffect |
michael@0 | 235 | assert($('test_element') == $('test_element').visualEffect(COMBINED_RJS_EFFECTS[idx])); |
michael@0 | 236 | |
michael@0 | 237 | // options parsing (shake, squish and grow are special here) |
michael@0 | 238 | if(!['Shake','Squish','Grow'].include(fx)) { |
michael@0 | 239 | var effect = Effect[fx]('test_element',{duration:2.0}); |
michael@0 | 240 | assertEqual(2.0, effect.options.duration, fx); |
michael@0 | 241 | } |
michael@0 | 242 | }); |
michael@0 | 243 | }}, |
michael@0 | 244 | |
michael@0 | 245 | }); |
michael@0 | 246 | |
michael@0 | 247 | // ]]> |
michael@0 | 248 | </script> |
michael@0 | 249 | </body> |
michael@0 | 250 | </html> |