test.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Tests</title>
  6. <link rel="stylesheet" href="../dist/reveal.css">
  7. <link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
  8. <script src="../node_modules/qunit/qunit/qunit.js"></script>
  9. </head>
  10. <body style="overflow: auto;">
  11. <div id="qunit"></div>
  12. <div id="qunit-fixture"></div>
  13. <div class="reveal" style="visibility: hidden;">
  14. <div class="slides">
  15. <section data-visibility="hidden">
  16. This should be remove by reveal.js before our tests run.
  17. </section>
  18. <section data-background-image="examples/assets/image1.png">
  19. <h1>1</h1>
  20. <img data-src="">
  21. <video data-src=""></video>
  22. <audio data-src=""></audio>
  23. <aside class="notes">speaker notes 1</aside>
  24. </section>
  25. <section>
  26. <section data-background="examples/assets/image2.png" data-notes="speaker notes 2">
  27. <h1>2.1</h1>
  28. </section>
  29. <section data-background-image="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/">
  30. <h1>2.2</h1>
  31. </section>
  32. <section>
  33. <h1>2.3</h1>
  34. </section>
  35. </section>
  36. <section id="fragment-slides">
  37. <section>
  38. <h1>3.1</h1>
  39. <ul>
  40. <li class="fragment">4.1</li>
  41. <li class="fragment">4.2</li>
  42. <li class="fragment">4.3</li>
  43. </ul>
  44. </section>
  45. <section>
  46. <h1>3.2</h1>
  47. <ul>
  48. <li class="fragment" data-fragment-index="0">4.1</li>
  49. <li class="fragment" data-fragment-index="0">4.2</li>
  50. </ul>
  51. <iframe data-src="http://example.com"></iframe>
  52. </section>
  53. <section id="fragments3">
  54. <h1>3.3</h1>
  55. <ul>
  56. <li class="fragment" data-fragment-index="1">3.3.1</li>
  57. <li class="fragment" data-fragment-index="4">3.3.2</li>
  58. <li class="fragment" data-fragment-index="4">3.3.3</li>
  59. </ul>
  60. </section>
  61. </section>
  62. <section>
  63. <h1>4</h1>
  64. </section>
  65. </div>
  66. </div>
  67. <script src="../dist/reveal.js"></script>
  68. <script>
  69. window.location.hash = '';
  70. Reveal.configure({maxScale: 1.11});
  71. // These tests expect the DOM to contain a presentation
  72. // with the following slide structure:
  73. //
  74. // 1
  75. // 2 - Three sub-slides
  76. // 3 - Three fragment elements
  77. // 3 - Two fragments with same data-fragment-index
  78. // 4
  79. Reveal.initialize().then( function() {
  80. // Helper methods
  81. function triggerKeyboardEvent(config) {
  82. document.dispatchEvent( new KeyboardEvent( 'keydown', config ) );
  83. }
  84. // ---------------------------------------------------------------
  85. // DOM TESTS
  86. QUnit.module( 'DOM' );
  87. QUnit.test( 'Initial slides classes', function( assert ) {
  88. var horizontalSlides = document.querySelectorAll( '.reveal .slides>section' )
  89. assert.strictEqual( document.querySelectorAll( '.reveal .slides section[data-visibility="hidden"]' ).length, 0, 'no data-visibility="hidden" slides' );
  90. assert.strictEqual( document.querySelectorAll( '.reveal .slides section.past' ).length, 0, 'no .past slides' );
  91. assert.strictEqual( document.querySelectorAll( '.reveal .slides section.present' ).length, 1, 'one .present slide' );
  92. assert.strictEqual( document.querySelectorAll( '.reveal .slides>section.future' ).length, horizontalSlides.length - 1, 'remaining horizontal slides are .future' );
  93. assert.strictEqual( document.querySelectorAll( '.reveal .slides section.stack' ).length, 2, 'two .stacks' );
  94. assert.ok( document.querySelectorAll( '.reveal .slides section.stack' )[0].querySelectorAll( '.future' ).length > 0, 'vertical slides are given .future' );
  95. });
  96. // ---------------------------------------------------------------
  97. // API TESTS
  98. QUnit.module( 'API' );
  99. QUnit.test( 'Reveal.configure before initialization', function( assert ) {
  100. assert.strictEqual( Reveal.getConfig().maxScale, 1.11 );
  101. });
  102. QUnit.test( 'Reveal.isReady', function( assert ) {
  103. assert.strictEqual( Reveal.isReady(), true, 'returns true' );
  104. });
  105. QUnit.test( 'Reveal.isOverview', function( assert ) {
  106. assert.strictEqual( Reveal.isOverview(), false, 'false by default' );
  107. Reveal.toggleOverview();
  108. assert.strictEqual( Reveal.isOverview(), true, 'true after toggling on' );
  109. Reveal.toggleOverview();
  110. assert.strictEqual( Reveal.isOverview(), false, 'false after toggling off' );
  111. });
  112. QUnit.test( 'Reveal.isPaused', function( assert ) {
  113. assert.strictEqual( Reveal.isPaused(), false, 'false by default' );
  114. Reveal.togglePause();
  115. assert.strictEqual( Reveal.isPaused(), true, 'true after pausing' );
  116. Reveal.togglePause();
  117. assert.strictEqual( Reveal.isPaused(), false, 'false after resuming' );
  118. });
  119. QUnit.test( 'Reveal.isFirstSlide', function( assert ) {
  120. Reveal.slide( 0, 0 );
  121. assert.strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' );
  122. Reveal.slide( 1, 0 );
  123. assert.strictEqual( Reveal.isFirstSlide(), false, 'false after Reveal.slide( 1, 0 )' );
  124. Reveal.slide( 0, 0 );
  125. assert.strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' );
  126. });
  127. QUnit.test( 'Reveal.isFirstSlide after vertical slide', function( assert ) {
  128. Reveal.slide( 1, 1 );
  129. Reveal.slide( 0, 0 );
  130. assert.strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( 0, 0 )' );
  131. });
  132. QUnit.test( 'Reveal.isLastSlide', function( assert ) {
  133. Reveal.slide( 0, 0 );
  134. assert.strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
  135. var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
  136. Reveal.slide( lastSlideIndex, 0 );
  137. assert.strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( '+ lastSlideIndex +', 0 )' );
  138. Reveal.slide( 0, 0 );
  139. assert.strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
  140. });
  141. QUnit.test( 'Reveal.isLastSlide after vertical slide', function( assert ) {
  142. var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
  143. Reveal.slide( 1, 1 );
  144. Reveal.slide( lastSlideIndex );
  145. assert.strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( '+ lastSlideIndex +', 0 )' );
  146. });
  147. QUnit.test( 'Reveal.getTotalSlides', function( assert ) {
  148. assert.strictEqual( Reveal.getTotalSlides(), 8, 'eight slides in total' );
  149. });
  150. QUnit.test( 'Reveal.getIndices', function( assert ) {
  151. var indices = Reveal.getIndices();
  152. assert.ok( indices.hasOwnProperty( 'h' ), 'h exists' );
  153. assert.ok( indices.hasOwnProperty( 'v' ), 'v exists' );
  154. assert.ok( indices.hasOwnProperty( 'f' ), 'f exists' );
  155. Reveal.slide( 1, 0 );
  156. assert.strictEqual( Reveal.getIndices().h, 1, 'h 1' );
  157. assert.strictEqual( Reveal.getIndices().v, 0, 'v 0' );
  158. Reveal.slide( 1, 2 );
  159. assert.strictEqual( Reveal.getIndices().h, 1, 'h 1' );
  160. assert.strictEqual( Reveal.getIndices().v, 2, 'v 2' );
  161. Reveal.slide( 0, 0 );
  162. assert.strictEqual( Reveal.getIndices().h, 0, 'h 0' );
  163. assert.strictEqual( Reveal.getIndices().v, 0, 'v 0' );
  164. });
  165. QUnit.test( 'Reveal.getSlide', function( assert ) {
  166. assert.equal( Reveal.getSlide( 0 ), document.querySelector( '.reveal .slides>section:first-child' ), 'gets correct first slide' );
  167. assert.equal( Reveal.getSlide( 1 ), document.querySelector( '.reveal .slides>section:nth-child(2)' ), 'no v index returns stack' );
  168. 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' );
  169. 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' );
  170. assert.strictEqual( Reveal.getSlide( 100 ), undefined, 'undefined when out of horizontal bounds' );
  171. assert.strictEqual( Reveal.getSlide( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
  172. });
  173. QUnit.test( 'Reveal.getSlideBackground', function( assert ) {
  174. assert.equal( Reveal.getSlideBackground( 0 ), document.querySelector( '.reveal .backgrounds>.slide-background:first-child' ), 'gets correct first background' );
  175. assert.equal( Reveal.getSlideBackground( 1 ), document.querySelector( '.reveal .backgrounds>.slide-background:nth-child(2)' ), 'no v index returns stack' );
  176. 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' );
  177. 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' );
  178. assert.strictEqual( Reveal.getSlideBackground( 100 ), undefined, 'undefined when out of horizontal bounds' );
  179. assert.strictEqual( Reveal.getSlideBackground( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
  180. });
  181. QUnit.test( 'Reveal.getSlideNotes', function( assert ) {
  182. Reveal.slide( 0, 0 );
  183. assert.ok( Reveal.getSlideNotes() === 'speaker notes 1', 'works with <aside class="notes">' );
  184. Reveal.slide( 1, 0 );
  185. assert.ok( Reveal.getSlideNotes() === 'speaker notes 2', 'works with <section data-notes="">' );
  186. });
  187. QUnit.test( 'Reveal.getPreviousSlide/getCurrentSlide', function( assert ) {
  188. Reveal.slide( 0, 0 );
  189. Reveal.slide( 1, 0 );
  190. var firstSlide = document.querySelector( '.reveal .slides>section:first-child' );
  191. var secondSlide = document.querySelector( '.reveal .slides>section:nth-child(2)>section' );
  192. assert.equal( Reveal.getPreviousSlide(), firstSlide, 'previous is slide #0' );
  193. assert.equal( Reveal.getCurrentSlide(), secondSlide, 'current is slide #1' );
  194. });
  195. QUnit.test( 'Reveal.getProgress', function( assert ) {
  196. Reveal.slide( 0, 0 );
  197. assert.strictEqual( Reveal.getProgress(), 0, 'progress is 0 on first slide' );
  198. var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
  199. Reveal.slide( lastSlideIndex, 0 );
  200. assert.strictEqual( Reveal.getProgress(), 1, 'progress is 1 on last slide' );
  201. });
  202. QUnit.test( 'Reveal.getScale', function( assert ) {
  203. assert.ok( typeof Reveal.getScale() === 'number', 'has scale' );
  204. });
  205. QUnit.test( 'Reveal.getConfig', function( assert ) {
  206. assert.ok( typeof Reveal.getConfig() === 'object', 'has config' );
  207. });
  208. QUnit.test( 'Reveal.configure', function( assert ) {
  209. assert.strictEqual( Reveal.getConfig().loop, false, '"loop" is false to start with' );
  210. Reveal.configure({ loop: true });
  211. assert.strictEqual( Reveal.getConfig().loop, true, '"loop" has changed to true' );
  212. Reveal.configure({ loop: false, customTestValue: 1 });
  213. assert.strictEqual( Reveal.getConfig().customTestValue, 1, 'supports custom values' );
  214. });
  215. QUnit.test( 'Reveal.availableRoutes', function( assert ) {
  216. Reveal.slide( 0, 0 );
  217. assert.deepEqual( Reveal.availableRoutes(), { left: false, up: false, down: false, right: true }, 'correct for first slide' );
  218. Reveal.slide( 1, 0 );
  219. assert.deepEqual( Reveal.availableRoutes(), { left: true, up: false, down: true, right: true }, 'correct for vertical slide' );
  220. Reveal.slide( 0, 0 );
  221. assert.deepEqual( Reveal.availableRoutes({ includeFragments: true }), { left: false, up: false, down: false, right: true }, 'correct with fragments included' );
  222. });
  223. QUnit.test( 'Reveal.next', function( assert ) {
  224. Reveal.slide( 0, 0 );
  225. // Step through vertical child slides
  226. Reveal.next();
  227. assert.deepEqual( Reveal.getIndices(), { h: 1, v: 0, f: undefined } );
  228. Reveal.next();
  229. assert.deepEqual( Reveal.getIndices(), { h: 1, v: 1, f: undefined } );
  230. Reveal.next();
  231. assert.deepEqual( Reveal.getIndices(), { h: 1, v: 2, f: undefined } );
  232. // Step through fragments
  233. Reveal.next();
  234. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: -1 } );
  235. Reveal.next();
  236. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 } );
  237. Reveal.next();
  238. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 } );
  239. Reveal.next();
  240. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 } );
  241. });
  242. QUnit.test( 'Reveal.next at end', function( assert ) {
  243. Reveal.slide( 3 );
  244. // We're at the end, this should have no effect
  245. Reveal.next();
  246. assert.deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
  247. Reveal.next();
  248. assert.deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
  249. });
  250. // ---------------------------------------------------------------
  251. // URL TESTS
  252. QUnit.module( 'URL' );
  253. QUnit.test( 'Write (fragmentInURL: false)', function( assert ) {
  254. Reveal.configure({ hash: true, fragmentInURL: false });
  255. Reveal.slide( 2, 0 );
  256. assert.strictEqual( window.location.hash, '#/2' );
  257. Reveal.slide( 2, 1 );
  258. assert.strictEqual( window.location.hash, '#/2/1' );
  259. Reveal.slide( 2, 0, 1 );
  260. assert.strictEqual( window.location.hash, '#/2' );
  261. Reveal.slide( 2, 2, 0 );
  262. assert.strictEqual( window.location.hash, '#/fragments3' );
  263. Reveal.slide( 2, 2, 1 );
  264. assert.strictEqual( window.location.hash, '#/fragments3' );
  265. });
  266. QUnit.test( 'Write (fragmentInURL: true)', function( assert ) {
  267. Reveal.configure({ hash: true, fragmentInURL: true });
  268. Reveal.slide( 2, 0, -1 );
  269. assert.strictEqual( window.location.hash, '#/2' );
  270. Reveal.slide( 2, 1, -1 );
  271. assert.strictEqual( window.location.hash, '#/2/1' );
  272. Reveal.slide( 2, 0, 1 );
  273. assert.strictEqual( window.location.hash, '#/2/0/1' );
  274. Reveal.slide( 2, 2, -1 );
  275. assert.strictEqual( window.location.hash, '#/fragments3' );
  276. Reveal.slide( 2, 2, 1 );
  277. assert.strictEqual( window.location.hash, '#/fragments3/1' );
  278. });
  279. QUnit.test( 'Read', async function( assert ) {
  280. Reveal.configure({ hash: true, fragmentInURL: true });
  281. let test = function( hash, indices ) {
  282. return new Promise( resolve => {
  283. window.onhashchange = () => {
  284. assert.deepEqual( Reveal.getIndices(), indices );
  285. resolve();
  286. };
  287. window.location.hash = hash;
  288. } );
  289. }
  290. await test( '#/0', { h: 0, v: 0, f: undefined } ); // horizontal
  291. await test( '#/1/1', { h: 1, v: 1, f: undefined } ); // vertical
  292. await test( '#/0/', { h: 0, v: 0, f: undefined } ); // trailing /
  293. await test( '#/1/1/', { h: 1, v: 1, f: undefined } ); // trailing /
  294. await test( '#/2/0/1', { h: 2, v: 0, f: 1 } ); // fragment
  295. });
  296. // ---------------------------------------------------------------
  297. // KEYBOARD TESTS
  298. QUnit.module( 'Keyboard' );
  299. QUnit.test( 'Add key bindings', function( assert ) {
  300. var done = assert.async( 1 );
  301. Reveal.addKeyBinding({keyCode: 88, key: 'X', description: 'X-SHORTCUT-X'}, function() {
  302. assert.ok( true, 'callback triggered' );
  303. done();
  304. } );
  305. Reveal.toggleHelp( true );
  306. assert.ok( /X\-SHORTCUT\-X/.test( document.body.innerHTML ), 'binding is added to help overlay' );
  307. Reveal.toggleHelp( false );
  308. triggerKeyboardEvent({ keyCode: 88 });
  309. Reveal.removeKeyBinding( 88 );
  310. // should do nothing
  311. triggerKeyboardEvent({ keyCode: 88 });
  312. });
  313. QUnit.test( 'Navigation bindings', function( assert ) {
  314. Reveal.slide( 0 );
  315. // right arrow
  316. triggerKeyboardEvent({ keyCode: 39 });
  317. assert.strictEqual( Reveal.getIndices().h, 1 );
  318. // down arrow + shift
  319. triggerKeyboardEvent({ keyCode: 40, shiftKey: true });
  320. assert.strictEqual( Reveal.getIndices().v, 2, 'shift + down arrow goes to last vertical slide' );
  321. // up arrow
  322. triggerKeyboardEvent({ keyCode: 38 });
  323. assert.strictEqual( Reveal.getIndices().v, 1 );
  324. // right arrow + shift
  325. triggerKeyboardEvent({ keyCode: 39, shiftKey: true });
  326. assert.ok( Reveal.isLastSlide(), 'shift + right arrow goes to last horizontal slide' );
  327. // right arrow on slide with fragments
  328. Reveal.slide( 2, 0, -1 );
  329. triggerKeyboardEvent({ keyCode: 39 });
  330. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'right arrow shows fragment' );
  331. triggerKeyboardEvent({ keyCode: 39, altKey: true });
  332. assert.strictEqual( Reveal.getIndices().h, 3, 'right arrow skips fragments when alt key is pressed' );
  333. });
  334. // ---------------------------------------------------------------
  335. // FRAGMENT TESTS
  336. QUnit.module( 'Fragments' );
  337. QUnit.test( 'Sliding to fragments', function( assert ) {
  338. Reveal.slide( 2, 0, -1 );
  339. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: -1 }, 'Reveal.slide( 2, 0, -1 )' );
  340. Reveal.slide( 2, 0, 0 );
  341. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'Reveal.slide( 2, 0, 0 )' );
  342. Reveal.slide( 2, 0, 2 );
  343. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'Reveal.slide( 2, 0, 2 )' );
  344. Reveal.slide( 2, 0, 1 );
  345. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'Reveal.slide( 2, 0, 1 )' );
  346. });
  347. QUnit.test( 'data-fragment is set on slide <section>', function( assert ) {
  348. Reveal.slide( 2, 0, -1 );
  349. assert.deepEqual( Reveal.getCurrentSlide().getAttribute( 'data-fragment' ), '-1' );
  350. Reveal.slide( 2, 0, 2 );
  351. assert.deepEqual( Reveal.getCurrentSlide().getAttribute( 'data-fragment' ), '2' );
  352. Reveal.slide( 2, 0, 0 );
  353. assert.deepEqual( Reveal.getCurrentSlide().getAttribute( 'data-fragment' ), '0' );
  354. var fragmentSlide = Reveal.getCurrentSlide();
  355. Reveal.slide( 3, 0 );
  356. assert.deepEqual( fragmentSlide.getAttribute( 'data-fragment' ), '0', 'data-fragment persists when jumping to another slide' );
  357. });
  358. QUnit.test( 'Hiding all fragments', function( assert ) {
  359. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  360. Reveal.slide( 2, 0, 0 );
  361. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 1, 'one fragment visible when index is 0' );
  362. Reveal.slide( 2, 0, -1 );
  363. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 0, 'no fragments visible when index is -1' );
  364. });
  365. QUnit.test( 'Current fragment', function( assert ) {
  366. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  367. var lastFragmentIndex = [].slice.call( fragmentSlide.querySelectorAll( '.fragment' ) ).pop().getAttribute( 'data-fragment-index' );
  368. Reveal.slide( 2, 0 );
  369. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment at index -1' );
  370. Reveal.slide( 2, 0, 0 );
  371. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 1, 'one current fragment at index 0' );
  372. Reveal.slide( 1, 0, 0 );
  373. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment when navigating to previous slide' );
  374. Reveal.slide( 3, 0, 0 );
  375. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment when navigating to next slide' );
  376. Reveal.slide( 2, 1, -1 );
  377. Reveal.prev();
  378. assert.strictEqual( fragmentSlide.querySelector( '.fragment.current-fragment' ).getAttribute( 'data-fragment-index' ), lastFragmentIndex, 'last fragment is current fragment when returning from future slide' );
  379. });
  380. QUnit.test( 'Stepping through fragments', function( assert ) {
  381. Reveal.slide( 2, 0, -1 );
  382. // forwards:
  383. Reveal.next();
  384. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'next() goes to next fragment' );
  385. Reveal.right();
  386. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'right() goes to next fragment' );
  387. Reveal.down();
  388. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'down() goes to next fragment' );
  389. Reveal.down(); // moves to f #3
  390. // backwards:
  391. Reveal.prev();
  392. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'prev() goes to prev fragment' );
  393. Reveal.left();
  394. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'left() goes to prev fragment' );
  395. Reveal.up();
  396. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'up() goes to prev fragment' );
  397. });
  398. QUnit.test( 'Stepping past fragments', function( assert ) {
  399. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  400. Reveal.slide( 0, 0, 0 );
  401. assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 0, 'no fragments visible when on previous slide' );
  402. Reveal.slide( 3, 0, 0 );
  403. assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 3, 'all fragments visible when on future slide' );
  404. });
  405. QUnit.test( 'Fragment indices', function( assert ) {
  406. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(2)' );
  407. Reveal.slide( 3, 0, 0 );
  408. assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 2, 'both fragments of same index are shown' );
  409. // This slide has three fragments, first one is index 0, second and third have index 1
  410. Reveal.slide( 2, 2, 0 );
  411. assert.equal( Reveal.getIndices().f, 0, 'returns correct index for first fragment' );
  412. Reveal.slide( 2, 2, 1 );
  413. assert.equal( Reveal.getIndices().f, 1, 'returns correct index for two fragments with same index' );
  414. });
  415. QUnit.test( 'Index generation', function( assert ) {
  416. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  417. // These have no indices defined to start with
  418. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[0].getAttribute( 'data-fragment-index' ), '0' );
  419. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[1].getAttribute( 'data-fragment-index' ), '1' );
  420. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[2].getAttribute( 'data-fragment-index' ), '2' );
  421. });
  422. QUnit.test( 'Index normalization', function( assert ) {
  423. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(3)' );
  424. // These start out as 1-4-4 and should normalize to 0-1-1
  425. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[0].getAttribute( 'data-fragment-index' ), '0' );
  426. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[1].getAttribute( 'data-fragment-index' ), '1' );
  427. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[2].getAttribute( 'data-fragment-index' ), '1' );
  428. });
  429. QUnit.test( 'fragmentshown event', function( assert ) {
  430. assert.expect( 2 );
  431. var done = assert.async( 2 );
  432. var _onEvent = function( event ) {
  433. assert.ok( true, 'event fired' );
  434. done();
  435. }
  436. Reveal.on( 'fragmentshown', _onEvent );
  437. Reveal.slide( 2, 0 );
  438. Reveal.slide( 2, 0 ); // should do nothing
  439. Reveal.slide( 2, 0, 0 ); // should do nothing
  440. Reveal.next();
  441. Reveal.next();
  442. Reveal.prev(); // shouldn't fire fragmentshown
  443. Reveal.off( 'fragmentshown', _onEvent );
  444. });
  445. QUnit.test( 'fragmenthidden event', function( assert ) {
  446. assert.expect( 2 );
  447. var done = assert.async( 2 );
  448. var _onEvent = function( event ) {
  449. assert.ok( true, 'event fired' );
  450. done();
  451. }
  452. Reveal.on( 'fragmenthidden', _onEvent );
  453. Reveal.slide( 2, 0, 2 );
  454. Reveal.slide( 2, 0, 2 ); // should do nothing
  455. Reveal.prev();
  456. Reveal.prev();
  457. Reveal.next(); // shouldn't fire fragmenthidden
  458. Reveal.off( 'fragmenthidden', _onEvent );
  459. });
  460. // ---------------------------------------------------------------
  461. // AUTO-SLIDE TESTS
  462. QUnit.module( 'Auto Sliding' );
  463. QUnit.test( 'Reveal.isAutoSliding', function( assert ) {
  464. assert.strictEqual( Reveal.isAutoSliding(), false, 'false by default' );
  465. Reveal.configure({ autoSlide: 10000 });
  466. assert.strictEqual( Reveal.isAutoSliding(), true, 'true after starting' );
  467. Reveal.configure({ autoSlide: 0 });
  468. assert.strictEqual( Reveal.isAutoSliding(), false, 'false after setting to 0' );
  469. });
  470. QUnit.test( 'Reveal.toggleAutoSlide', function( assert ) {
  471. Reveal.configure({ autoSlide: 10000 });
  472. Reveal.toggleAutoSlide();
  473. assert.strictEqual( Reveal.isAutoSliding(), false, 'false after first toggle' );
  474. Reveal.toggleAutoSlide();
  475. assert.strictEqual( Reveal.isAutoSliding(), true, 'true after second toggle' );
  476. Reveal.configure({ autoSlide: 0 });
  477. });
  478. QUnit.test( 'autoslidepaused', function( assert ) {
  479. assert.expect( 1 );
  480. var done = assert.async();
  481. var _onEvent = function( event ) {
  482. assert.ok( true, 'event fired' );
  483. done();
  484. }
  485. Reveal.on( 'autoslidepaused', _onEvent );
  486. Reveal.configure({ autoSlide: 10000 });
  487. Reveal.toggleAutoSlide();
  488. // cleanup
  489. Reveal.configure({ autoSlide: 0 });
  490. Reveal.off( 'autoslidepaused', _onEvent );
  491. });
  492. QUnit.test( 'autoslideresumed', function( assert ) {
  493. assert.expect( 1 );
  494. var done = assert.async();
  495. var _onEvent = function( event ) {
  496. assert.ok( true, 'event fired' );
  497. done();
  498. }
  499. Reveal.on( 'autoslideresumed', _onEvent );
  500. Reveal.configure({ autoSlide: 10000 });
  501. Reveal.toggleAutoSlide();
  502. Reveal.toggleAutoSlide();
  503. // cleanup
  504. Reveal.configure({ autoSlide: 0 });
  505. Reveal.off( 'autoslideresumed', _onEvent );
  506. });
  507. // ---------------------------------------------------------------
  508. // CONFIGURATION VALUES
  509. QUnit.module( 'Configuration' );
  510. QUnit.test( 'Controls', function( assert ) {
  511. var controlsElement = document.querySelector( '.reveal>.controls' );
  512. Reveal.configure({ controls: false });
  513. assert.equal( controlsElement.style.display, 'none', 'controls are hidden' );
  514. Reveal.configure({ controls: true });
  515. assert.equal( controlsElement.style.display, 'block', 'controls are visible' );
  516. });
  517. QUnit.test( 'Progress', function( assert ) {
  518. var progressElement = document.querySelector( '.reveal>.progress' );
  519. Reveal.configure({ progress: false });
  520. assert.equal( progressElement.style.display, 'none', 'progress are hidden' );
  521. Reveal.configure({ progress: true });
  522. assert.equal( progressElement.style.display, 'block', 'progress are visible' );
  523. });
  524. QUnit.test( 'Loop', function( assert ) {
  525. Reveal.configure({ loop: true });
  526. Reveal.slide( 0, 0 );
  527. Reveal.left();
  528. assert.notEqual( Reveal.getIndices().h, 0, 'looped from start to end' );
  529. Reveal.right();
  530. assert.equal( Reveal.getIndices().h, 0, 'looped from end to start' );
  531. Reveal.configure({ navigationMode: 'linear' });
  532. Reveal.slide( 0, 0 );
  533. Reveal.prev();
  534. assert.notEqual( Reveal.getIndices().h, 0, 'looped from start to end in linear mode' );
  535. Reveal.next();
  536. assert.equal( Reveal.getIndices().h, 0, 'looped from end to start in linear mode' );
  537. Reveal.configure({ loop: false, navigationMode: 'default' });
  538. });
  539. // ---------------------------------------------------------------
  540. // LAZY-LOADING TESTS
  541. QUnit.module( 'Lazy-Loading' );
  542. QUnit.test( 'img with data-src', function( assert ) {
  543. assert.strictEqual( document.querySelectorAll( '.reveal section img[src]' ).length, 1, 'Image source has been set' );
  544. });
  545. QUnit.test( 'video with data-src', function( assert ) {
  546. assert.strictEqual( document.querySelectorAll( '.reveal section video[src]' ).length, 1, 'Video source has been set' );
  547. });
  548. QUnit.test( 'audio with data-src', function( assert ) {
  549. assert.strictEqual( document.querySelectorAll( '.reveal section audio[src]' ).length, 1, 'Audio source has been set' );
  550. });
  551. QUnit.test( 'iframe with data-src', function( assert ) {
  552. Reveal.slide( 0, 0 );
  553. assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
  554. Reveal.slide( 2, 1 );
  555. assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 1, 'Iframe source is set' );
  556. Reveal.slide( 2, 2 );
  557. assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
  558. });
  559. QUnit.test( 'background images', function( assert ) {
  560. var imageSource1 = Reveal.getSlide( 0 ).getAttribute( 'data-background-image' );
  561. var imageSource2 = Reveal.getSlide( 1, 0 ).getAttribute( 'data-background' );
  562. var imageSource3 = Reveal.getSlide( 1, 1 ).getAttribute( 'data-background-image' );
  563. // check that the images are applied to the background elements
  564. assert.ok( Reveal.getSlideBackground( 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource1 ) !== -1, 'data-background-image worked' );
  565. assert.ok( Reveal.getSlideBackground( 1, 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource2 ) !== -1, 'data-background worked' );
  566. assert.ok( Reveal.getSlideBackground( 1, 1 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource3 ) !== -1, 'data-background worked' );
  567. });
  568. // ---------------------------------------------------------------
  569. // EVENT TESTS
  570. QUnit.module( 'Events' );
  571. QUnit.test( 'beforeslidechange', function( assert ) {
  572. var done = assert.async( 2 );
  573. var normalEvent = function( event ) {
  574. assert.ok( true, 'event fired' );
  575. done();
  576. }
  577. var blockingEvent = function( event ) {
  578. event.preventDefault();
  579. assert.ok( true, 'event fired' );
  580. done();
  581. }
  582. Reveal.on( 'beforeslidechange', normalEvent );
  583. Reveal.slide( 2, 0 );
  584. Reveal.off( 'beforeslidechange', normalEvent );
  585. Reveal.on( 'beforeslidechange', blockingEvent );
  586. Reveal.slide( 3, 0 );
  587. Reveal.off( 'beforeslidechange', blockingEvent );
  588. assert.strictEqual( Reveal.getIndices().h, 2, 'preventing "beforeslidechange" blocks navigation ' );
  589. });
  590. QUnit.test( 'slidechanged', function( assert ) {
  591. assert.expect( 3 );
  592. var done = assert.async( 3 );
  593. var _onEvent = function( event ) {
  594. assert.ok( true, 'event fired' );
  595. done();
  596. }
  597. Reveal.on( 'slidechanged', _onEvent );
  598. Reveal.slide( 1, 0 ); // should trigger
  599. Reveal.slide( 1, 0 ); // should do nothing
  600. Reveal.next(); // should trigger
  601. Reveal.slide( 3, 0 ); // should trigger
  602. Reveal.next(); // should do nothing
  603. Reveal.off( 'slidechanged', _onEvent );
  604. });
  605. /* Fails intermittently...
  606. QUnit.test( 'slidetransitionend', function( assert ) {
  607. assert.expect( 2 );
  608. let done = assert.async( 2 );
  609. let time = Date.now();
  610. let horizontalCallback = event => {
  611. assert.ok( Date.now() - time > 200, 'horizontal event fired' );
  612. done();
  613. let verticalCallback = event => {
  614. assert.ok( true, 'vertical event fired' );
  615. done();
  616. Reveal.off( 'slidetransitionend', verticalCallback );
  617. }
  618. Reveal.off( 'slidetransitionend', horizontalCallback );
  619. Reveal.on( 'slidetransitionend', verticalCallback );
  620. Reveal.slide( 1, 1 );
  621. }
  622. Reveal.slide( 0, 0 );
  623. Reveal.on( 'slidetransitionend', horizontalCallback );
  624. Reveal.slide( 1, 0 );
  625. });
  626. */
  627. QUnit.test( 'paused', function( assert ) {
  628. assert.expect( 1 );
  629. var done = assert.async();
  630. var _onEvent = function( event ) {
  631. assert.ok( true, 'event fired' );
  632. done();
  633. }
  634. Reveal.on( 'paused', _onEvent );
  635. Reveal.togglePause();
  636. Reveal.togglePause();
  637. Reveal.off( 'paused', _onEvent );
  638. });
  639. QUnit.test( 'resumed', function( assert ) {
  640. assert.expect( 1 );
  641. var done = assert.async();
  642. var _onEvent = function( event ) {
  643. assert.ok( true, 'event fired' );
  644. done();
  645. }
  646. Reveal.on( 'resumed', _onEvent );
  647. Reveal.togglePause();
  648. Reveal.togglePause();
  649. Reveal.off( 'resumed', _onEvent );
  650. });
  651. } );
  652. </script>
  653. </body>
  654. </html>