test-auto-animate.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test Auto-Animate</title>
  6. </head>
  7. <body style="overflow: auto;">
  8. <div id="qunit"></div>
  9. <div id="qunit-fixture"></div>
  10. <div class="reveal">
  11. <div class="slides">
  12. <section data-auto-animate>
  13. <h1>h1</h1>
  14. <h2>h2</h2>
  15. <h3 style="position: absolute; left: 0;">h3</h3>
  16. </section>
  17. <section data-auto-animate>
  18. <h1 data-auto-animate-duration="0.1">h1</h1>
  19. <h2 style="opacity: 0;">h2</h2>
  20. <h3 style="position: absolute; left: 100px;">h3</h3>
  21. </section>
  22. <section data-auto-animate data-auto-animate-duration="0.1">
  23. <h1>h1</h1>
  24. <h2>h2</h2>
  25. <h3>h3</h3>
  26. </section>
  27. <section>
  28. <h1>Non-auto-animate slide</h1>
  29. </section>
  30. <section data-auto-animate>
  31. <h1 class="fragment">h1</h1>
  32. <h2 class="fragment">h2</h2>
  33. <h3>h3</h3>
  34. </section>
  35. <section data-auto-animate>
  36. <h1 class="fragment">h1</h1>
  37. <h2 class="fragment">h2</h2>
  38. <h3 class="fragment">h3</h3>
  39. </section>
  40. <section>
  41. <h1>Non-auto-animate slide</h1>
  42. </section>
  43. </div>
  44. </div>
  45. <script type="module">
  46. import 'reveal.css';
  47. import 'qunit/qunit/qunit.css';
  48. import QUnit from 'qunit';
  49. import Reveal from 'reveal.js';
  50. QUnit.config.testTimeout = 30000;
  51. QUnit.config.reorder = false;
  52. QUnit.config.autostart = false;
  53. const slides = Array.prototype.map.call( document.querySelectorAll( '.slides section' ), slide => {
  54. return {
  55. slide: slide,
  56. h1: slide.querySelector( 'h1' ),
  57. h2: slide.querySelector( 'h2' ),
  58. h3: slide.querySelector( 'h3' )
  59. };
  60. } );
  61. QUnit.module( 'Auto-Animate' );
  62. Reveal.initialize().then( () => {
  63. QUnit.start();
  64. QUnit.test( 'Adds data-auto-animate-target', assert => {
  65. Reveal.slide(1);
  66. assert.strictEqual( slides[0].h1.getAttribute( 'data-auto-animate-target' ), '', 'From elements have blank data-auto-animate-target' );
  67. assert.ok( slides[1].h1.getAttribute( 'data-auto-animate-target' ).length > 0, 'To elements have a data-auto-animate-target value' );
  68. });
  69. QUnit.test( 'Ends on correct target styles', assert => {
  70. Reveal.slide(1);
  71. assert.strictEqual( slides[1].h2.style.opacity, "0" );
  72. assert.strictEqual( slides[1].h3.offsetLeft, 100 );
  73. });
  74. QUnit.test( 'Does not add [data-auto-animate] on non auto-animated slides', assert => {
  75. Reveal.slide(2);
  76. Reveal.next();
  77. assert.ok( slides[3].slide.hasAttribute( 'data-auto-animate' ) === false )
  78. });
  79. QUnit.test( 'autoAnimate config option', assert => {
  80. Reveal.configure({ autoAnimate: false });
  81. assert.ok( document.querySelectorAll( 'data-auto-animate-target' ).length === 0, 'Removes all [data-auto-animate-target]' )
  82. assert.ok( Array.prototype.every.call( document.querySelectorAll( 'section[data-auto-animate]' ), el => {
  83. return el.dataset.autoAnimate === '';
  84. }, 'All data-auto-animate attributes are reset' ) );
  85. Reveal.configure({ autoAnimate: true });
  86. });
  87. QUnit.test( 'Slide specific data-auto-animate-duration', assert => {
  88. assert.timeout( 2000 );
  89. assert.expect( 1 );
  90. return new Promise( resolve => {
  91. let callback = () => {
  92. slides[2].h3.removeEventListener( 'transitionend', callback );
  93. assert.ok( true, 'Transition ended within time window' );
  94. resolve();
  95. }
  96. Reveal.slide(1);
  97. Reveal.slide(2);
  98. slides[2].h3.addEventListener( 'transitionend', callback );
  99. } );
  100. });
  101. // QUnit.test( 'Element specific data-auto-animate-duration', assert => {
  102. // assert.timeout( 400 );
  103. // assert.expect( 1 );
  104. // return new Promise( resolve => {
  105. // let callback = () => {
  106. // slides[1].h1.removeEventListener( 'transitionend', callback );
  107. // assert.ok( true, 'Transition ended within time window' );
  108. // resolve()
  109. // }
  110. // Reveal.slide(1);
  111. // slides[1].h1.addEventListener( 'transitionend', callback );
  112. // } );
  113. // });
  114. } );
  115. </script>
  116. </body>
  117. </html>