test.js 22 KB

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