test-plugins.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test Plugins</title>
  6. <link rel="stylesheet" href="../css/reveal.css">
  7. <link rel="stylesheet" href="qunit-2.5.0.css">
  8. </head>
  9. <body style="overflow: auto;">
  10. <div id="qunit"></div>
  11. <div id="qunit-fixture"></div>
  12. <div class="reveal" style="display: none;">
  13. <div class="slides">
  14. <section>Slide content</section>
  15. </div>
  16. </div>
  17. <script src="../js/reveal.js"></script>
  18. <script src="qunit-2.5.0.js"></script>
  19. <script>
  20. QUnit.module( 'Plugins' );
  21. var initCounter = { PluginB: 0, PluginC: 0, PluginD: 0 };
  22. // Plugin with no init method
  23. var PluginA = {};
  24. // Plugin with init method
  25. var PluginB = { init: function() {
  26. initCounter['PluginB'] += 1;
  27. } };
  28. // Async plugin with init method
  29. var PluginC = { init: function() {
  30. return new Promise(function( resolve ) {
  31. setTimeout( () => {
  32. initCounter['PluginC'] += 1;
  33. resolve();
  34. }, 1000 );
  35. });
  36. } };
  37. // Plugin initialized after reveal.js is ready
  38. var PluginD = { init: function() {
  39. initCounter['PluginD'] += 1;
  40. } };
  41. Reveal.registerPlugin( 'PluginA', PluginA );
  42. Reveal.registerPlugin( 'PluginB', PluginB );
  43. Reveal.registerPlugin( 'PluginC', PluginC );
  44. Reveal.initialize();
  45. QUnit.test( 'Can initialize synchronously', function( assert ) {
  46. assert.strictEqual( initCounter['PluginB'], 1 );
  47. Reveal.registerPlugin( 'PluginB', PluginB );
  48. assert.strictEqual( initCounter['PluginB'], 1, 'prevents duplicate registration' );
  49. });
  50. QUnit.test( 'Can initialie asynchronously', function( assert ) {
  51. assert.expect( 3 );
  52. var done = assert.async( 2 );
  53. assert.strictEqual( initCounter['PluginC'], 0, 'async plugin not immediately initialized' );
  54. Reveal.addEventListener( 'ready', function() {
  55. assert.strictEqual( initCounter['PluginC'], 1, 'finsihed initializing when reveal.js dispatches "ready"' );
  56. done();
  57. Reveal.registerPlugin( 'PluginD', PluginD );
  58. assert.strictEqual( initCounter['PluginD'], 1, 'plugin registered after reveal.js is ready still initiailizes' );
  59. done();
  60. });
  61. } );
  62. </script>
  63. </body>
  64. </html>