Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Add test for "destroy" method
Browse files Browse the repository at this point in the history
Add test to confirm elements are returned to their original states
after "destroy"
  • Loading branch information
Brandon Belvin committed Jul 9, 2013
1 parent 4fe8d81 commit fd61b5a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/coverflow.js
Expand Up @@ -200,7 +200,7 @@
.each(function(){
var $this = $(this);
$this.data("origstyle", $this.attr("style") || "");
})
});

this.element
.addClass( "ui-coverflow" )
Expand Down
38 changes: 38 additions & 0 deletions tests/qunit/methods.js
@@ -1,4 +1,11 @@
(function($) {
function getAttributes( $elem ) {
var attrs = {};
$.each( $elem[ 0 ].attributes, function () {
attrs[ this.nodeName ] = this.nodeValue;
});
return attrs;
}

module( 'CoverflowJS: methods', {
setup: function() {
Expand All @@ -11,5 +18,36 @@
deepEqual( this.el, this.el.coverflow(), 'method is chainable' );
deepEqual( this.el.get( 0 ), this.el.coverflow( 'widget' ).get( 0 ), 'widget method' );
});

test( 'destroy', 9, function () {
var originalAttrs = getAttributes( this.el ),
parentOriginalAttrs = getAttributes( this.el.parent() ),
endAttrs, parentEndAttrs;

ok( ! this.el.hasClass( "ui-coverflow" ), "Element does not have coverflow class" );
ok( ! this.el.parent().hasClass( "ui-coverflow-wrapper" ), "Element's parent does not have coverflow wrapper class" );

this.el.coverflow();

ok( this.el.hasClass( "ui-coverflow" ), "Element has coverflow class" );
ok( this.el.parent().hasClass( "ui-coverflow-wrapper" ), "Element's parent has coverflow wrapper class" );

this.el.coverflow( "destroy" );

ok( ! this.el.hasClass( "ui-coverflow" ), "Element does not have coverflow class" );
ok( ! this.el.parent().hasClass( "ui-coverflow-wrapper" ), "Element's parent does not have coverflow wrapper class" );

endAttrs = getAttributes( this.el );

// Have to compare each attribute since the original element may not have had any styling, leading to a comparison of "" to undefined
$.each( endAttrs, function ( n, v ) {
strictEqual ( v, ( originalAttrs[ n ] || ""), "Element attribute " + n + " matches original after destroy" );
});

parentEndAttrs = getAttributes( this.el.parent() );

deepEqual( parentOriginalAttrs, parentEndAttrs, "Element's parent attributes match originals after destroy" );

});

})( jQuery );

0 comments on commit fd61b5a

Please sign in to comment.