test.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. });
  87. test( 'Reveal.next', function() {
  88. Reveal.slide( 0, 0 );
  89. // Step through the vertical child slides
  90. Reveal.next();
  91. deepEqual( Reveal.getIndices(), { h: 1, v: 0, f: undefined } );
  92. Reveal.next();
  93. deepEqual( Reveal.getIndices(), { h: 1, v: 1, f: undefined } );
  94. Reveal.next();
  95. deepEqual( Reveal.getIndices(), { h: 1, v: 2, f: undefined } );
  96. // There's fragments on this slide
  97. Reveal.next();
  98. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 } );
  99. Reveal.next();
  100. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 } );
  101. Reveal.next();
  102. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 } );
  103. Reveal.next();
  104. deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 3 } );
  105. Reveal.next();
  106. deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
  107. // We're at the end
  108. Reveal.next();
  109. deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
  110. });
  111. // ---------------------------------------------------------------
  112. // TODO: FRAGMENT TESTS
  113. // ---------------------------------------------------------------
  114. // CONFIGURATION VALUES
  115. QUnit.module( 'Configuration' );
  116. test( 'Controls', function() {
  117. var controlsElement = document.querySelector( '.reveal>.controls' );
  118. Reveal.configure({ controls: false });
  119. equal( controlsElement.style.display, 'none', 'controls are hidden' );
  120. Reveal.configure({ controls: true });
  121. equal( controlsElement.style.display, 'block', 'controls are visible' );
  122. });
  123. test( 'Progress', function() {
  124. var progressElement = document.querySelector( '.reveal>.progress' );
  125. Reveal.configure({ progress: false });
  126. equal( progressElement.style.display, 'none', 'progress are hidden' );
  127. Reveal.configure({ progress: true });
  128. equal( progressElement.style.display, 'block', 'progress are visible' );
  129. });
  130. test( 'Loop', function() {
  131. Reveal.configure({ loop: true });
  132. Reveal.slide( 0, 0 );
  133. Reveal.left();
  134. notEqual( Reveal.getIndices().h, 0, 'looped from start to end' );
  135. Reveal.right();
  136. equal( Reveal.getIndices().h, 0, 'looped from end to start' );
  137. Reveal.configure({ loop: false });
  138. });
  139. // ---------------------------------------------------------------
  140. // EVENT TESTS
  141. QUnit.module( 'Events' );
  142. asyncTest( 'slidechanged', function() {
  143. expect( 1 );
  144. var _onSlideChanged = function( event ) {
  145. ok( true, 'event fired' );
  146. start();
  147. }
  148. Reveal.addEventListener( 'slidechanged', _onSlideChanged );
  149. // Should trigger the event
  150. Reveal.slide( 1, 0 );
  151. // Should not trigger an event since it's the same #
  152. Reveal.slide( 1, 0 );
  153. Reveal.removeEventListener( 'slidechanged', _onSlideChanged );
  154. });
  155. } );
  156. Reveal.initialize();