From bb522c6efd9a02e611014038566b15feb28da0c8 Mon Sep 17 00:00:00 2001 From: Morgan Richomme Date: Mon, 23 May 2016 14:40:54 +0200 Subject: Add framework for presentations Change-Id: I8ba24fb4b2a3a6c8d8c69f15a1fd9259aea4ab6c Signed-off-by: Morgan Richomme --- docs/com/test/test.js | 597 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 597 insertions(+) create mode 100755 docs/com/test/test.js (limited to 'docs/com/test/test.js') diff --git a/docs/com/test/test.js b/docs/com/test/test.js new file mode 100755 index 000000000..a96b70b3d --- /dev/null +++ b/docs/com/test/test.js @@ -0,0 +1,597 @@ + +// These tests expect the DOM to contain a presentation +// with the following slide structure: +// +// 1 +// 2 - Three sub-slides +// 3 - Three fragment elements +// 3 - Two fragments with same data-fragment-index +// 4 + + +Reveal.addEventListener( 'ready', function() { + + // --------------------------------------------------------------- + // DOM TESTS + + QUnit.module( 'DOM' ); + + test( 'Initial slides classes', function() { + var horizontalSlides = document.querySelectorAll( '.reveal .slides>section' ) + + strictEqual( document.querySelectorAll( '.reveal .slides section.past' ).length, 0, 'no .past slides' ); + strictEqual( document.querySelectorAll( '.reveal .slides section.present' ).length, 1, 'one .present slide' ); + strictEqual( document.querySelectorAll( '.reveal .slides>section.future' ).length, horizontalSlides.length - 1, 'remaining horizontal slides are .future' ); + + strictEqual( document.querySelectorAll( '.reveal .slides section.stack' ).length, 2, 'two .stacks' ); + + ok( document.querySelectorAll( '.reveal .slides section.stack' )[0].querySelectorAll( '.future' ).length > 0, 'vertical slides are given .future' ); + }); + + // --------------------------------------------------------------- + // API TESTS + + QUnit.module( 'API' ); + + test( 'Reveal.isReady', function() { + strictEqual( Reveal.isReady(), true, 'returns true' ); + }); + + test( 'Reveal.isOverview', function() { + strictEqual( Reveal.isOverview(), false, 'false by default' ); + + Reveal.toggleOverview(); + strictEqual( Reveal.isOverview(), true, 'true after toggling on' ); + + Reveal.toggleOverview(); + strictEqual( Reveal.isOverview(), false, 'false after toggling off' ); + }); + + test( 'Reveal.isPaused', function() { + strictEqual( Reveal.isPaused(), false, 'false by default' ); + + Reveal.togglePause(); + strictEqual( Reveal.isPaused(), true, 'true after pausing' ); + + Reveal.togglePause(); + strictEqual( Reveal.isPaused(), false, 'false after resuming' ); + }); + + test( 'Reveal.isFirstSlide', function() { + Reveal.slide( 0, 0 ); + strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' ); + + Reveal.slide( 1, 0 ); + strictEqual( Reveal.isFirstSlide(), false, 'false after Reveal.slide( 1, 0 )' ); + + Reveal.slide( 0, 0 ); + 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 )' ); + + var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1; + + Reveal.slide( lastSlideIndex, 0 ); + 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( indices.hasOwnProperty( 'h' ), 'h exists' ); + ok( indices.hasOwnProperty( 'v' ), 'v exists' ); + ok( indices.hasOwnProperty( 'f' ), 'f exists' ); + + Reveal.slide( 1, 0 ); + strictEqual( Reveal.getIndices().h, 1, 'h 1' ); + strictEqual( Reveal.getIndices().v, 0, 'v 0' ); + + Reveal.slide( 1, 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() { + 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' ); + + 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.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