aboutsummaryrefslogtreecommitdiff
path: root/test/test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/test.js')
-rw-r--r--test/test.js177
1 files changed, 168 insertions, 9 deletions
diff --git a/test/test.js b/test/test.js
index f620b5b..a96b70b 100644
--- a/test/test.js
+++ b/test/test.js
@@ -68,6 +68,12 @@ Reveal.addEventListener( 'ready', function() {
strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' );
});
+ test( 'Reveal.isFirstSlide after vertical slide', function() {
+ Reveal.slide( 1, 1 );
+ Reveal.slide( 0, 0 );
+ strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( 0, 0 )' );
+ });
+
test( 'Reveal.isLastSlide', function() {
Reveal.slide( 0, 0 );
strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
@@ -75,34 +81,70 @@ Reveal.addEventListener( 'ready', function() {
var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
Reveal.slide( lastSlideIndex, 0 );
- strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( ', 0+ lastSlideIndex +' )' );
+ strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( '+ lastSlideIndex +', 0 )' );
Reveal.slide( 0, 0 );
strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
});
+ test( 'Reveal.isLastSlide after vertical slide', function() {
+ var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
+
+ Reveal.slide( 1, 1 );
+ Reveal.slide( lastSlideIndex );
+ strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( '+ lastSlideIndex +', 0 )' );
+ });
+
+ test( 'Reveal.getTotalSlides', function() {
+ strictEqual( Reveal.getTotalSlides(), 8, 'eight slides in total' );
+ });
+
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' );
+ ok( indices.hasOwnProperty( 'h' ), 'h exists' );
+ ok( indices.hasOwnProperty( 'v' ), 'v exists' );
+ ok( indices.hasOwnProperty( 'f' ), 'f exists' );
Reveal.slide( 1, 0 );
- ok( Reveal.getIndices().h === 1 && Reveal.getIndices().v === 0, 'h 1, v 0' );
+ strictEqual( Reveal.getIndices().h, 1, 'h 1' );
+ strictEqual( Reveal.getIndices().v, 0, 'v 0' );
Reveal.slide( 1, 2 );
- ok( Reveal.getIndices().h === 1 && Reveal.getIndices().v === 2, 'h 1, v 2' );
+ strictEqual( Reveal.getIndices().h, 1, 'h 1' );
+ strictEqual( Reveal.getIndices().v, 2, 'v 2' );
Reveal.slide( 0, 0 );
+ strictEqual( Reveal.getIndices().h, 0, 'h 0' );
+ strictEqual( Reveal.getIndices().v, 0, 'v 0' );
});
test( 'Reveal.getSlide', function() {
- var firstSlide = document.querySelector( '.reveal .slides>section:first-child' );
+ equal( Reveal.getSlide( 0 ), document.querySelector( '.reveal .slides>section:first-child' ), 'gets correct first slide' );
+ equal( Reveal.getSlide( 1 ), document.querySelector( '.reveal .slides>section:nth-child(2)' ), 'no v index returns stack' );
+ equal( Reveal.getSlide( 1, 0 ), document.querySelector( '.reveal .slides>section:nth-child(2)>section:nth-child(1)' ), 'v index 0 returns first vertical child' );
+ equal( Reveal.getSlide( 1, 1 ), document.querySelector( '.reveal .slides>section:nth-child(2)>section:nth-child(2)' ), 'v index 1 returns second vertical child' );
- equal( Reveal.getSlide( 0 ), firstSlide, 'gets correct first slide' );
+ strictEqual( Reveal.getSlide( 100 ), undefined, 'undefined when out of horizontal bounds' );
+ strictEqual( Reveal.getSlide( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
+ });
+
+ test( 'Reveal.getSlideBackground', function() {
+ equal( Reveal.getSlideBackground( 0 ), document.querySelector( '.reveal .backgrounds>.slide-background:first-child' ), 'gets correct first background' );
+ equal( Reveal.getSlideBackground( 1 ), document.querySelector( '.reveal .backgrounds>.slide-background:nth-child(2)' ), 'no v index returns stack' );
+ equal( Reveal.getSlideBackground( 1, 0 ), document.querySelector( '.reveal .backgrounds>.slide-background:nth-child(2) .slide-background:nth-child(1)' ), 'v index 0 returns first vertical child' );
+ equal( Reveal.getSlideBackground( 1, 1 ), document.querySelector( '.reveal .backgrounds>.slide-background:nth-child(2) .slide-background:nth-child(2)' ), 'v index 1 returns second vertical child' );
- strictEqual( Reveal.getSlide( 100 ), undefined, 'returns undefined when slide can\'t be found' );
+ strictEqual( Reveal.getSlideBackground( 100 ), undefined, 'undefined when out of horizontal bounds' );
+ strictEqual( Reveal.getSlideBackground( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
+ });
+
+ test( 'Reveal.getSlideNotes', function() {
+ Reveal.slide( 0, 0 );
+ ok( Reveal.getSlideNotes() === 'speaker notes 1', 'works with <aside class="notes">' );
+
+ Reveal.slide( 1, 0 );
+ ok( Reveal.getSlideNotes() === 'speaker notes 2', 'works with <section data-notes="">' );
});
test( 'Reveal.getPreviousSlide/getCurrentSlide', function() {
@@ -116,6 +158,16 @@ Reveal.addEventListener( 'ready', function() {
equal( Reveal.getCurrentSlide(), secondSlide, 'current is slide #1' );
});
+ test( 'Reveal.getProgress', function() {
+ Reveal.slide( 0, 0 );
+ strictEqual( Reveal.getProgress(), 0, 'progress is 0 on first slide' );
+
+ var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
+
+ Reveal.slide( lastSlideIndex, 0 );
+ strictEqual( Reveal.getProgress(), 1, 'progress is 1 on last slide' );
+ });
+
test( 'Reveal.getScale', function() {
ok( typeof Reveal.getScale() === 'number', 'has scale' );
});
@@ -269,6 +321,13 @@ Reveal.addEventListener( 'ready', function() {
Reveal.slide( 3, 0, 0 );
equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 2, 'both fragments of same index are shown' );
+
+ // This slide has three fragments, first one is index 0, second and third have index 1
+ Reveal.slide( 2, 2, 0 );
+ equal( Reveal.getIndices().f, 0, 'returns correct index for first fragment' );
+
+ Reveal.slide( 2, 2, 1 );
+ equal( Reveal.getIndices().f, 1, 'returns correct index for two fragments with same index' );
});
test( 'Index generation', function() {
@@ -332,6 +391,70 @@ Reveal.addEventListener( 'ready', function() {
// ---------------------------------------------------------------
+ // AUTO-SLIDE TESTS
+
+ QUnit.module( 'Auto Sliding' );
+
+ test( 'Reveal.isAutoSliding', function() {
+ strictEqual( Reveal.isAutoSliding(), false, 'false by default' );
+
+ Reveal.configure({ autoSlide: 10000 });
+ strictEqual( Reveal.isAutoSliding(), true, 'true after starting' );
+
+ Reveal.configure({ autoSlide: 0 });
+ strictEqual( Reveal.isAutoSliding(), false, 'false after setting to 0' );
+ });
+
+ test( 'Reveal.toggleAutoSlide', function() {
+ Reveal.configure({ autoSlide: 10000 });
+
+ Reveal.toggleAutoSlide();
+ strictEqual( Reveal.isAutoSliding(), false, 'false after first toggle' );
+ Reveal.toggleAutoSlide();
+ strictEqual( Reveal.isAutoSliding(), true, 'true after second toggle' );
+
+ Reveal.configure({ autoSlide: 0 });
+ });
+
+ asyncTest( 'autoslidepaused', function() {
+ expect( 1 );
+
+ var _onEvent = function( event ) {
+ ok( true, 'event fired' );
+ }
+
+ Reveal.addEventListener( 'autoslidepaused', _onEvent );
+ Reveal.configure({ autoSlide: 10000 });
+ Reveal.toggleAutoSlide();
+
+ start();
+
+ // cleanup
+ Reveal.configure({ autoSlide: 0 });
+ Reveal.removeEventListener( 'autoslidepaused', _onEvent );
+ });
+
+ asyncTest( 'autoslideresumed', function() {
+ expect( 1 );
+
+ var _onEvent = function( event ) {
+ ok( true, 'event fired' );
+ }
+
+ Reveal.addEventListener( 'autoslideresumed', _onEvent );
+ Reveal.configure({ autoSlide: 10000 });
+ Reveal.toggleAutoSlide();
+ Reveal.toggleAutoSlide();
+
+ start();
+
+ // cleanup
+ Reveal.configure({ autoSlide: 0 });
+ Reveal.removeEventListener( 'autoslideresumed', _onEvent );
+ });
+
+
+ // ---------------------------------------------------------------
// CONFIGURATION VALUES
QUnit.module( 'Configuration' );
@@ -372,6 +495,42 @@ Reveal.addEventListener( 'ready', function() {
// ---------------------------------------------------------------
+ // LAZY-LOADING TESTS
+
+ QUnit.module( 'Lazy-Loading' );
+
+ test( 'img with data-src', function() {
+ strictEqual( document.querySelectorAll( '.reveal section img[src]' ).length, 1, 'Image source has been set' );
+ });
+
+ test( 'video with data-src', function() {
+ strictEqual( document.querySelectorAll( '.reveal section video[src]' ).length, 1, 'Video source has been set' );
+ });
+
+ test( 'audio with data-src', function() {
+ strictEqual( document.querySelectorAll( '.reveal section audio[src]' ).length, 1, 'Audio source has been set' );
+ });
+
+ test( 'iframe with data-src', function() {
+ Reveal.slide( 0, 0 );
+ strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
+ Reveal.slide( 2, 1 );
+ strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 1, 'Iframe source is set' );
+ Reveal.slide( 2, 2 );
+ strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
+ });
+
+ test( 'background images', function() {
+ var imageSource1 = Reveal.getSlide( 0 ).getAttribute( 'data-background-image' );
+ var imageSource2 = Reveal.getSlide( 1, 0 ).getAttribute( 'data-background' );
+
+ // check that the images are applied to the background elements
+ ok( Reveal.getSlideBackground( 0 ).style.backgroundImage.indexOf( imageSource1 ) !== -1, 'data-background-image worked' );
+ ok( Reveal.getSlideBackground( 1, 0 ).style.backgroundImage.indexOf( imageSource2 ) !== -1, 'data-background worked' );
+ });
+
+
+ // ---------------------------------------------------------------
// EVENT TESTS
QUnit.module( 'Events' );