diff options
author | Hakim El Hattab | 2013-08-22 19:03:11 -0400 |
---|---|---|
committer | Hakim El Hattab | 2013-08-22 19:03:11 -0400 |
commit | c7728ba659e11bdbea3105298a1c8f81668627e5 (patch) | |
tree | c14e03b03792b008dacc15054f783960d5b52724 /test/test.js | |
parent | 8d7e93cfc69e816b823579966b429ea72263c82b (diff) |
add unit tests #123
Diffstat (limited to 'test/test.js')
-rw-r--r-- | test/test.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..6e11f00 --- /dev/null +++ b/test/test.js @@ -0,0 +1,103 @@ + + +Reveal.addEventListener( 'ready', function() { + + QUnit.module( 'API' ); + + test( 'Reveal.isReady', function() { + ok( Reveal.isReady() === true, 'returns true' ); + }); + + test( 'Reveal.isOverview', function() { + ok( Reveal.isOverview() === false, 'returns false' ); + + Reveal.toggleOverview(); + ok( Reveal.isOverview() === true, 'returns true after toggling on' ); + + Reveal.toggleOverview(); + ok( Reveal.isOverview() === false, 'returns false after toggling off' ); + }); + + test( 'Reveal.isPaused', function() { + ok( Reveal.isPaused() === false, 'returns false' ); + + Reveal.togglePause(); + ok( Reveal.isPaused() === true, 'returns true after pausing' ); + + Reveal.togglePause(); + ok( Reveal.isPaused() === false, 'returns false after resuming' ); + }); + + test( 'Reveal.isFirstSlide', function() { + Reveal.slide( 0 ); + ok( Reveal.isFirstSlide() === true, 'returns true' ); + + Reveal.slide( 1 ); + ok( Reveal.isFirstSlide() === false, 'returns false after navigation' ); + + Reveal.slide( 0 ); + ok( Reveal.isFirstSlide() === true, 'returns true after navigation' ); + }); + + test( 'Reveal.isLastSlide', function() { + Reveal.slide( 0 ); + ok( Reveal.isLastSlide() === false, 'returns false' ); + + Reveal.slide( document.querySelectorAll( '.reveal .slides>section' ).length - 1 ); + ok( Reveal.isLastSlide() === true, 'returns true after navigation' ); + + Reveal.slide( 0 ); + ok( Reveal.isLastSlide() === false, 'returns false after navigation' ); + }); + + test( 'Reveal.getIndices', function() { + var indices = Reveal.getIndices(); + + ok( typeof indices.hasOwnProperty( 'h' ), 'h exists' ); + ok( typeof indices.hasOwnProperty( 'v' ), 'v exists' ); + ok( typeof indices.hasOwnProperty( 'f' ), 'f exists' ); + + Reveal.slide( 1 ); + ok( Reveal.getIndices().h === 1 && Reveal.getIndices().v === 0, 'h 1, v 0' ); + + Reveal.slide( 1, 2 ); + ok( Reveal.getIndices().h === 1 && Reveal.getIndices().v === 2, 'h 1, v 2' ); + + Reveal.slide( 0 ); + }); + + test( 'Reveal.getScale', function() { + ok( typeof Reveal.getScale() === 'number', 'has scale' ); + }); + + test( 'Reveal.getConfig', function() { + ok( typeof Reveal.getConfig() === 'object', 'has config' ); + }); + + + QUnit.module( 'Events' ); + + asyncTest( 'slidechanged', function() { + expect( 1 ); + + var _onSlideChanged = function( event ) { + ok( true, 'event fired' ); + start(); + } + + Reveal.addEventListener( 'slidechanged', _onSlideChanged ); + + // Should trigger the event + Reveal.slide( 1 ); + + // Should not trigger an event since it's the same # + Reveal.slide( 1 ); + + Reveal.removeEventListener( 'slidechanged', _onSlideChanged ); + + }); + +} ); + +Reveal.initialize(); + |