test.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. // These tests expect the DOM to contain a presentation
  2. // with the following slide structure:
  3. //
  4. // 1
  5. // 2 - Three sub-slides
  6. // 3 - Three fragment elements
  7. // 3 - Two fragments with same data-fragment-index
  8. // 4
  9. Reveal.addEventListener( 'ready', function() {
  10. // ---------------------------------------------------------------
  11. // DOM TESTS
  12. QUnit.module( 'DOM' );
  13. QUnit.test( 'Initial slides classes', function( assert ) {
  14. var horizontalSlides = document.querySelectorAll( '.reveal .slides>section' )
  15. assert.strictEqual( document.querySelectorAll( '.reveal .slides section.past' ).length, 0, 'no .past slides' );
  16. assert.strictEqual( document.querySelectorAll( '.reveal .slides section.present' ).length, 1, 'one .present slide' );
  17. assert.strictEqual( document.querySelectorAll( '.reveal .slides>section.future' ).length, horizontalSlides.length - 1, 'remaining horizontal slides are .future' );
  18. assert.strictEqual( document.querySelectorAll( '.reveal .slides section.stack' ).length, 2, 'two .stacks' );
  19. assert.ok( document.querySelectorAll( '.reveal .slides section.stack' )[0].querySelectorAll( '.future' ).length > 0, 'vertical slides are given .future' );
  20. });
  21. // ---------------------------------------------------------------
  22. // API TESTS
  23. QUnit.module( 'API' );
  24. QUnit.test( 'Reveal.isReady', function( assert ) {
  25. assert.strictEqual( Reveal.isReady(), true, 'returns true' );
  26. });
  27. QUnit.test( 'Reveal.isOverview', function( assert ) {
  28. assert.strictEqual( Reveal.isOverview(), false, 'false by default' );
  29. Reveal.toggleOverview();
  30. assert.strictEqual( Reveal.isOverview(), true, 'true after toggling on' );
  31. Reveal.toggleOverview();
  32. assert.strictEqual( Reveal.isOverview(), false, 'false after toggling off' );
  33. });
  34. QUnit.test( 'Reveal.isPaused', function( assert ) {
  35. assert.strictEqual( Reveal.isPaused(), false, 'false by default' );
  36. Reveal.togglePause();
  37. assert.strictEqual( Reveal.isPaused(), true, 'true after pausing' );
  38. Reveal.togglePause();
  39. assert.strictEqual( Reveal.isPaused(), false, 'false after resuming' );
  40. });
  41. QUnit.test( 'Reveal.isFirstSlide', function( assert ) {
  42. Reveal.slide( 0, 0 );
  43. assert.strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' );
  44. Reveal.slide( 1, 0 );
  45. assert.strictEqual( Reveal.isFirstSlide(), false, 'false after Reveal.slide( 1, 0 )' );
  46. Reveal.slide( 0, 0 );
  47. assert.strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' );
  48. });
  49. QUnit.test( 'Reveal.isFirstSlide after vertical slide', function( assert ) {
  50. Reveal.slide( 1, 1 );
  51. Reveal.slide( 0, 0 );
  52. assert.strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( 0, 0 )' );
  53. });
  54. QUnit.test( 'Reveal.isLastSlide', function( assert ) {
  55. Reveal.slide( 0, 0 );
  56. assert.strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
  57. var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
  58. Reveal.slide( lastSlideIndex, 0 );
  59. assert.strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( '+ lastSlideIndex +', 0 )' );
  60. Reveal.slide( 0, 0 );
  61. assert.strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
  62. });
  63. QUnit.test( 'Reveal.isLastSlide after vertical slide', function( assert ) {
  64. var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
  65. Reveal.slide( 1, 1 );
  66. Reveal.slide( lastSlideIndex );
  67. assert.strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( '+ lastSlideIndex +', 0 )' );
  68. });
  69. QUnit.test( 'Reveal.getTotalSlides', function( assert ) {
  70. assert.strictEqual( Reveal.getTotalSlides(), 8, 'eight slides in total' );
  71. });
  72. QUnit.test( 'Reveal.getIndices', function( assert ) {
  73. var indices = Reveal.getIndices();
  74. assert.ok( indices.hasOwnProperty( 'h' ), 'h exists' );
  75. assert.ok( indices.hasOwnProperty( 'v' ), 'v exists' );
  76. assert.ok( indices.hasOwnProperty( 'f' ), 'f exists' );
  77. Reveal.slide( 1, 0 );
  78. assert.strictEqual( Reveal.getIndices().h, 1, 'h 1' );
  79. assert.strictEqual( Reveal.getIndices().v, 0, 'v 0' );
  80. Reveal.slide( 1, 2 );
  81. assert.strictEqual( Reveal.getIndices().h, 1, 'h 1' );
  82. assert.strictEqual( Reveal.getIndices().v, 2, 'v 2' );
  83. Reveal.slide( 0, 0 );
  84. assert.strictEqual( Reveal.getIndices().h, 0, 'h 0' );
  85. assert.strictEqual( Reveal.getIndices().v, 0, 'v 0' );
  86. });
  87. QUnit.test( 'Reveal.getSlide', function( assert ) {
  88. assert.equal( Reveal.getSlide( 0 ), document.querySelector( '.reveal .slides>section:first-child' ), 'gets correct first slide' );
  89. assert.equal( Reveal.getSlide( 1 ), document.querySelector( '.reveal .slides>section:nth-child(2)' ), 'no v index returns stack' );
  90. 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' );
  91. 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' );
  92. assert.strictEqual( Reveal.getSlide( 100 ), undefined, 'undefined when out of horizontal bounds' );
  93. assert.strictEqual( Reveal.getSlide( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
  94. });
  95. QUnit.test( 'Reveal.getSlideBackground', function( assert ) {
  96. assert.equal( Reveal.getSlideBackground( 0 ), document.querySelector( '.reveal .backgrounds>.slide-background:first-child' ), 'gets correct first background' );
  97. assert.equal( Reveal.getSlideBackground( 1 ), document.querySelector( '.reveal .backgrounds>.slide-background:nth-child(2)' ), 'no v index returns stack' );
  98. 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' );
  99. 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' );
  100. assert.strictEqual( Reveal.getSlideBackground( 100 ), undefined, 'undefined when out of horizontal bounds' );
  101. assert.strictEqual( Reveal.getSlideBackground( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
  102. });
  103. QUnit.test( 'Reveal.getSlideNotes', function( assert ) {
  104. Reveal.slide( 0, 0 );
  105. assert.ok( Reveal.getSlideNotes() === 'speaker notes 1', 'works with <aside class="notes">' );
  106. Reveal.slide( 1, 0 );
  107. assert.ok( Reveal.getSlideNotes() === 'speaker notes 2', 'works with <section data-notes="">' );
  108. });
  109. QUnit.test( 'Reveal.getPreviousSlide/getCurrentSlide', function( assert ) {
  110. Reveal.slide( 0, 0 );
  111. Reveal.slide( 1, 0 );
  112. var firstSlide = document.querySelector( '.reveal .slides>section:first-child' );
  113. var secondSlide = document.querySelector( '.reveal .slides>section:nth-child(2)>section' );
  114. assert.equal( Reveal.getPreviousSlide(), firstSlide, 'previous is slide #0' );
  115. assert.equal( Reveal.getCurrentSlide(), secondSlide, 'current is slide #1' );
  116. });
  117. QUnit.test( 'Reveal.getProgress', function( assert ) {
  118. Reveal.slide( 0, 0 );
  119. assert.strictEqual( Reveal.getProgress(), 0, 'progress is 0 on first slide' );
  120. var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
  121. Reveal.slide( lastSlideIndex, 0 );
  122. assert.strictEqual( Reveal.getProgress(), 1, 'progress is 1 on last slide' );
  123. });
  124. QUnit.test( 'Reveal.getScale', function( assert ) {
  125. assert.ok( typeof Reveal.getScale() === 'number', 'has scale' );
  126. });
  127. QUnit.test( 'Reveal.getConfig', function( assert ) {
  128. assert.ok( typeof Reveal.getConfig() === 'object', 'has config' );
  129. });
  130. QUnit.test( 'Reveal.configure', function( assert ) {
  131. assert.strictEqual( Reveal.getConfig().loop, false, '"loop" is false to start with' );
  132. Reveal.configure({ loop: true });
  133. assert.strictEqual( Reveal.getConfig().loop, true, '"loop" has changed to true' );
  134. Reveal.configure({ loop: false, customTestValue: 1 });
  135. assert.strictEqual( Reveal.getConfig().customTestValue, 1, 'supports custom values' );
  136. });
  137. QUnit.test( 'Reveal.availableRoutes', function( assert ) {
  138. Reveal.slide( 0, 0 );
  139. assert.deepEqual( Reveal.availableRoutes(), { left: false, up: false, down: false, right: true }, 'correct for first slide' );
  140. Reveal.slide( 1, 0 );
  141. assert.deepEqual( Reveal.availableRoutes(), { left: true, up: false, down: true, right: true }, 'correct for vertical slide' );
  142. });
  143. QUnit.test( 'Reveal.next', function( assert ) {
  144. Reveal.slide( 0, 0 );
  145. // Step through vertical child slides
  146. Reveal.next();
  147. assert.deepEqual( Reveal.getIndices(), { h: 1, v: 0, f: undefined } );
  148. Reveal.next();
  149. assert.deepEqual( Reveal.getIndices(), { h: 1, v: 1, f: undefined } );
  150. Reveal.next();
  151. assert.deepEqual( Reveal.getIndices(), { h: 1, v: 2, f: undefined } );
  152. // Step through fragments
  153. Reveal.next();
  154. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: -1 } );
  155. Reveal.next();
  156. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 } );
  157. Reveal.next();
  158. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 } );
  159. Reveal.next();
  160. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 } );
  161. });
  162. QUnit.test( 'Reveal.next at end', function( assert ) {
  163. Reveal.slide( 3 );
  164. // We're at the end, this should have no effect
  165. Reveal.next();
  166. assert.deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
  167. Reveal.next();
  168. assert.deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
  169. });
  170. // ---------------------------------------------------------------
  171. // FRAGMENT TESTS
  172. QUnit.module( 'Fragments' );
  173. QUnit.test( 'Sliding to fragments', function( assert ) {
  174. Reveal.slide( 2, 0, -1 );
  175. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: -1 }, 'Reveal.slide( 2, 0, -1 )' );
  176. Reveal.slide( 2, 0, 0 );
  177. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'Reveal.slide( 2, 0, 0 )' );
  178. Reveal.slide( 2, 0, 2 );
  179. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'Reveal.slide( 2, 0, 2 )' );
  180. Reveal.slide( 2, 0, 1 );
  181. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'Reveal.slide( 2, 0, 1 )' );
  182. });
  183. QUnit.test( 'data-fragment is set on slide <section>', function( assert ) {
  184. Reveal.slide( 2, 0, -1 );
  185. assert.deepEqual( Reveal.getCurrentSlide().getAttribute( 'data-fragment' ), '-1' );
  186. Reveal.slide( 2, 0, 2 );
  187. assert.deepEqual( Reveal.getCurrentSlide().getAttribute( 'data-fragment' ), '2' );
  188. Reveal.slide( 2, 0, 0 );
  189. assert.deepEqual( Reveal.getCurrentSlide().getAttribute( 'data-fragment' ), '0' );
  190. var fragmentSlide = Reveal.getCurrentSlide();
  191. Reveal.slide( 3, 0 );
  192. assert.deepEqual( fragmentSlide.getAttribute( 'data-fragment' ), '0', 'data-fragment persists when jumping to another slide' );
  193. });
  194. QUnit.test( 'Hiding all fragments', function( assert ) {
  195. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  196. Reveal.slide( 2, 0, 0 );
  197. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 1, 'one fragment visible when index is 0' );
  198. Reveal.slide( 2, 0, -1 );
  199. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 0, 'no fragments visible when index is -1' );
  200. });
  201. QUnit.test( 'Current fragment', function( assert ) {
  202. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  203. var lastFragmentIndex = [].slice.call( fragmentSlide.querySelectorAll( '.fragment' ) ).pop().getAttribute( 'data-fragment-index' );
  204. Reveal.slide( 2, 0 );
  205. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment at index -1' );
  206. Reveal.slide( 2, 0, 0 );
  207. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 1, 'one current fragment at index 0' );
  208. Reveal.slide( 1, 0, 0 );
  209. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment when navigating to previous slide' );
  210. Reveal.slide( 3, 0, 0 );
  211. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment when navigating to next slide' );
  212. Reveal.slide( 2, 1, -1 );
  213. Reveal.prev();
  214. assert.strictEqual( fragmentSlide.querySelector( '.fragment.current-fragment' ).getAttribute( 'data-fragment-index' ), lastFragmentIndex, 'last fragment is current fragment when returning from future slide' );
  215. });
  216. QUnit.test( 'Stepping through fragments', function( assert ) {
  217. Reveal.slide( 2, 0, -1 );
  218. // forwards:
  219. Reveal.next();
  220. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'next() goes to next fragment' );
  221. Reveal.right();
  222. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'right() goes to next fragment' );
  223. Reveal.down();
  224. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'down() goes to next fragment' );
  225. Reveal.down(); // moves to f #3
  226. // backwards:
  227. Reveal.prev();
  228. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'prev() goes to prev fragment' );
  229. Reveal.left();
  230. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'left() goes to prev fragment' );
  231. Reveal.up();
  232. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'up() goes to prev fragment' );
  233. });
  234. QUnit.test( 'Stepping past fragments', function( assert ) {
  235. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  236. Reveal.slide( 0, 0, 0 );
  237. assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 0, 'no fragments visible when on previous slide' );
  238. Reveal.slide( 3, 0, 0 );
  239. assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 3, 'all fragments visible when on future slide' );
  240. });
  241. QUnit.test( 'Fragment indices', function( assert ) {
  242. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(2)' );
  243. Reveal.slide( 3, 0, 0 );
  244. assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 2, 'both fragments of same index are shown' );
  245. // This slide has three fragments, first one is index 0, second and third have index 1
  246. Reveal.slide( 2, 2, 0 );
  247. assert.equal( Reveal.getIndices().f, 0, 'returns correct index for first fragment' );
  248. Reveal.slide( 2, 2, 1 );
  249. assert.equal( Reveal.getIndices().f, 1, 'returns correct index for two fragments with same index' );
  250. });
  251. QUnit.test( 'Index generation', function( assert ) {
  252. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  253. // These have no indices defined to start with
  254. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[0].getAttribute( 'data-fragment-index' ), '0' );
  255. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[1].getAttribute( 'data-fragment-index' ), '1' );
  256. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[2].getAttribute( 'data-fragment-index' ), '2' );
  257. });
  258. QUnit.test( 'Index normalization', function( assert ) {
  259. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(3)' );
  260. // These start out as 1-4-4 and should normalize to 0-1-1
  261. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[0].getAttribute( 'data-fragment-index' ), '0' );
  262. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[1].getAttribute( 'data-fragment-index' ), '1' );
  263. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[2].getAttribute( 'data-fragment-index' ), '1' );
  264. });
  265. QUnit.test( 'fragmentshown event', function( assert ) {
  266. assert.expect( 2 );
  267. var done = assert.async( 2 );
  268. var _onEvent = function( event ) {
  269. assert.ok( true, 'event fired' );
  270. done();
  271. }
  272. Reveal.addEventListener( 'fragmentshown', _onEvent );
  273. Reveal.slide( 2, 0 );
  274. Reveal.slide( 2, 0 ); // should do nothing
  275. Reveal.slide( 2, 0, 0 ); // should do nothing
  276. Reveal.next();
  277. Reveal.next();
  278. Reveal.prev(); // shouldn't fire fragmentshown
  279. Reveal.removeEventListener( 'fragmentshown', _onEvent );
  280. });
  281. QUnit.test( 'fragmenthidden event', function( assert ) {
  282. assert.expect( 2 );
  283. var done = assert.async( 2 );
  284. var _onEvent = function( event ) {
  285. assert.ok( true, 'event fired' );
  286. done();
  287. }
  288. Reveal.addEventListener( 'fragmenthidden', _onEvent );
  289. Reveal.slide( 2, 0, 2 );
  290. Reveal.slide( 2, 0, 2 ); // should do nothing
  291. Reveal.prev();
  292. Reveal.prev();
  293. Reveal.next(); // shouldn't fire fragmenthidden
  294. Reveal.removeEventListener( 'fragmenthidden', _onEvent );
  295. });
  296. // ---------------------------------------------------------------
  297. // AUTO-SLIDE TESTS
  298. QUnit.module( 'Auto Sliding' );
  299. QUnit.test( 'Reveal.isAutoSliding', function( assert ) {
  300. assert.strictEqual( Reveal.isAutoSliding(), false, 'false by default' );
  301. Reveal.configure({ autoSlide: 10000 });
  302. assert.strictEqual( Reveal.isAutoSliding(), true, 'true after starting' );
  303. Reveal.configure({ autoSlide: 0 });
  304. assert.strictEqual( Reveal.isAutoSliding(), false, 'false after setting to 0' );
  305. });
  306. QUnit.test( 'Reveal.toggleAutoSlide', function( assert ) {
  307. Reveal.configure({ autoSlide: 10000 });
  308. Reveal.toggleAutoSlide();
  309. assert.strictEqual( Reveal.isAutoSliding(), false, 'false after first toggle' );
  310. Reveal.toggleAutoSlide();
  311. assert.strictEqual( Reveal.isAutoSliding(), true, 'true after second toggle' );
  312. Reveal.configure({ autoSlide: 0 });
  313. });
  314. QUnit.test( 'autoslidepaused', function( assert ) {
  315. assert.expect( 1 );
  316. var done = assert.async();
  317. var _onEvent = function( event ) {
  318. assert.ok( true, 'event fired' );
  319. done();
  320. }
  321. Reveal.addEventListener( 'autoslidepaused', _onEvent );
  322. Reveal.configure({ autoSlide: 10000 });
  323. Reveal.toggleAutoSlide();
  324. // cleanup
  325. Reveal.configure({ autoSlide: 0 });
  326. Reveal.removeEventListener( 'autoslidepaused', _onEvent );
  327. });
  328. QUnit.test( 'autoslideresumed', function( assert ) {
  329. assert.expect( 1 );
  330. var done = assert.async();
  331. var _onEvent = function( event ) {
  332. assert.ok( true, 'event fired' );
  333. done();
  334. }
  335. Reveal.addEventListener( 'autoslideresumed', _onEvent );
  336. Reveal.configure({ autoSlide: 10000 });
  337. Reveal.toggleAutoSlide();
  338. Reveal.toggleAutoSlide();
  339. // cleanup
  340. Reveal.configure({ autoSlide: 0 });
  341. Reveal.removeEventListener( 'autoslideresumed', _onEvent );
  342. });
  343. // ---------------------------------------------------------------
  344. // CONFIGURATION VALUES
  345. QUnit.module( 'Configuration' );
  346. QUnit.test( 'Controls', function( assert ) {
  347. var controlsElement = document.querySelector( '.reveal>.controls' );
  348. Reveal.configure({ controls: false });
  349. assert.equal( controlsElement.style.display, 'none', 'controls are hidden' );
  350. Reveal.configure({ controls: true });
  351. assert.equal( controlsElement.style.display, 'block', 'controls are visible' );
  352. });
  353. QUnit.test( 'Progress', function( assert ) {
  354. var progressElement = document.querySelector( '.reveal>.progress' );
  355. Reveal.configure({ progress: false });
  356. assert.equal( progressElement.style.display, 'none', 'progress are hidden' );
  357. Reveal.configure({ progress: true });
  358. assert.equal( progressElement.style.display, 'block', 'progress are visible' );
  359. });
  360. QUnit.test( 'Loop', function( assert ) {
  361. Reveal.configure({ loop: true });
  362. Reveal.slide( 0, 0 );
  363. Reveal.left();
  364. assert.notEqual( Reveal.getIndices().h, 0, 'looped from start to end' );
  365. Reveal.right();
  366. assert.equal( Reveal.getIndices().h, 0, 'looped from end to start' );
  367. Reveal.configure({ loop: false });
  368. });
  369. // ---------------------------------------------------------------
  370. // LAZY-LOADING TESTS
  371. QUnit.module( 'Lazy-Loading' );
  372. QUnit.test( 'img with data-src', function( assert ) {
  373. assert.strictEqual( document.querySelectorAll( '.reveal section img[src]' ).length, 1, 'Image source has been set' );
  374. });
  375. QUnit.test( 'video with data-src', function( assert ) {
  376. assert.strictEqual( document.querySelectorAll( '.reveal section video[src]' ).length, 1, 'Video source has been set' );
  377. });
  378. QUnit.test( 'audio with data-src', function( assert ) {
  379. assert.strictEqual( document.querySelectorAll( '.reveal section audio[src]' ).length, 1, 'Audio source has been set' );
  380. });
  381. QUnit.test( 'iframe with data-src', function( assert ) {
  382. Reveal.slide( 0, 0 );
  383. assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
  384. Reveal.slide( 2, 1 );
  385. assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 1, 'Iframe source is set' );
  386. Reveal.slide( 2, 2 );
  387. assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
  388. });
  389. QUnit.test( 'background images', function( assert ) {
  390. var imageSource1 = Reveal.getSlide( 0 ).getAttribute( 'data-background-image' );
  391. var imageSource2 = Reveal.getSlide( 1, 0 ).getAttribute( 'data-background' );
  392. // check that the images are applied to the background elements
  393. assert.ok( Reveal.getSlideBackground( 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource1 ) !== -1, 'data-background-image worked' );
  394. assert.ok( Reveal.getSlideBackground( 1, 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource2 ) !== -1, 'data-background worked' );
  395. });
  396. // ---------------------------------------------------------------
  397. // EVENT TESTS
  398. QUnit.module( 'Events' );
  399. QUnit.test( 'slidechanged', function( assert ) {
  400. assert.expect( 3 );
  401. var done = assert.async( 3 );
  402. var _onEvent = function( event ) {
  403. assert.ok( true, 'event fired' );
  404. done();
  405. }
  406. Reveal.addEventListener( 'slidechanged', _onEvent );
  407. Reveal.slide( 1, 0 ); // should trigger
  408. Reveal.slide( 1, 0 ); // should do nothing
  409. Reveal.next(); // should trigger
  410. Reveal.slide( 3, 0 ); // should trigger
  411. Reveal.next(); // should do nothing
  412. Reveal.removeEventListener( 'slidechanged', _onEvent );
  413. });
  414. QUnit.test( 'paused', function( assert ) {
  415. assert.expect( 1 );
  416. var done = assert.async();
  417. var _onEvent = function( event ) {
  418. assert.ok( true, 'event fired' );
  419. done();
  420. }
  421. Reveal.addEventListener( 'paused', _onEvent );
  422. Reveal.togglePause();
  423. Reveal.togglePause();
  424. Reveal.removeEventListener( 'paused', _onEvent );
  425. });
  426. QUnit.test( 'resumed', function( assert ) {
  427. assert.expect( 1 );
  428. var done = assert.async();
  429. var _onEvent = function( event ) {
  430. assert.ok( true, 'event fired' );
  431. done();
  432. }
  433. Reveal.addEventListener( 'resumed', _onEvent );
  434. Reveal.togglePause();
  435. Reveal.togglePause();
  436. Reveal.removeEventListener( 'resumed', _onEvent );
  437. });
  438. } );
  439. Reveal.initialize();