2013-08-23 02:27:41 +02:00
// These tests expect the DOM to contain a presentation
// with the following slide structure:
//
// 1
// 2 - Three sub-slides
// 3 - Three fragment elements
2013-11-25 20:45:14 +01:00
// 3 - Two fragments with same data-fragment-index
2013-08-23 02:27:41 +02:00
// 4
2013-08-23 01:03:11 +02:00
Reveal . addEventListener ( 'ready' , function ( ) {
2013-11-28 17:31:16 +01:00
// ---------------------------------------------------------------
// DOM TESTS
QUnit . module ( 'DOM' ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Initial slides classes' , function ( assert ) {
2013-11-28 17:31:16 +01:00
var horizontalSlides = document . querySelectorAll ( '.reveal .slides>section' )
2018-01-22 15:35:15 +01:00
assert . strictEqual ( document . querySelectorAll ( '.reveal .slides section.past' ) . length , 0 , 'no .past slides' ) ;
assert . strictEqual ( document . querySelectorAll ( '.reveal .slides section.present' ) . length , 1 , 'one .present slide' ) ;
assert . strictEqual ( document . querySelectorAll ( '.reveal .slides>section.future' ) . length , horizontalSlides . length - 1 , 'remaining horizontal slides are .future' ) ;
2013-11-28 17:31:16 +01:00
2018-01-22 15:35:15 +01:00
assert . strictEqual ( document . querySelectorAll ( '.reveal .slides section.stack' ) . length , 2 , 'two .stacks' ) ;
2013-11-28 17:31:16 +01:00
2018-01-22 15:35:15 +01:00
assert . ok ( document . querySelectorAll ( '.reveal .slides section.stack' ) [ 0 ] . querySelectorAll ( '.future' ) . length > 0 , 'vertical slides are given .future' ) ;
2013-11-28 17:31:16 +01:00
} ) ;
2013-08-23 01:51:00 +02:00
// ---------------------------------------------------------------
// API TESTS
2013-08-23 01:03:11 +02:00
QUnit . module ( 'API' ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.isReady' , function ( assert ) {
assert . strictEqual ( Reveal . isReady ( ) , true , 'returns true' ) ;
2013-08-23 01:03:11 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.isOverview' , function ( assert ) {
assert . strictEqual ( Reveal . isOverview ( ) , false , 'false by default' ) ;
2013-08-23 01:03:11 +02:00
Reveal . toggleOverview ( ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isOverview ( ) , true , 'true after toggling on' ) ;
2013-08-23 01:03:11 +02:00
Reveal . toggleOverview ( ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isOverview ( ) , false , 'false after toggling off' ) ;
2013-08-23 01:03:11 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.isPaused' , function ( assert ) {
assert . strictEqual ( Reveal . isPaused ( ) , false , 'false by default' ) ;
2013-08-23 01:03:11 +02:00
Reveal . togglePause ( ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isPaused ( ) , true , 'true after pausing' ) ;
2013-08-23 01:03:11 +02:00
Reveal . togglePause ( ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isPaused ( ) , false , 'false after resuming' ) ;
2013-08-23 01:03:11 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.isFirstSlide' , function ( assert ) {
2013-08-23 02:09:40 +02:00
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isFirstSlide ( ) , true , 'true after Reveal.slide( 0, 0 )' ) ;
2013-08-23 01:03:11 +02:00
2013-08-23 02:09:40 +02:00
Reveal . slide ( 1 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isFirstSlide ( ) , false , 'false after Reveal.slide( 1, 0 )' ) ;
2013-08-23 01:03:11 +02:00
2013-08-23 02:09:40 +02:00
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isFirstSlide ( ) , true , 'true after Reveal.slide( 0, 0 )' ) ;
2013-08-23 01:03:11 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.isFirstSlide after vertical slide' , function ( assert ) {
2014-05-09 17:28:53 +02:00
Reveal . slide ( 1 , 1 ) ;
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isFirstSlide ( ) , true , 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( 0, 0 )' ) ;
2014-05-09 17:28:53 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.isLastSlide' , function ( assert ) {
2013-08-23 02:09:40 +02:00
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isLastSlide ( ) , false , 'false after Reveal.slide( 0, 0 )' ) ;
2013-08-23 01:03:11 +02:00
2013-08-23 01:46:35 +02:00
var lastSlideIndex = document . querySelectorAll ( '.reveal .slides>section' ) . length - 1 ;
2013-08-23 02:09:40 +02:00
Reveal . slide ( lastSlideIndex , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isLastSlide ( ) , true , 'true after Reveal.slide( ' + lastSlideIndex + ', 0 )' ) ;
2013-08-23 01:03:11 +02:00
2013-08-23 02:09:40 +02:00
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isLastSlide ( ) , false , 'false after Reveal.slide( 0, 0 )' ) ;
2013-08-23 01:03:11 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.isLastSlide after vertical slide' , function ( assert ) {
2014-05-09 17:28:53 +02:00
var lastSlideIndex = document . querySelectorAll ( '.reveal .slides>section' ) . length - 1 ;
2015-09-10 08:28:52 +02:00
2014-05-09 17:28:53 +02:00
Reveal . slide ( 1 , 1 ) ;
2014-05-09 19:23:25 +02:00
Reveal . slide ( lastSlideIndex ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isLastSlide ( ) , true , 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( ' + lastSlideIndex + ', 0 )' ) ;
2014-05-09 17:28:53 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.getTotalSlides' , function ( assert ) {
assert . strictEqual ( Reveal . getTotalSlides ( ) , 8 , 'eight slides in total' ) ;
2014-04-01 09:14:29 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.getIndices' , function ( assert ) {
2013-08-23 01:03:11 +02:00
var indices = Reveal . getIndices ( ) ;
2018-01-22 15:35:15 +01:00
assert . ok ( indices . hasOwnProperty ( 'h' ) , 'h exists' ) ;
assert . ok ( indices . hasOwnProperty ( 'v' ) , 'v exists' ) ;
assert . ok ( indices . hasOwnProperty ( 'f' ) , 'f exists' ) ;
2013-08-23 01:03:11 +02:00
2013-08-23 02:09:40 +02:00
Reveal . slide ( 1 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . getIndices ( ) . h , 1 , 'h 1' ) ;
assert . strictEqual ( Reveal . getIndices ( ) . v , 0 , 'v 0' ) ;
2013-08-23 01:03:11 +02:00
Reveal . slide ( 1 , 2 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . getIndices ( ) . h , 1 , 'h 1' ) ;
assert . strictEqual ( Reveal . getIndices ( ) . v , 2 , 'v 2' ) ;
2013-08-23 01:03:11 +02:00
2013-08-23 02:09:40 +02:00
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . getIndices ( ) . h , 0 , 'h 0' ) ;
assert . strictEqual ( Reveal . getIndices ( ) . v , 0 , 'v 0' ) ;
2013-08-23 02:09:40 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.getSlide' , function ( assert ) {
assert . equal ( Reveal . getSlide ( 0 ) , document . querySelector ( '.reveal .slides>section:first-child' ) , 'gets correct first slide' ) ;
assert . equal ( Reveal . getSlide ( 1 ) , document . querySelector ( '.reveal .slides>section:nth-child(2)' ) , 'no v index returns stack' ) ;
assert . equal ( Reveal . getSlide ( 1 , 0 ) , document . querySelector ( '.reveal .slides>section:nth-child(2)>section:nth-child(1)' ) , 'v index 0 returns first vertical child' ) ;
assert . equal ( Reveal . getSlide ( 1 , 1 ) , document . querySelector ( '.reveal .slides>section:nth-child(2)>section:nth-child(2)' ) , 'v index 1 returns second vertical child' ) ;
2013-08-23 02:09:40 +02:00
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . getSlide ( 100 ) , undefined , 'undefined when out of horizontal bounds' ) ;
assert . strictEqual ( Reveal . getSlide ( 1 , 100 ) , undefined , 'undefined when out of vertical bounds' ) ;
2013-08-23 02:09:40 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.getSlideBackground' , function ( assert ) {
assert . equal ( Reveal . getSlideBackground ( 0 ) , document . querySelector ( '.reveal .backgrounds>.slide-background:first-child' ) , 'gets correct first background' ) ;
assert . equal ( Reveal . getSlideBackground ( 1 ) , document . querySelector ( '.reveal .backgrounds>.slide-background:nth-child(2)' ) , 'no v index returns stack' ) ;
2018-04-27 15:53:02 +02:00
assert . equal ( Reveal . getSlideBackground ( 1 , 0 ) , document . querySelector ( '.reveal .backgrounds>.slide-background:nth-child(2) .slide-background:nth-child(2)' ) , 'v index 0 returns first vertical child' ) ;
assert . equal ( Reveal . getSlideBackground ( 1 , 1 ) , document . querySelector ( '.reveal .backgrounds>.slide-background:nth-child(2) .slide-background:nth-child(3)' ) , 'v index 1 returns second vertical child' ) ;
2014-04-27 14:46:49 +02:00
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . getSlideBackground ( 100 ) , undefined , 'undefined when out of horizontal bounds' ) ;
assert . strictEqual ( Reveal . getSlideBackground ( 1 , 100 ) , undefined , 'undefined when out of vertical bounds' ) ;
2014-04-27 14:46:49 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.getSlideNotes' , function ( assert ) {
2015-09-10 08:28:52 +02:00
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . ok ( Reveal . getSlideNotes ( ) === 'speaker notes 1' , 'works with <aside class="notes">' ) ;
2015-09-10 08:28:52 +02:00
Reveal . slide ( 1 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . ok ( Reveal . getSlideNotes ( ) === 'speaker notes 2' , 'works with <section data-notes="">' ) ;
2015-09-10 08:28:52 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.getPreviousSlide/getCurrentSlide' , function ( assert ) {
2013-08-23 02:09:40 +02:00
Reveal . slide ( 0 , 0 ) ;
Reveal . slide ( 1 , 0 ) ;
var firstSlide = document . querySelector ( '.reveal .slides>section:first-child' ) ;
var secondSlide = document . querySelector ( '.reveal .slides>section:nth-child(2)>section' ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( Reveal . getPreviousSlide ( ) , firstSlide , 'previous is slide #0' ) ;
assert . equal ( Reveal . getCurrentSlide ( ) , secondSlide , 'current is slide #1' ) ;
2013-08-23 01:03:11 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.getProgress' , function ( assert ) {
2014-03-12 22:29:01 +01:00
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . getProgress ( ) , 0 , 'progress is 0 on first slide' ) ;
2014-03-12 22:29:01 +01:00
var lastSlideIndex = document . querySelectorAll ( '.reveal .slides>section' ) . length - 1 ;
Reveal . slide ( lastSlideIndex , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . getProgress ( ) , 1 , 'progress is 1 on last slide' ) ;
2014-03-12 22:29:01 +01:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.getScale' , function ( assert ) {
assert . ok ( typeof Reveal . getScale ( ) === 'number' , 'has scale' ) ;
2013-08-23 01:03:11 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.getConfig' , function ( assert ) {
assert . ok ( typeof Reveal . getConfig ( ) === 'object' , 'has config' ) ;
2013-08-23 01:03:11 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.configure' , function ( assert ) {
assert . strictEqual ( Reveal . getConfig ( ) . loop , false , '"loop" is false to start with' ) ;
2013-08-23 01:51:00 +02:00
Reveal . configure ( { loop : true } ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . getConfig ( ) . loop , true , '"loop" has changed to true' ) ;
2013-08-23 01:51:00 +02:00
Reveal . configure ( { loop : false , customTestValue : 1 } ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . getConfig ( ) . customTestValue , 1 , 'supports custom values' ) ;
2013-08-23 01:51:00 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.availableRoutes' , function ( assert ) {
2013-08-23 02:09:40 +02:00
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . availableRoutes ( ) , { left : false , up : false , down : false , right : true } , 'correct for first slide' ) ;
2013-08-23 21:36:16 +02:00
Reveal . slide ( 1 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . availableRoutes ( ) , { left : true , up : false , down : true , right : true } , 'correct for vertical slide' ) ;
2013-08-23 02:09:40 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.next' , function ( assert ) {
2013-08-23 02:27:41 +02:00
Reveal . slide ( 0 , 0 ) ;
2013-11-25 20:45:14 +01:00
// Step through vertical child slides
2013-08-23 02:27:41 +02:00
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 1 , v : 0 , f : undefined } ) ;
2013-08-23 02:27:41 +02:00
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 1 , v : 1 , f : undefined } ) ;
2013-08-23 02:27:41 +02:00
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 1 , v : 2 , f : undefined } ) ;
2013-08-23 02:27:41 +02:00
2013-11-25 20:45:14 +01:00
// Step through fragments
2013-11-21 15:01:18 +01:00
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : - 1 } ) ;
2013-11-21 15:01:18 +01:00
2013-08-23 02:27:41 +02:00
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 0 } ) ;
2013-08-23 02:27:41 +02:00
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 1 } ) ;
2013-08-23 02:27:41 +02:00
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 2 } ) ;
2013-11-25 20:45:14 +01:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.next at end' , function ( assert ) {
2013-11-25 20:45:14 +01:00
Reveal . slide ( 3 ) ;
2013-08-23 02:27:41 +02:00
2013-11-25 20:45:14 +01:00
// We're at the end, this should have no effect
2013-08-23 02:27:41 +02:00
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 3 , v : 0 , f : undefined } ) ;
2013-08-23 02:27:41 +02:00
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 3 , v : 0 , f : undefined } ) ;
2013-08-23 02:27:41 +02:00
} ) ;
2013-08-23 02:09:40 +02:00
// ---------------------------------------------------------------
2013-08-23 21:36:16 +02:00
// FRAGMENT TESTS
QUnit . module ( 'Fragments' ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Sliding to fragments' , function ( assert ) {
2013-11-23 23:13:14 +01:00
Reveal . slide ( 2 , 0 , - 1 ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : - 1 } , 'Reveal.slide( 2, 0, -1 )' ) ;
2013-11-23 23:13:14 +01:00
2013-08-23 21:36:16 +02:00
Reveal . slide ( 2 , 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 0 } , 'Reveal.slide( 2, 0, 0 )' ) ;
2013-08-23 21:36:16 +02:00
Reveal . slide ( 2 , 0 , 2 ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 2 } , 'Reveal.slide( 2, 0, 2 )' ) ;
2013-08-23 21:36:16 +02:00
Reveal . slide ( 2 , 0 , 1 ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 1 } , 'Reveal.slide( 2, 0, 1 )' ) ;
2013-08-23 21:36:16 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Hiding all fragments' , function ( assert ) {
2013-11-25 20:45:14 +01:00
var fragmentSlide = document . querySelector ( '#fragment-slides>section:nth-child(1)' ) ;
2013-11-23 23:13:14 +01:00
Reveal . slide ( 2 , 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( fragmentSlide . querySelectorAll ( '.fragment.visible' ) . length , 1 , 'one fragment visible when index is 0' ) ;
2013-11-23 23:13:14 +01:00
Reveal . slide ( 2 , 0 , - 1 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( fragmentSlide . querySelectorAll ( '.fragment.visible' ) . length , 0 , 'no fragments visible when index is -1' ) ;
2013-11-23 23:13:14 +01:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Current fragment' , function ( assert ) {
2013-11-25 20:45:14 +01:00
var fragmentSlide = document . querySelector ( '#fragment-slides>section:nth-child(1)' ) ;
2018-10-11 11:32:23 +02:00
var lastFragmentIndex = [ ] . slice . call ( fragmentSlide . querySelectorAll ( '.fragment' ) ) . pop ( ) . getAttribute ( 'data-fragment-index' ) ;
2013-11-23 23:13:14 +01:00
Reveal . slide ( 2 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( fragmentSlide . querySelectorAll ( '.fragment.current-fragment' ) . length , 0 , 'no current fragment at index -1' ) ;
2013-11-23 23:13:14 +01:00
Reveal . slide ( 2 , 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( fragmentSlide . querySelectorAll ( '.fragment.current-fragment' ) . length , 1 , 'one current fragment at index 0' ) ;
2013-11-23 23:13:14 +01:00
Reveal . slide ( 1 , 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( fragmentSlide . querySelectorAll ( '.fragment.current-fragment' ) . length , 0 , 'no current fragment when navigating to previous slide' ) ;
2013-11-23 23:13:14 +01:00
Reveal . slide ( 3 , 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( fragmentSlide . querySelectorAll ( '.fragment.current-fragment' ) . length , 0 , 'no current fragment when navigating to next slide' ) ;
2018-10-11 11:24:54 +02:00
Reveal . slide ( 2 , 1 , - 1 ) ;
Reveal . prev ( ) ;
assert . strictEqual ( fragmentSlide . querySelector ( '.fragment.current-fragment' ) . getAttribute ( 'data-fragment-index' ) , lastFragmentIndex , 'last fragment is current fragment when returning from future slide' ) ;
2013-11-23 23:13:14 +01:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Stepping through fragments' , function ( assert ) {
2013-11-21 15:01:18 +01:00
Reveal . slide ( 2 , 0 , - 1 ) ;
2013-08-23 21:36:16 +02:00
// forwards:
Reveal . next ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 0 } , 'next() goes to next fragment' ) ;
2013-08-23 21:36:16 +02:00
Reveal . right ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 1 } , 'right() goes to next fragment' ) ;
2013-08-23 21:36:16 +02:00
Reveal . down ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 2 } , 'down() goes to next fragment' ) ;
2013-08-23 21:36:16 +02:00
Reveal . down ( ) ; // moves to f #3
// backwards:
Reveal . prev ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 2 } , 'prev() goes to prev fragment' ) ;
2013-08-23 21:36:16 +02:00
Reveal . left ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 1 } , 'left() goes to prev fragment' ) ;
2013-08-23 21:36:16 +02:00
Reveal . up ( ) ;
2018-01-22 15:35:15 +01:00
assert . deepEqual ( Reveal . getIndices ( ) , { h : 2 , v : 0 , f : 0 } , 'up() goes to prev fragment' ) ;
2013-08-23 21:36:16 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Stepping past fragments' , function ( assert ) {
2013-11-25 21:26:22 +01:00
var fragmentSlide = document . querySelector ( '#fragment-slides>section:nth-child(1)' ) ;
2013-11-07 14:39:19 +01:00
Reveal . slide ( 0 , 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( fragmentSlide . querySelectorAll ( '.fragment.visible' ) . length , 0 , 'no fragments visible when on previous slide' ) ;
2013-11-07 14:39:19 +01:00
Reveal . slide ( 3 , 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( fragmentSlide . querySelectorAll ( '.fragment.visible' ) . length , 3 , 'all fragments visible when on future slide' ) ;
2013-11-07 14:39:19 +01:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Fragment indices' , function ( assert ) {
2013-11-25 20:45:14 +01:00
var fragmentSlide = document . querySelector ( '#fragment-slides>section:nth-child(2)' ) ;
Reveal . slide ( 3 , 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( fragmentSlide . querySelectorAll ( '.fragment.visible' ) . length , 2 , 'both fragments of same index are shown' ) ;
2014-09-09 12:42:11 +02:00
// This slide has three fragments, first one is index 0, second and third have index 1
Reveal . slide ( 2 , 2 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( Reveal . getIndices ( ) . f , 0 , 'returns correct index for first fragment' ) ;
2014-09-09 12:42:11 +02:00
Reveal . slide ( 2 , 2 , 1 ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( Reveal . getIndices ( ) . f , 1 , 'returns correct index for two fragments with same index' ) ;
2013-11-25 20:45:14 +01:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Index generation' , function ( assert ) {
2013-11-25 21:26:22 +01:00
var fragmentSlide = document . querySelector ( '#fragment-slides>section:nth-child(1)' ) ;
// These have no indices defined to start with
2018-01-22 15:35:15 +01:00
assert . equal ( fragmentSlide . querySelectorAll ( '.fragment' ) [ 0 ] . getAttribute ( 'data-fragment-index' ) , '0' ) ;
assert . equal ( fragmentSlide . querySelectorAll ( '.fragment' ) [ 1 ] . getAttribute ( 'data-fragment-index' ) , '1' ) ;
assert . equal ( fragmentSlide . querySelectorAll ( '.fragment' ) [ 2 ] . getAttribute ( 'data-fragment-index' ) , '2' ) ;
2013-11-25 21:26:22 +01:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Index normalization' , function ( assert ) {
2013-11-25 21:26:22 +01:00
var fragmentSlide = document . querySelector ( '#fragment-slides>section:nth-child(3)' ) ;
// These start out as 1-4-4 and should normalize to 0-1-1
2018-01-22 15:35:15 +01:00
assert . equal ( fragmentSlide . querySelectorAll ( '.fragment' ) [ 0 ] . getAttribute ( 'data-fragment-index' ) , '0' ) ;
assert . equal ( fragmentSlide . querySelectorAll ( '.fragment' ) [ 1 ] . getAttribute ( 'data-fragment-index' ) , '1' ) ;
assert . equal ( fragmentSlide . querySelectorAll ( '.fragment' ) [ 2 ] . getAttribute ( 'data-fragment-index' ) , '1' ) ;
2013-11-25 21:26:22 +01:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'fragmentshown event' , function ( assert ) {
assert . expect ( 2 ) ;
var done = a ssert . async ( 2 ) ;
2013-08-23 21:36:16 +02:00
var _onEvent = function ( event ) {
2018-01-22 15:35:15 +01:00
assert . ok ( true , 'event fired' ) ;
done ( ) ;
2013-08-23 21:36:16 +02:00
}
Reveal . addEventListener ( 'fragmentshown' , _onEvent ) ;
Reveal . slide ( 2 , 0 ) ;
Reveal . slide ( 2 , 0 ) ; // should do nothing
Reveal . slide ( 2 , 0 , 0 ) ; // should do nothing
Reveal . next ( ) ;
Reveal . next ( ) ;
Reveal . prev ( ) ; // shouldn't fire fragmentshown
Reveal . removeEventListener ( 'fragmentshown' , _onEvent ) ;
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'fragmenthidden event' , function ( assert ) {
assert . expect ( 2 ) ;
var done = assert . async ( 2 ) ;
2013-08-23 21:36:16 +02:00
var _onEvent = function ( event ) {
2018-01-22 15:35:15 +01:00
assert . ok ( true , 'event fired' ) ;
done ( ) ;
2013-08-23 21:36:16 +02:00
}
Reveal . addEventListener ( 'fragmenthidden' , _onEvent ) ;
Reveal . slide ( 2 , 0 , 2 ) ;
Reveal . slide ( 2 , 0 , 2 ) ; // should do nothing
Reveal . prev ( ) ;
Reveal . prev ( ) ;
Reveal . next ( ) ; // shouldn't fire fragmenthidden
Reveal . removeEventListener ( 'fragmenthidden' , _onEvent ) ;
} ) ;
2013-08-23 02:09:40 +02:00
2013-12-21 18:08:40 +01:00
// ---------------------------------------------------------------
// AUTO-SLIDE TESTS
QUnit . module ( 'Auto Sliding' ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.isAutoSliding' , function ( assert ) {
assert . strictEqual ( Reveal . isAutoSliding ( ) , false , 'false by default' ) ;
2013-12-21 18:08:40 +01:00
Reveal . configure ( { autoSlide : 10000 } ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isAutoSliding ( ) , true , 'true after starting' ) ;
2013-12-21 18:08:40 +01:00
Reveal . configure ( { autoSlide : 0 } ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isAutoSliding ( ) , false , 'false after setting to 0' ) ;
2013-12-21 18:08:40 +01:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Reveal.toggleAutoSlide' , function ( assert ) {
2013-12-21 18:08:40 +01:00
Reveal . configure ( { autoSlide : 10000 } ) ;
Reveal . toggleAutoSlide ( ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isAutoSliding ( ) , false , 'false after first toggle' ) ;
2013-12-21 18:08:40 +01:00
Reveal . toggleAutoSlide ( ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( Reveal . isAutoSliding ( ) , true , 'true after second toggle' ) ;
2013-12-21 18:08:40 +01:00
Reveal . configure ( { autoSlide : 0 } ) ;
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'autoslidepaused' , function ( assert ) {
assert . expect ( 1 ) ;
var done = assert . async ( ) ;
2013-12-21 18:08:40 +01:00
var _onEvent = function ( event ) {
2018-01-22 15:35:15 +01:00
assert . ok ( true , 'event fired' ) ;
done ( ) ;
2013-12-21 18:08:40 +01:00
}
Reveal . addEventListener ( 'autoslidepaused' , _onEvent ) ;
Reveal . configure ( { autoSlide : 10000 } ) ;
Reveal . toggleAutoSlide ( ) ;
// cleanup
Reveal . configure ( { autoSlide : 0 } ) ;
Reveal . removeEventListener ( 'autoslidepaused' , _onEvent ) ;
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'autoslideresumed' , function ( assert ) {
assert . expect ( 1 ) ;
var done = assert . async ( ) ;
2013-12-21 18:08:40 +01:00
var _onEvent = function ( event ) {
2018-01-22 15:35:15 +01:00
assert . ok ( true , 'event fired' ) ;
done ( ) ;
2013-12-21 18:08:40 +01:00
}
Reveal . addEventListener ( 'autoslideresumed' , _onEvent ) ;
Reveal . configure ( { autoSlide : 10000 } ) ;
Reveal . toggleAutoSlide ( ) ;
Reveal . toggleAutoSlide ( ) ;
// cleanup
Reveal . configure ( { autoSlide : 0 } ) ;
Reveal . removeEventListener ( 'autoslideresumed' , _onEvent ) ;
} ) ;
2013-08-23 02:09:40 +02:00
// ---------------------------------------------------------------
2013-08-23 02:27:41 +02:00
// CONFIGURATION VALUES
QUnit . module ( 'Configuration' ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Controls' , function ( assert ) {
2013-08-23 02:27:41 +02:00
var controlsElement = document . querySelector ( '.reveal>.controls' ) ;
Reveal . configure ( { controls : false } ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( controlsElement . style . display , 'none' , 'controls are hidden' ) ;
2013-08-23 02:27:41 +02:00
Reveal . configure ( { controls : true } ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( controlsElement . style . display , 'block' , 'controls are visible' ) ;
2013-08-23 02:27:41 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Progress' , function ( assert ) {
2013-08-23 02:27:41 +02:00
var progressElement = document . querySelector ( '.reveal>.progress' ) ;
Reveal . configure ( { progress : false } ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( progressElement . style . display , 'none' , 'progress are hidden' ) ;
2013-08-23 02:27:41 +02:00
Reveal . configure ( { progress : true } ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( progressElement . style . display , 'block' , 'progress are visible' ) ;
2013-08-23 02:27:41 +02:00
} ) ;
2013-08-23 02:09:40 +02:00
2018-01-22 15:35:15 +01:00
QUnit . test ( 'Loop' , function ( assert ) {
2013-08-23 03:38:37 +02:00
Reveal . configure ( { loop : true } ) ;
Reveal . slide ( 0 , 0 ) ;
Reveal . left ( ) ;
2018-01-22 15:35:15 +01:00
assert . notEqual ( Reveal . getIndices ( ) . h , 0 , 'looped from start to end' ) ;
2013-08-23 03:38:37 +02:00
Reveal . right ( ) ;
2018-01-22 15:35:15 +01:00
assert . equal ( Reveal . getIndices ( ) . h , 0 , 'looped from end to start' ) ;
2013-08-23 03:38:37 +02:00
Reveal . configure ( { loop : false } ) ;
} ) ;
2013-08-23 01:51:00 +02:00
2014-04-22 15:58:21 +02:00
// ---------------------------------------------------------------
// LAZY-LOADING TESTS
QUnit . module ( 'Lazy-Loading' ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'img with data-src' , function ( assert ) {
assert . strictEqual ( document . querySelectorAll ( '.reveal section img[src]' ) . length , 1 , 'Image source has been set' ) ;
2014-04-22 15:58:21 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'video with data-src' , function ( assert ) {
assert . strictEqual ( document . querySelectorAll ( '.reveal section video[src]' ) . length , 1 , 'Video source has been set' ) ;
2015-05-06 11:25:50 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'audio with data-src' , function ( assert ) {
assert . strictEqual ( document . querySelectorAll ( '.reveal section audio[src]' ) . length , 1 , 'Audio source has been set' ) ;
2015-05-06 11:25:50 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'iframe with data-src' , function ( assert ) {
2015-05-05 02:58:58 +02:00
Reveal . slide ( 0 , 0 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( document . querySelectorAll ( '.reveal section iframe[src]' ) . length , 0 , 'Iframe source is not set' ) ;
2015-05-05 02:58:58 +02:00
Reveal . slide ( 2 , 1 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( document . querySelectorAll ( '.reveal section iframe[src]' ) . length , 1 , 'Iframe source is set' ) ;
2015-05-06 11:02:41 +02:00
Reveal . slide ( 2 , 2 ) ;
2018-01-22 15:35:15 +01:00
assert . strictEqual ( document . querySelectorAll ( '.reveal section iframe[src]' ) . length , 0 , 'Iframe source is not set' ) ;
2015-05-05 02:58:58 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'background images' , function ( assert ) {
2014-04-28 11:51:35 +02:00
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
2018-04-27 15:53:02 +02:00
assert . ok ( Reveal . getSlideBackground ( 0 ) . querySelector ( '.slide-background-content' ) . style . backgroundImage . indexOf ( imageSource1 ) !== - 1 , 'data-background-image worked' ) ;
assert . ok ( Reveal . getSlideBackground ( 1 , 0 ) . querySelector ( '.slide-background-content' ) . style . backgroundImage . indexOf ( imageSource2 ) !== - 1 , 'data-background worked' ) ;
2014-04-28 11:51:35 +02:00
} ) ;
2014-04-22 15:58:21 +02:00
2013-08-23 01:51:00 +02:00
// ---------------------------------------------------------------
// EVENT TESTS
2013-08-23 01:03:11 +02:00
QUnit . module ( 'Events' ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'slidechanged' , function ( assert ) {
assert . expect ( 3 ) ;
var done = assert . async ( 3 ) ;
2013-08-23 01:03:11 +02:00
2013-08-23 21:36:16 +02:00
var _onEvent = function ( event ) {
2018-01-22 15:35:15 +01:00
assert . ok ( true , 'event fired' ) ;
done ( ) ;
2013-08-23 01:03:11 +02:00
}
2013-08-23 21:36:16 +02:00
Reveal . addEventListener ( 'slidechanged' , _onEvent ) ;
2013-08-23 01:03:11 +02:00
2013-08-23 21:57:28 +02:00
Reveal . slide ( 1 , 0 ) ; // should trigger
Reveal . slide ( 1 , 0 ) ; // should do nothing
Reveal . next ( ) ; // should trigger
Reveal . slide ( 3 , 0 ) ; // should trigger
Reveal . next ( ) ; // should do nothing
2013-08-23 01:03:11 +02:00
2013-08-23 21:36:16 +02:00
Reveal . removeEventListener ( 'slidechanged' , _onEvent ) ;
2013-08-23 01:03:11 +02:00
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'paused' , function ( assert ) {
assert . expect ( 1 ) ;
var done = assert . async ( ) ;
2013-08-23 21:57:28 +02:00
var _onEvent = function ( event ) {
2018-01-22 15:35:15 +01:00
assert . ok ( true , 'event fired' ) ;
done ( ) ;
2013-08-23 21:57:28 +02:00
}
Reveal . addEventListener ( 'paused' , _onEvent ) ;
Reveal . togglePause ( ) ;
Reveal . togglePause ( ) ;
Reveal . removeEventListener ( 'paused' , _onEvent ) ;
} ) ;
2018-01-22 15:35:15 +01:00
QUnit . test ( 'resumed' , function ( assert ) {
assert . expect ( 1 ) ;
var done = assert . async ( ) ;
2013-08-23 21:57:28 +02:00
var _onEvent = function ( event ) {
2018-01-22 15:35:15 +01:00
assert . ok ( true , 'event fired' ) ;
done ( ) ;
2013-08-23 21:57:28 +02:00
}
Reveal . addEventListener ( 'resumed' , _onEvent ) ;
Reveal . togglePause ( ) ;
Reveal . togglePause ( ) ;
Reveal . removeEventListener ( 'resumed' , _onEvent ) ;
} ) ;
2013-08-23 01:03:11 +02:00
} ) ;
Reveal . initialize ( ) ;