test.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. // 4
  8. Reveal.addEventListener( 'ready', function() {
  9. // ---------------------------------------------------------------
  10. // API TESTS
  11. QUnit.module( 'API' );
  12. test( 'Reveal.isReady', function() {
  13. strictEqual( Reveal.isReady(), true, 'returns true' );
  14. });
  15. test( 'Reveal.isOverview', function() {
  16. strictEqual( Reveal.isOverview(), false, 'false by default' );
  17. Reveal.toggleOverview();
  18. strictEqual( Reveal.isOverview(), true, 'true after toggling on' );
  19. Reveal.toggleOverview();
  20. strictEqual( Reveal.isOverview(), false, 'false after toggling off' );
  21. });
  22. test( 'Reveal.isPaused', function() {
  23. strictEqual( Reveal.isPaused(), false, 'false by default' );
  24. Reveal.togglePause();
  25. strictEqual( Reveal.isPaused(), true, 'true after pausing' );
  26. Reveal.togglePause();
  27. strictEqual( Reveal.isPaused(), false, 'false after resuming' );
  28. });
  29. test( 'Reveal.isFirstSlide', function() {
  30. Reveal.slide( 0, 0 );
  31. strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' );
  32. Reveal.slide( 1, 0 );
  33. strictEqual( Reveal.isFirstSlide(), false, 'false after Reveal.slide( 1, 0 )' );
  34. Reveal.slide( 0, 0 );
  35. strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' );
  36. });
  37. test( 'Reveal.isLastSlide', function() {
  38. Reveal.slide( 0, 0 );
  39. strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
  40. var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
  41. Reveal.slide( lastSlideIndex, 0 );
  42. strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( ', 0+ lastSlideIndex +' )' );
  43. Reveal.slide( 0, 0 );
  44. strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
  45. });
  46. test( 'Reveal.getIndices', function() {
  47. var indices = Reveal.getIndices();
  48. ok( typeof indices.hasOwnProperty( 'h' ), 'h exists' );
  49. ok( typeof indices.hasOwnProperty( 'v' ), 'v exists' );
  50. ok( typeof indices.hasOwnProperty( 'f' ), 'f exists' );
  51. Reveal.slide( 1, 0 );
  52. ok( Reveal.getIndices().h === 1 && Reveal.getIndices().v === 0, 'h 1, v 0' );
  53. Reveal.slide( 1, 2 );
  54. ok( Reveal.getIndices().h === 1 && Reveal.getIndices().v === 2, 'h 1, v 2' );
  55. Reveal.slide( 0, 0 );
  56. });
  57. test( 'Reveal.getSlide', function() {
  58. var firstSlide = document.querySelector( '.reveal .slides>section:first-child' );
  59. equal( Reveal.getSlide( 0 ), firstSlide, 'gets correct first slide' );
  60. strictEqual( Reveal.getSlide( 100 ), undefined, 'returns undefined when slide can\'t be found' );
  61. });
  62. test( 'Reveal.getPreviousSlide/getCurrentSlide', function() {
  63. Reveal.slide( 0, 0 );
  64. Reveal.slide( 1, 0 );
  65. var firstSlide = document.querySelector( '.reveal .slides>section:first-child' );
  66. var secondSlide = document.querySelector( '.reveal .slides>section:nth-child(2)>section' );
  67. equal( Reveal.getPreviousSlide(), firstSlide, 'previous is slide #0' );
  68. equal( Reveal.getCurrentSlide(), secondSlide, 'current is slide #1' );
  69. });
  70. test( 'Reveal.getScale', function() {
  71. ok( typeof Reveal.getScale() === 'number', 'has scale' );
  72. });
  73. test( 'Reveal.getConfig', function() {
  74. ok( typeof Reveal.getConfig() === 'object', 'has config' );
  75. });
  76. test( 'Reveal.configure', function() {
  77. strictEqual( Reveal.getConfig().loop, false, '"loop" is false to start with' );
  78. Reveal.configure({ loop: true });
  79. strictEqual( Reveal.getConfig().loop, true, '"loop" has changed to true' );
  80. Reveal.configure({ loop: false, customTestValue: 1 });
  81. strictEqual( Reveal.getConfig().customTestValue, 1, 'supports custom values' );
  82. });
  83. test( 'Reveal.availableRoutes', function() {
  84. Reveal.slide( 0, 0 );
  85. deepEqual( Reveal.availableRoutes(), { left: false, up: false, down: false, right: true }, 'correct for first slide' );
  86. Reveal.slide( 1, 0 );
  87. deepEqual( Reveal.availableRoutes(), { left: true, up: false, down: true, right: true }, 'correct for vertical slide' );
  88. });
  89. test( 'Reveal.next', function() {
  90. Reveal.slide( 0, 0 );
  91. // Step through the vertical child slides
  92. Reveal.next();
  93. deepEqual( Reveal.getIndices(), { h: 1, v: 0, f: undefined } );
  94. Reveal.next();
  95. deepEqual( Reveal.getIndices(), { h: 1, v: 1, f: undefined } );
  96. Reveal.next();
  97. deepEqual( Reveal.getIndices(), { h: 1, v: 2, f: undefined } );
  98. // There's fragments on this slide
  99. Reveal.next();
  100. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 } );
  101. Reveal.next();
  102. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 } );
  103. Reveal.next();
  104. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 } );
  105. Reveal.next();
  106. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 3 } );
  107. Reveal.next();
  108. deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
  109. // We're at the end, this should have no effect
  110. Reveal.next();
  111. deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
  112. });
  113. // ---------------------------------------------------------------
  114. // FRAGMENT TESTS
  115. QUnit.module( 'Fragments' );
  116. test( 'Sliding to fragments', function() {
  117. Reveal.slide( 2, 0, 0 );
  118. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'Reveal.slide( 2, 0, 0 )' );
  119. Reveal.slide( 2, 0, 2 );
  120. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'Reveal.slide( 2, 0, 2 )' );
  121. Reveal.slide( 2, 0, 1 );
  122. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'Reveal.slide( 2, 0, 1 )' );
  123. });
  124. test( 'Stepping through fragments', function() {
  125. Reveal.slide( 2, 0, 0 );
  126. // forwards:
  127. Reveal.next();
  128. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'next() goes to next fragment' );
  129. Reveal.right();
  130. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'right() goes to next fragment' );
  131. Reveal.down();
  132. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 3 }, 'down() goes to next fragment' );
  133. Reveal.down(); // moves to f #3
  134. // backwards:
  135. Reveal.prev();
  136. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'prev() goes to prev fragment' );
  137. Reveal.left();
  138. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'left() goes to prev fragment' );
  139. Reveal.up();
  140. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'left() goes to prev fragment' );
  141. });
  142. asyncTest( 'fragmentshown event', function() {
  143. expect( 2 );
  144. var _onEvent = function( event ) {
  145. ok( true, 'event fired' );
  146. }
  147. Reveal.addEventListener( 'fragmentshown', _onEvent );
  148. Reveal.slide( 2, 0 );
  149. Reveal.slide( 2, 0 ); // should do nothing
  150. Reveal.slide( 2, 0, 0 ); // should do nothing
  151. Reveal.next();
  152. Reveal.next();
  153. Reveal.prev(); // shouldn't fire fragmentshown
  154. start();
  155. Reveal.removeEventListener( 'fragmentshown', _onEvent );
  156. });
  157. asyncTest( 'fragmenthidden event', function() {
  158. expect( 2 );
  159. var _onEvent = function( event ) {
  160. ok( true, 'event fired' );
  161. }
  162. Reveal.addEventListener( 'fragmenthidden', _onEvent );
  163. Reveal.slide( 2, 0, 2 );
  164. Reveal.slide( 2, 0, 2 ); // should do nothing
  165. Reveal.prev();
  166. Reveal.prev();
  167. Reveal.next(); // shouldn't fire fragmenthidden
  168. start();
  169. Reveal.removeEventListener( 'fragmenthidden', _onEvent );
  170. });
  171. // ---------------------------------------------------------------
  172. // CONFIGURATION VALUES
  173. QUnit.module( 'Configuration' );
  174. test( 'Controls', function() {
  175. var controlsElement = document.querySelector( '.reveal>.controls' );
  176. Reveal.configure({ controls: false });
  177. equal( controlsElement.style.display, 'none', 'controls are hidden' );
  178. Reveal.configure({ controls: true });
  179. equal( controlsElement.style.display, 'block', 'controls are visible' );
  180. });
  181. test( 'Progress', function() {
  182. var progressElement = document.querySelector( '.reveal>.progress' );
  183. Reveal.configure({ progress: false });
  184. equal( progressElement.style.display, 'none', 'progress are hidden' );
  185. Reveal.configure({ progress: true });
  186. equal( progressElement.style.display, 'block', 'progress are visible' );
  187. });
  188. test( 'Loop', function() {
  189. Reveal.configure({ loop: true });
  190. Reveal.slide( 0, 0 );
  191. Reveal.left();
  192. notEqual( Reveal.getIndices().h, 0, 'looped from start to end' );
  193. Reveal.right();
  194. equal( Reveal.getIndices().h, 0, 'looped from end to start' );
  195. Reveal.configure({ loop: false });
  196. });
  197. // ---------------------------------------------------------------
  198. // EVENT TESTS
  199. QUnit.module( 'Events' );
  200. asyncTest( 'slidechanged', function() {
  201. expect( 3 );
  202. var _onEvent = function( event ) {
  203. ok( true, 'event fired' );
  204. }
  205. Reveal.addEventListener( 'slidechanged', _onEvent );
  206. Reveal.slide( 1, 0 ); // should trigger
  207. Reveal.slide( 1, 0 ); // should do nothing
  208. Reveal.next(); // should trigger
  209. Reveal.slide( 3, 0 ); // should trigger
  210. Reveal.next(); // should do nothing
  211. start();
  212. Reveal.removeEventListener( 'slidechanged', _onEvent );
  213. });
  214. asyncTest( 'paused', function() {
  215. expect( 1 );
  216. var _onEvent = function( event ) {
  217. ok( true, 'event fired' );
  218. }
  219. Reveal.addEventListener( 'paused', _onEvent );
  220. Reveal.togglePause();
  221. Reveal.togglePause();
  222. start();
  223. Reveal.removeEventListener( 'paused', _onEvent );
  224. });
  225. asyncTest( 'resumed', function() {
  226. expect( 1 );
  227. var _onEvent = function( event ) {
  228. ok( true, 'event fired' );
  229. }
  230. Reveal.addEventListener( 'resumed', _onEvent );
  231. Reveal.togglePause();
  232. Reveal.togglePause();
  233. start();
  234. Reveal.removeEventListener( 'resumed', _onEvent );
  235. });
  236. } );
  237. Reveal.initialize();