Skip to content
Permalink
Browse files

Merge pull request #260 from gnarf37/effects-unit

Unit Tests: effects: adding some animateClass tests
  • Loading branch information...
scottgonzalez committed May 13, 2011
2 parents 5bff5c7 + e4204b1 commit 7e2a704a07b13ae4f9731fea5409b36434bb5da4
Showing with 63 additions and 8 deletions.
  1. +19 −1 tests/unit/effects/effects.html
  2. +44 −7 tests/unit/effects/effects_core.js
@@ -35,6 +35,22 @@
.hidden {
display: none;
}
.test {
background: #000;
border: 0;
}
.testAddBorder {
border: 10px solid #000;
}
.testChangeBackground {
background: #fff;
}
.test h2 {
font-size: 10px;
}
.testChildren h2 {
font-size: 20px;
}
</style>
</head>
<body>
@@ -48,7 +64,9 @@ <h2 id="qunit-userAgent"></h2>

<div id="qunit-fixture">
<div class="hidden test"></div>
<div class="shown test"></div>
<div class="animateClass test">
<h2>Child Element Test</h2>
</div>
</div>

</body>
@@ -1,5 +1,13 @@
(function($) {

function present( value, array, message ) {
QUnit.push( jQuery.inArray( value, array ) !== -1 , value, array, message );
}

function notPresent( value, array, message ) {
QUnit.push( jQuery.inArray( value, array ) === -1 , value, array, message );
}

var animateTime = 15;

module( "effects.core" );
@@ -8,12 +16,10 @@ $.each( $.effects.effect, function( effect ) {
if ( effect === "transfer" ) {
return;
}
QUnit.reset();
module( "effect."+effect );
test( "show/hide", function() {
asyncTest( "show/hide", function() {
var hidden = $( "div.hidden" );
expect( 8 );
stop();

var count = 0,
test = 0;
@@ -23,24 +29,55 @@ $.each( $.effects.effect, function( effect ) {
var point = count;
return function( next ) {
test++;
equals( point, test, "Queue function fired in order" );
equal( point, test, "Queue function fired in order" );
if ( fn ) {
fn ()
fn ();
} else {
setTimeout( next, animateTime );
}
}
};
}

hidden.queue( queueTest() ).show( effect, animateTime, queueTest(function() {
equal( hidden.css("display"), "block", "Hidden is shown after .show(\"" +effect+ "\", time)" );
})).queue( queueTest() ).hide( effect, animateTime, queueTest(function() {
equal( hidden.css("display"), "none", "Back to hidden after .hide(\"" +effect+ "\", time)" );
})).queue( queueTest(function(next) {
deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains")
deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains");
start();
}));
});
});

module("animateClass");

asyncTest( "animateClass works with borderStyle", function() {
var test = $("div.animateClass"),
count = 0;
expect(3);
test.toggleClass("testAddBorder", 20, function() {
test.toggleClass("testAddBorder", 20, function() {
equal( test.css("borderLeftStyle"), "none", "None border set" );
start();
});
equal( test.css("borderLeftStyle"), "solid", "None border not immedately set" );
});
equal( test.css("borderLeftStyle"), "solid", "Solid border immedately set" );
});

asyncTest( "animateClass works with colors", function() {
var test = $("div.animateClass"),
count = 0;
expect(2);
test.toggleClass("testChangeBackground", 100, function() {
present( test.css("backgroundColor"), [ "#ffffff", "rgb(255, 255, 255)" ], "Color is final" );
start();
});
setTimeout(function() {
var color = test.css("backgroundColor");
notPresent( color, [ "#000000", "#ffffff", "rgb(0, 0, 0)", "rgb(255,255,255)" ],
"Color is not endpoints in middle." );
}, 50);
});

})(jQuery);

0 comments on commit 7e2a704

Please sign in to comment.
You can’t perform that action at this time.