test.js 21 KB

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