選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

test.html 32KB

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