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">
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">
31
<h1>script.aculo.us Unit test file</h1>
36
<!-- generated elements go in here -->
37
<div id="sandbox"></div>
40
<div id="testlog"> </div>
42
<div class="morphing blub" style="font-size:25px;color:#f00">Well</div>
43
<div class="morphing">You know</div>
44
<div id="blah" style="border:1px solid black;width:100px">Whoo-hoo!</div>
46
<div id="error_message">ERROR MESSAGE</div>
47
<div id="error_message_2">SECOND ERROR MESSAGE</div>
48
<div id="error_message_3" style="border:1px solid red; width:100px; color: #f00">THIRD ERROR MESSAGE</div>
50
<ul class="error-list" id="error_test_ul">
51
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</li>
52
<li>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</li>
53
<li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris</li>
54
<li>nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in</li>
55
<li>reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</li>
58
<div id="rotfl">ROTFL</div>
61
<script type="text/javascript" language="javascript" charset="utf-8">
65
['div','span','ol','ul','table','p','h1','h2','h3','h4','h5','h6'];
67
var COMBINED_EFFECTS =
68
['Fade','Appear','BlindUp','BlindDown','Puff','SwitchOff','DropOut','Shake',
69
'SlideUp','SlideDown','Pulsate','Squish','Fold','Grow','Shrink'];
71
var COMBINED_RJS_EFFECTS = $w('fade appear blind_up blind_down puff switch_off '+
72
'drop_out shake slide_up slide_down pulsate squish fold grow shrink');
76
new Test.Unit.Runner({
78
setup: function() { with (this) {
79
$('sandbox').innerHTML = "";
82
teardown: function() { with(this) {
83
// remove all queued effects
84
Effect.Queue.each(function(e) { e.cancel() });
87
testBackwardsCompat: function() { with(this) {
88
assertInstanceOf(Effect.Opacity, new Effect2.Fade('sandbox'));
91
testExceptionOnNonExistingElement: function() { with(this) {
92
assertRaise('ElementDoesNotExistError',
93
function(){new Effect.Opacity('nothing-to-see-here')});
94
assertRaise('ElementDoesNotExistError',
95
function(){new Effect.Move('nothing-to-see-here')});
96
assertRaise('ElementDoesNotExistError',
97
function(){new Effect.Scale('nothing-to-see-here')});
98
assertRaise('ElementDoesNotExistError',
99
function(){new Effect.Highlight('nothing-to-see-here')});
102
testCallbacks: function() { with(this) {
104
var e1 = new Effect.Opacity('sandbox',{from:1.0,to:0.5,duration:0.5,
105
beforeStart: function() { tmp++ },
106
beforeStartInternal: function() { tmp++ },
107
beforeSetup: function() { tmp++ },
108
beforeSetupInternal: function() { tmp++ },
109
afterSetup: function() { tmp++ },
110
afterSetupInternal: function() { tmp++ },
111
beforeUpdate: function() { tmp2++ },
112
beforeUpdateInternal: function() { tmp2++ },
113
beforeFinish: function() { tmp++ },
114
beforeFinishInternal: function() { tmp++ },
115
afterFinish: function() { tmp++ },
116
afterFinishInternal: function() { tmp++ }
118
wait(1000, function() {
119
assertEqual(10, tmp);
124
testEvent: function() { with(this) {
126
new Effect.Event({ afterFinish:function(){ tmp++ }, position:'end'});
127
wait(100, function() {
132
testTransition: function() { with(this) {
133
// false implies linear
134
var e = new Effect.Opacity('sandbox',{transition:false,from:0.0,to:0.25,duration:0.5});
135
assert(e.options.transition == Effect.Transitions.linear);
137
wait(1000, function() {
138
assertEqual(0.25, $('sandbox').getStyle('opacity'));
139
// default to sinoidal
140
var e = new Effect.Opacity('sandbox',{from:0.0,to:0.25,duration:0.5});
141
assert(e.options.transition == Effect.Transitions.sinoidal);
142
wait(1000, function() {
143
assertEqual(0.25, $('sandbox').getStyle('opacity'));
146
{ transition: Effect.Transitions.linear, expected: 1 },
147
{ transition: Effect.Transitions.sinoidal, expected: 1 },
148
{ transition: Effect.Transitions.reverse, expected: 0 },
149
{ transition: Effect.Transitions.flicker, expected: 1 },
150
{ transition: Effect.Transitions.wobble, expected: 1 },
151
{ transition: Effect.Transitions.pulse, expected: 1 },
152
{ transition: Effect.Transitions.none, expected: 0 }
155
transitions.each(function(t){
156
var e = new Effect.Opacity('sandbox',{sync:true, from:0, to: 1, transition:t.transition});
157
assert(e.options.transition == t.transition);
159
assertEqual(t.expected, e.position, t.transition);
166
testInspect: function() { with(this) {
167
var e1 = new Effect.Opacity('sandbox',{from:1.0,to:0.5,duration:0.5});
168
info( e1.inspect() );
169
assertEqual(0, e1.inspect().indexOf('#<Effect:'));
170
assert(e1.inspect().indexOf('idle')>0);
171
wait(1000, function() {
172
assert(e1.inspect().indexOf('finished')>0);
176
testDefaultOptions: function() { with(this) {
177
var oldDefaultOptions = Object.extend({},Effect.DefaultOptions);
179
assertEqual(1.0, Effect.DefaultOptions.duration);
180
Effect.DefaultOptions.duration = 0.5;
181
var e1 = new Effect.Opacity('sandbox');
182
assertEqual(0.5, e1.options.duration);
184
wait(750, function() {
185
assertEqual('finished', e1.state);
186
Effect.DefaultOptions = oldDefaultOptions;
190
testEffectsQueue: function() { with(this) {
191
var e1 = new Effect.Highlight('sandbox');
192
var e2 = new Effect.Appear('sandbox');
194
assertEqual(2, Effect.Queue.effects.length);
197
Effect.Queue.each(function(e) { tmp++ });
200
// the internal interval timer should be active
201
assertNotNull(Effect.Queue.interval);
204
assertEqual(0, Effect.Queue.effects.length);
206
// should be inactive after all effects are removed from queue
207
assertNull(Effect.Queue.interval);
209
// should be in e3,e1,e2 order
210
var e1 = new Effect.Highlight('sandbox');
211
var e2 = new Effect.Appear('sandbox',{queue:'end'});
212
var e3 = new Effect.Fade('sandbox',{queue:'front'});
213
assert(e2.startOn > e1.startOn);
214
assert(e3.startOn < e1.startOn);
215
assert(e3.startOn < e2.startOn);
216
assertEqual(3, Effect.Queue.effects.length);
218
Effect.Queue.each(function(e) { e.cancel() });
219
assertEqual(0, Effect.Queue.effects.length);
222
testScopedEffectsQueue: function() { with(this) {
223
var e1 = new Effect.Highlight('sandbox', {queue: {scope:'myscope'} } );
224
var e2 = new Effect.Appear('sandbox', {queue: {scope:'myscope'} } );
225
var e3 = new Effect.Highlight('sandbox', {queue: {scope:'secondscope'} } );
226
var e4 = new Effect.Appear('sandbox');
228
assertEqual(2, Effect.Queues.get('myscope').effects.length);
229
assertEqual(1, Effect.Queues.get('secondscope').effects.length);
230
assertEqual(1, Effect.Queues.get('global').effects.length);
231
assertEqual(Effect.Queue.effects.length, Effect.Queues.get('global').effects.length);
234
Effect.Queues.get('myscope').effects.each(function(e) { tmp++ });
237
// the internal interval timer should be active
238
assertNotNull(Effect.Queues.get('myscope').interval);
239
assertNotNull(Effect.Queues.get('secondscope').interval);
240
assertNotNull(Effect.Queues.get('global').interval);
242
e1.cancel(); e2.cancel(); e3.cancel(); e4.cancel();
244
assertEqual(0, Effect.Queues.get('myscope').effects.length);
245
assertEqual(0, Effect.Queues.get('secondscope').effects.length);
246
assertEqual(0, Effect.Queues.get('global').effects.length);
248
// should be inactive after all effects are removed from queues
249
assertNull(Effect.Queues.get('myscope').interval);
250
assertNull(Effect.Queues.get('secondscope').interval);
251
assertNull(Effect.Queues.get('global').interval);
253
// should be in e3 and e4 together and then e1,e2 order
254
var e1 = new Effect.Highlight('sandbox', {queue: {scope:'myscope'} } );
255
var e2 = new Effect.Appear('sandbox', {queue: {position: 'end', scope:'myscope'} } );
256
var e3 = new Effect.Fade('sandbox', {queue: {position: 'front', scope:'myscope'} } );
257
var e4 = new Effect.Appear('sandbox');
258
assert(e2.startOn > e1.startOn);
259
assert(e3.startOn < e1.startOn);
260
assert(e3.startOn < e2.startOn);
261
assert(e3.startOn = e4.startOn);
262
assertEqual(3, Effect.Queues.get('myscope').effects.length);
264
Effect.Queues.get('myscope').each(function(e) { e.cancel() });
265
assertEqual(0, Effect.Queues.get('myscope').effects.length);
267
Effect.Queues.get('global').each(function(e) { e.cancel() });
268
assertEqual(0, Effect.Queues.get('global').effects.length);
270
// should only allow the first two effects and ignore the third
271
var e1 = new Effect.Highlight('sandbox', {queue: {scope:'myscope', limit: 2} } );
272
var e2 = new Effect.Appear('sandbox', {queue: {position: 'end', scope:'myscope', limit: 2} } );
273
var e3 = new Effect.Fade('sandbox', {queue: {position: 'front', scope:'myscope', limit: 2} } );
275
assertEqual(2, Effect.Queues.get('myscope').effects.length);
278
testEffectMultiple: function() { with(this) {
279
$('sandbox').appendChild(Builder.node('div',{id:'test_1'}));
280
$('sandbox').appendChild(Builder.node('div',{id:'test_2'},[Builder.node('div',{id:'test_2a'})]));
281
$('sandbox').appendChild(Builder.node('div',{id:'test_3'}));
283
// only direct child elements
284
Effect.multiple('sandbox',Effect.Fade);
285
assertEqual(3, Effect.Queue.effects.length);
287
Effect.Queue.each(function(e) { e.cancel() });
288
assertEqual(0, Effect.Queue.effects.length);
291
Effect.multiple(['test_1','test_3'],Effect.Puff);
292
assertEqual(2, Effect.Queue.effects.length);
295
testEffectTagifyText: function() { with(this) {
296
$('sandbox').innerHTML = "Blah<strong>bleb</strong> Blub";
297
assertEqual(3, $('sandbox').childNodes.length);
298
Effect.tagifyText('sandbox');
299
assertEqual(10, $('sandbox').childNodes.length);
301
Effect.multiple('sandbox', Effect.Fade);
302
assertEqual(10, Effect.Queue.effects.length);
305
// test if all combined effects correctly initialize themselves
306
testCombinedEffectsInitialize: function() { with(this) {
307
COMBINED_EFFECTS.each(function(fx,idx){
309
$('sandbox').innerHTML = "";
310
$('sandbox').appendChild(
311
Builder.node('div',{id:'test_element'},
312
Builder.node('span','test'))); //some effects require a child element
314
// should work with new Effect.Blah syntax
315
var effect = new Effect[fx]('test_element');
316
assertEqual(0, effect.currentFrame);
318
// and without the 'new'
319
var effect = Effect[fx]('test_element');
320
assertEqual(0, effect.currentFrame);
322
// and, for visualEffect
323
assert($('test_element') == $('test_element').visualEffect(COMBINED_RJS_EFFECTS[idx]));
325
// options parsing (shake, squish and grow are special here)
326
if(!['Shake','Squish','Grow'].include(fx)) {
327
var effect = Effect[fx]('test_element',{duration:2.0});
328
assertEqual(2.0, effect.options.duration, fx);
333
testSynchronizedEffects: function() { with(this) {
334
var e1 = new Effect.Fade('sandbox',{sync:true});
335
wait(250, function() {
336
// effect should still be at frame 0
337
assertEqual(0, e1.currentFrame);
338
assertEqual('idle', e1.state);
341
// no frame count for sync effects
342
assertEqual(0, e1.currentFrame);
343
assertEqual('running', e1.state);
347
testEffectPosition: function() { with(this) {
348
var testeffect = new Effect.Opacity('sandbox',{
349
afterSetup: function(effect) { effect.frames = 0; },
350
afterUpdate: function(effect) { effect.frames++; $('sandbox').update(effect.position); },
351
duration: 0.5, from: 1.0, to: 0.5
353
assertNull(testeffect.position);
354
assertEqual('idle', testeffect.state);
355
wait(1000, function() {
356
info('Rendered ' + testeffect.frames + ' frames in .5 seconds ' +
357
'(~' + (testeffect.frames/0.5) + 'fps of a possible 60fps, ' +
358
'note that this can exceed 60fps because of additional last frame rendering)');
359
assertEqual('0.5', $('sandbox').innerHTML);
360
assertEqual(0.5, testeffect.position);
361
assertEqual('finished', testeffect.state);
365
testRenderPerformance: function() { with(this) {
366
info('The render() method is generated on a per-effect basis')
367
var e = new Effect.Opacity('sandbox',{sync:true});
368
benchmark(function(){
370
},1000, 'Without events');
371
var e = new Effect.Opacity('sandbox',{sync:true,afterUpdate:function(){return}});
372
benchmark(function(){
374
},1000, 'With afterUpdate event');
377
testElementMorph: function() { with(this) {
378
$('error_test_ul').morph('font-size:40px', {duration: 0.5}).setStyle({marginRight:'17px'});
379
$('error_message_2').morph({
382
backgroundColor: '#ffffff'
387
$('error_message_3').morph('final', {duration:0.5});
388
wait(1000,function(){
389
assertEqual('17px', $('error_test_ul').getStyle('margin-right'));
390
assertEqual('40px', $('error_test_ul').getStyle('font-size'));
391
assertEqual('#ffffff', $('error_message_2').getStyle('background-color').parseColor());
392
assertEqual('20px', $('error_message_2').getStyle('font-size'));
393
assertEqual('italic', $('error_message_3').getStyle('font-style'));
394
assertEqual('20px', $('error_message_3').getStyle('font-size'));
395
assertEqual(.5, $('error_message_3').getStyle('opacity'));
396
assertEqual('', $('error_message_3').style.fontSize);
400
testElementMorphChaining: function() { with(this) {
401
$('error_message').morph('font-size:17px').morph('opacity:0',{delay:3});
402
wait(4100,function(){ // 3000ms delay + 1000ms default duration
403
assertEqual(0, $('error_message').getOpacity());
407
testTransformBySelector: function() { with(this) {
408
new Effect.Transform([
409
{ 'ul.error-list li': 'font-size:20px;text-indent:40pt' }
410
],{ duration: 0.5 }).play();
414
$A($('error_test_ul').cleanWhitespace().childNodes).each(function(node){
415
assertEqual('20px', $(node).getStyle('font-size'));
416
assertEqual('40pt', $(node).getStyle('text-indent'));
423
testTransformUsesCSSClassPresets: function() { with(this) {
424
assertEqual('40px', $('rotfl').getStyle('font-size'));
426
// Render the effect at half-way through, font-size should be
427
// exactly half-way between original and target
428
new Effect.Transform([
429
{ 'rotfl': 'font-size:20px;text-indent:40pt;background-color:#888' }
430
],{ sync:true }).play().render(0.5);
432
wait(1100,function(){
433
// shoould be 30px = 40px + (20px-40px)/2
434
assertEqual('30px', $('rotfl').getStyle('font-size'));
438
testTransformMultiple: function() { with(this) {
439
var transformation = new Effect.Transform([
440
{ 'div.morphing': 'font-size:20px;padding-left:40em;opacity:0.5' },
442
'width:480px;border-width:10px;border-right-width:20px;' +
443
'margin:20px;margin-bottom:-20px;font-size:30px;' +
445
],{ duration: 0.5 });
447
var generatedEffect = transformation.play();
449
assertEqual(3, generatedEffect.effects.length);
451
wait(700, function(){
452
// have a look at the generated color transforms for the 3rd found element
453
// which is the "blah" div
454
assertEqual('blah', generatedEffect.effects[2].element.id);
455
assertEnumEqual([255,255,255],
456
generatedEffect.effects[2].transforms.detect( function(transform){
457
return (transform.style == 'backgroundColor')
459
assertEnumEqual([153,85,68],
460
generatedEffect.effects[2].transforms.detect( function(transform){
461
return (transform.style == 'backgroundColor')
464
assertEqual('20px', $$('div.morphing').first().getStyle('font-size'));
465
assertEqual('20px', $$('div.morphing').last().getStyle('font-size'));
466
assertEqual('30px', $('blah').getStyle('font-size'));
468
// border-width/border-right-width should be set independently
469
assertEqual('10px', $('blah').getStyle('border-top-width'));
470
assertEqual('10px', $('blah').getStyle('border-bottom-width'));
471
assertEqual('10px', $('blah').getStyle('border-left-width'));
472
assertEqual('20px', $('blah').getStyle('border-right-width'));
474
// colors should assume transition from
475
// #ffffff (white) if original was transparent
476
// we now should have arrived at the given color
477
assertEqual('#995544', $('blah').getStyle('background-color').parseColor());
479
// play again = should have same values
480
transformation.play();
481
wait(700, function(){
482
assertEqual('20px', $$('div.morphing').first().getStyle('font-size'));
483
assertEqual('20px', $$('div.morphing').last().getStyle('font-size'));
484
assertEqual('30px', $('blah').getStyle('font-size'));
486
$('blah').setStyle({'font-size':'100px'});
487
assertEqual('100px', $('blah').getStyle('font-size'));
488
transformation.play();
489
wait(700, function(){
490
assertEqual('30px', $('blah').getStyle('font-size'));
492
new Effect.Transform([
493
{ 'blah': 'color: #80d980; background: #208020' }
494
],{ duration: 1.1 }).play();
495
wait(1500, function(){
496
assertEqual('#80d980', $('blah').getStyle('color').parseColor());
497
assertEqual('#208020', $('blah').getStyle('background-color').parseColor());
b'\\ No newline at end of file'