You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

109 rivejä
2.8 KiB

  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="../dist/reveal.css">
  7. <link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
  8. <script src="../node_modules/qunit/qunit/qunit.js"></script>
  9. </head>
  10. <body style="overflow: auto;">
  11. <div id="qunit"></div>
  12. <div id="qunit-fixture"></div>
  13. <div class="reveal" style="display: none;">
  14. <div class="slides">
  15. <section>Slide content</section>
  16. </div>
  17. </div>
  18. <script src="../dist/reveal.js"></script>
  19. <script>
  20. QUnit.config.testTimeout = 30000;
  21. QUnit.module( 'Plugins' );
  22. var initCounter = { PluginB: 0, PluginC: 0, PluginD: 0 };
  23. // Plugin with no init method
  24. var PluginA = { id: 'PluginA' };
  25. // Plugin with init method
  26. var PluginB = { id: 'PluginB', init: function() {
  27. initCounter['PluginB'] += 1;
  28. } };
  29. // Async plugin with init method
  30. var PluginC = { id: 'PluginC', init: function() {
  31. return new Promise(function( resolve ) {
  32. setTimeout( () => {
  33. initCounter['PluginC'] += 1;
  34. resolve();
  35. }, 1000 );
  36. });
  37. } };
  38. // Plugin initialized after reveal.js is ready
  39. var PluginD = { id: 'PluginD', init: function() {
  40. initCounter['PluginD'] += 1;
  41. } };
  42. var PluginE = { id: 'PluginE' };
  43. var reveal = new Reveal( document.querySelector( '.reveal' ), {
  44. plugins: [ PluginA ]
  45. } );
  46. reveal.registerPlugin( PluginB );
  47. reveal.registerPlugin( PluginC );
  48. reveal.initialize();
  49. QUnit.test( 'Can initialize synchronously', function( assert ) {
  50. assert.strictEqual( initCounter['PluginB'], 1 );
  51. reveal.registerPlugin( PluginB );
  52. assert.strictEqual( initCounter['PluginB'], 1, 'prevents duplicate registration' );
  53. });
  54. QUnit.test( 'Can initialize asynchronously', function( assert ) {
  55. assert.expect( 3 );
  56. var done = assert.async( 2 );
  57. assert.strictEqual( initCounter['PluginC'], 0, 'async plugin not immediately initialized' );
  58. reveal.on( 'ready', function() {
  59. assert.strictEqual( initCounter['PluginC'], 1, 'finsihed initializing when reveal.js dispatches "ready"' );
  60. done();
  61. reveal.registerPlugin( PluginD );
  62. assert.strictEqual( initCounter['PluginD'], 1, 'plugin registered after reveal.js is ready still initiailizes' );
  63. done();
  64. });
  65. } );
  66. QUnit.test( 'Can check if plugin is registered', function( assert ) {
  67. assert.strictEqual( reveal.hasPlugin( 'PluginA' ), true );
  68. assert.strictEqual( reveal.hasPlugin( 'PluginE' ), false );
  69. reveal.registerPlugin( PluginE );
  70. assert.strictEqual( reveal.hasPlugin( 'PluginE' ), true );
  71. } );
  72. QUnit.test( 'Can retrieve plugin instance', function( assert ) {
  73. assert.strictEqual( reveal.getPlugin( 'PluginB' ), PluginB );
  74. } );
  75. </script>
  76. </body>
  77. </html>