melky, я тут продолжаю играться с тестами и вот что получилось учел твой коммент и то что прочитал, именна тестов только не поменял еще.
Так лучше?)
describe('new ModalJS', function() {
var modal;
it( 'new Object', function() {
modal = new ModalJS();
expect( ( typeof modal ).valueOf())
.toBe( "object" );
});
it ( "Create overlay", function () {
expect ( isHTMLElement( modal.overlay) )
.toBe( true );
expect ( modal.overlay.parentElement )
.toBe( document.body );
} );
});
function isHTMLElement( elem ) {
return (typeof elem === "object") &&
(elem.nodeType === 1) && (typeof elem.style === "object") &&
(typeof elem.ownerDocument ==="object");
}
describe ( "Methods", function () {
var modal = modal = new ModalJS( {
NotUseAnimate: true
} );
it( "set window", function () {
var win = document.getElementById( "modal-test-win");
expect ( modal.setWindow ( win ) )
.toBe ( modal );
});
it ( "Show window", function ( done ) {
modal.show();
expect ( isDisplayed ( modal.window ))
.toBe ( true );
expect ( isDisplayed( modal.overlay ) )
.toBe ( true );
setTimeout ( function (){
expect ( isCentered ( modal.window ))
.toBe ( true );
done();
}, 0 );
} );
it ( "Hide window", function ( ) {
modal.hide () ;
expect ( isDisplayed( modal.window ) )
.toBe ( false );
expect ( isDisplayed( modal.overlay ) )
.toBe ( false );
} );
it ( "Window destroy", function ( ) {
expect ( modal.destroy( ) )
.toBe ( true );
expect ( modal.overlay)
.toBeUndefined ();
} );
it ( "Window destroy [remove Window]", function ( ) {
var modal = new ModalJS()
.setWindow( document.getElementById( "modal-test-win") );
expect ( modal.destroy( true ) )
.toBe ( true );
expect ( modal.window )
.toBeUndefined();
} );
} );
function isDisplayed ( elem ) {
var display = getStyle( elem, "display" );
return !display || display !== "none";
};
function isCentered ( win ) {
var y = ( window.innerHeight - win.offsetHeight ) / 2 ,
x = ( window.innerWidth - win.offsetWidth) / 2 ,
winY = Math.round( parseFloat( getStyle( win, "top" ) ) ),
winX = Math.round( parseFloat( getStyle( win, "left" ) ) );
return Math.round( y ) == winY
&& Math.round( x ) == winX;
}
function getStyle ( elem, style ) {
var value = elem.style[ style ];
if ( !value ) {
value = window.getComputedStyle( elem, null).getPropertyValue( style );
}
return value;
}
describe ( "Async animate", function ( ) {
var win2 = document.getElementById( "modal-test-win2"),
modal = new ModalJS().setWindow ( win2 );
beforeEach( function ( done ) {
modal.on ( "showed", function () {
expect ( isDisplayed ( modal.window ))
.toBe ( true );
expect ( isCentered ( modal.window ))
.toBe ( true );
expect ( isDisplayed( modal.overlay ) )
.toBe ( true );
}, done );
modal.show();
} );
it ( "Hide window", function ( done ) {
modal.on ( "closed", function () {
expect ( isDisplayed( modal.window ) )
.toBe ( false );
expect ( isDisplayed( modal.overlay ) )
.toBe ( false );
}, done );
modal.hide();
} );
});