test.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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( 'Hiding all fragments', function( assert ) {
  184. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  185. Reveal.slide( 2, 0, 0 );
  186. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 1, 'one fragment visible when index is 0' );
  187. Reveal.slide( 2, 0, -1 );
  188. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 0, 'no fragments visible when index is -1' );
  189. });
  190. QUnit.test( 'Current fragment', function( assert ) {
  191. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  192. var lastFragmentIndex = [].slice.call( fragmentSlide.querySelectorAll( '.fragment' ) ).pop().getAttribute( 'data-fragment-index' );
  193. Reveal.slide( 2, 0 );
  194. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment at index -1' );
  195. Reveal.slide( 2, 0, 0 );
  196. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 1, 'one current fragment at index 0' );
  197. Reveal.slide( 1, 0, 0 );
  198. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment when navigating to previous slide' );
  199. Reveal.slide( 3, 0, 0 );
  200. assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment when navigating to next slide' );
  201. Reveal.slide( 2, 1, -1 );
  202. Reveal.prev();
  203. assert.strictEqual( fragmentSlide.querySelector( '.fragment.current-fragment' ).getAttribute( 'data-fragment-index' ), lastFragmentIndex, 'last fragment is current fragment when returning from future slide' );
  204. });
  205. QUnit.test( 'Stepping through fragments', function( assert ) {
  206. Reveal.slide( 2, 0, -1 );
  207. // forwards:
  208. Reveal.next();
  209. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'next() goes to next fragment' );
  210. Reveal.right();
  211. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'right() goes to next fragment' );
  212. Reveal.down();
  213. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'down() goes to next fragment' );
  214. Reveal.down(); // moves to f #3
  215. // backwards:
  216. Reveal.prev();
  217. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'prev() goes to prev fragment' );
  218. Reveal.left();
  219. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'left() goes to prev fragment' );
  220. Reveal.up();
  221. assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'up() goes to prev fragment' );
  222. });
  223. QUnit.test( 'Stepping past fragments', function( assert ) {
  224. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  225. Reveal.slide( 0, 0, 0 );
  226. assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 0, 'no fragments visible when on previous slide' );
  227. Reveal.slide( 3, 0, 0 );
  228. assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 3, 'all fragments visible when on future slide' );
  229. });
  230. QUnit.test( 'Fragment indices', function( assert ) {
  231. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(2)' );
  232. Reveal.slide( 3, 0, 0 );
  233. assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 2, 'both fragments of same index are shown' );
  234. // This slide has three fragments, first one is index 0, second and third have index 1
  235. Reveal.slide( 2, 2, 0 );
  236. assert.equal( Reveal.getIndices().f, 0, 'returns correct index for first fragment' );
  237. Reveal.slide( 2, 2, 1 );
  238. assert.equal( Reveal.getIndices().f, 1, 'returns correct index for two fragments with same index' );
  239. });
  240. QUnit.test( 'Index generation', function( assert ) {
  241. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
  242. // These have no indices defined to start with
  243. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[0].getAttribute( 'data-fragment-index' ), '0' );
  244. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[1].getAttribute( 'data-fragment-index' ), '1' );
  245. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[2].getAttribute( 'data-fragment-index' ), '2' );
  246. });
  247. QUnit.test( 'Index normalization', function( assert ) {
  248. var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(3)' );
  249. // These start out as 1-4-4 and should normalize to 0-1-1
  250. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[0].getAttribute( 'data-fragment-index' ), '0' );
  251. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[1].getAttribute( 'data-fragment-index' ), '1' );
  252. assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[2].getAttribute( 'data-fragment-index' ), '1' );
  253. });
  254. QUnit.test( 'fragmentshown event', function( assert ) {
  255. assert.expect( 2 );
  256. var done = assert.async( 2 );
  257. var _onEvent = function( event ) {
  258. assert.ok( true, 'event fired' );
  259. done();
  260. }
  261. Reveal.addEventListener( 'fragmentshown', _onEvent );
  262. Reveal.slide( 2, 0 );
  263. Reveal.slide( 2, 0 ); // should do nothing
  264. Reveal.slide( 2, 0, 0 ); // should do nothing
  265. Reveal.next();
  266. Reveal.next();
  267. Reveal.prev(); // shouldn't fire fragmentshown
  268. Reveal.removeEventListener( 'fragmentshown', _onEvent );
  269. });
  270. QUnit.test( 'fragmenthidden event', function( assert ) {
  271. assert.expect( 2 );
  272. var done = assert.async( 2 );
  273. var _onEvent = function( event ) {
  274. assert.ok( true, 'event fired' );
  275. done();
  276. }
  277. Reveal.addEventListener( 'fragmenthidden', _onEvent );
  278. Reveal.slide( 2, 0, 2 );
  279. Reveal.slide( 2, 0, 2 ); // should do nothing
  280. Reveal.prev();
  281. Reveal.prev();
  282. Reveal.next(); // shouldn't fire fragmenthidden
  283. Reveal.removeEventListener( 'fragmenthidden', _onEvent );
  284. });
  285. // ---------------------------------------------------------------
  286. // AUTO-SLIDE TESTS
  287. QUnit.module( 'Auto Sliding' );
  288. QUnit.test( 'Reveal.isAutoSliding', function( assert ) {
  289. assert.strictEqual( Reveal.isAutoSliding(), false, 'false by default' );
  290. Reveal.configure({ autoSlide: 10000 });
  291. assert.strictEqual( Reveal.isAutoSliding(), true, 'true after starting' );
  292. Reveal.configure({ autoSlide: 0 });
  293. assert.strictEqual( Reveal.isAutoSliding(), false, 'false after setting to 0' );
  294. });
  295. QUnit.test( 'Reveal.toggleAutoSlide', function( assert ) {
  296. Reveal.configure({ autoSlide: 10000 });
  297. Reveal.toggleAutoSlide();
  298. assert.strictEqual( Reveal.isAutoSliding(), false, 'false after first toggle' );
  299. Reveal.toggleAutoSlide();
  300. assert.strictEqual( Reveal.isAutoSliding(), true, 'true after second toggle' );
  301. Reveal.configure({ autoSlide: 0 });
  302. });
  303. QUnit.test( 'autoslidepaused', function( assert ) {
  304. assert.expect( 1 );
  305. var done = assert.async();
  306. var _onEvent = function( event ) {
  307. assert.ok( true, 'event fired' );
  308. done();
  309. }
  310. Reveal.addEventListener( 'autoslidepaused', _onEvent );
  311. Reveal.configure({ autoSlide: 10000 });
  312. Reveal.toggleAutoSlide();
  313. // cleanup
  314. Reveal.configure({ autoSlide: 0 });
  315. Reveal.removeEventListener( 'autoslidepaused', _onEvent );
  316. });
  317. QUnit.test( 'autoslideresumed', function( assert ) {
  318. assert.expect( 1 );
  319. var done = assert.async();
  320. var _onEvent = function( event ) {
  321. assert.ok( true, 'event fired' );
  322. done();
  323. }
  324. Reveal.addEventListener( 'autoslideresumed', _onEvent );
  325. Reveal.configure({ autoSlide: 10000 });
  326. Reveal.toggleAutoSlide();
  327. Reveal.toggleAutoSlide();
  328. // cleanup
  329. Reveal.configure({ autoSlide: 0 });
  330. Reveal.removeEventListener( 'autoslideresumed', _onEvent );
  331. });
  332. // ---------------------------------------------------------------
  333. // CONFIGURATION VALUES
  334. QUnit.module( 'Configuration' );
  335. QUnit.test( 'Controls', function( assert ) {
  336. var controlsElement = document.querySelector( '.reveal>.controls' );
  337. Reveal.configure({ controls: false });
  338. assert.equal( controlsElement.style.display, 'none', 'controls are hidden' );
  339. Reveal.configure({ controls: true });
  340. assert.equal( controlsElement.style.display, 'block', 'controls are visible' );
  341. });
  342. QUnit.test( 'Progress', function( assert ) {
  343. var progressElement = document.querySelector( '.reveal>.progress' );
  344. Reveal.configure({ progress: false });
  345. assert.equal( progressElement.style.display, 'none', 'progress are hidden' );
  346. Reveal.configure({ progress: true });
  347. assert.equal( progressElement.style.display, 'block', 'progress are visible' );
  348. });
  349. QUnit.test( 'Loop', function( assert ) {
  350. Reveal.configure({ loop: true });
  351. Reveal.slide( 0, 0 );
  352. Reveal.left();
  353. assert.notEqual( Reveal.getIndices().h, 0, 'looped from start to end' );
  354. Reveal.right();
  355. assert.equal( Reveal.getIndices().h, 0, 'looped from end to start' );
  356. Reveal.configure({ loop: false });
  357. });
  358. // ---------------------------------------------------------------
  359. // LAZY-LOADING TESTS
  360. QUnit.module( 'Lazy-Loading' );
  361. QUnit.test( 'img with data-src', function( assert ) {
  362. assert.strictEqual( document.querySelectorAll( '.reveal section img[src]' ).length, 1, 'Image source has been set' );
  363. });
  364. QUnit.test( 'video with data-src', function( assert ) {
  365. assert.strictEqual( document.querySelectorAll( '.reveal section video[src]' ).length, 1, 'Video source has been set' );
  366. });
  367. QUnit.test( 'audio with data-src', function( assert ) {
  368. assert.strictEqual( document.querySelectorAll( '.reveal section audio[src]' ).length, 1, 'Audio source has been set' );
  369. });
  370. QUnit.test( 'iframe with data-src', function( assert ) {
  371. Reveal.slide( 0, 0 );
  372. assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
  373. Reveal.slide( 2, 1 );
  374. assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 1, 'Iframe source is set' );
  375. Reveal.slide( 2, 2 );
  376. assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
  377. });
  378. QUnit.test( 'background images', function( assert ) {
  379. var imageSource1 = Reveal.getSlide( 0 ).getAttribute( 'data-background-image' );
  380. var imageSource2 = Reveal.getSlide( 1, 0 ).getAttribute( 'data-background' );
  381. // check that the images are applied to the background elements
  382. assert.ok( Reveal.getSlideBackground( 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource1 ) !== -1, 'data-background-image worked' );
  383. assert.ok( Reveal.getSlideBackground( 1, 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource2 ) !== -1, 'data-background worked' );
  384. });
  385. // ---------------------------------------------------------------
  386. // EVENT TESTS
  387. QUnit.module( 'Events' );
  388. QUnit.test( 'slidechanged', function( assert ) {
  389. assert.expect( 3 );
  390. var done = assert.async( 3 );
  391. var _onEvent = function( event ) {
  392. assert.ok( true, 'event fired' );
  393. done();
  394. }
  395. Reveal.addEventListener( 'slidechanged', _onEvent );
  396. Reveal.slide( 1, 0 ); // should trigger
  397. Reveal.slide( 1, 0 ); // should do nothing
  398. Reveal.next(); // should trigger
  399. Reveal.slide( 3, 0 ); // should trigger
  400. Reveal.next(); // should do nothing
  401. Reveal.removeEventListener( 'slidechanged', _onEvent );
  402. });
  403. QUnit.test( 'paused', function( assert ) {
  404. assert.expect( 1 );
  405. var done = assert.async();
  406. var _onEvent = function( event ) {
  407. assert.ok( true, 'event fired' );
  408. done();
  409. }
  410. Reveal.addEventListener( 'paused', _onEvent );
  411. Reveal.togglePause();
  412. Reveal.togglePause();
  413. Reveal.removeEventListener( 'paused', _onEvent );
  414. });
  415. QUnit.test( 'resumed', function( assert ) {
  416. assert.expect( 1 );
  417. var done = assert.async();
  418. var _onEvent = function( event ) {
  419. assert.ok( true, 'event fired' );
  420. done();
  421. }
  422. Reveal.addEventListener( 'resumed', _onEvent );
  423. Reveal.togglePause();
  424. Reveal.togglePause();
  425. Reveal.removeEventListener( 'resumed', _onEvent );
  426. });
  427. } );
  428. Reveal.initialize();