presentations

Presentations
Log | Files | Refs

test-plugins.html (2713B)


      1 <!doctype html>
      2 <html lang="en">
      3 
      4 	<head>
      5 		<meta charset="utf-8">
      6 
      7 		<title>reveal.js - Test Plugins</title>
      8 
      9 		<link rel="stylesheet" href="../css/reveal.css">
     10 		<link rel="stylesheet" href="qunit-2.5.0.css">
     11 	</head>
     12 
     13 	<body style="overflow: auto;">
     14 
     15 		<div id="qunit"></div>
     16 		<div id="qunit-fixture"></div>
     17 
     18 		<div class="reveal" style="display: none;">
     19 
     20 			<div class="slides">
     21 
     22 				<section>Slide content</section>
     23 
     24 			</div>
     25 
     26 		</div>
     27 
     28 		<script src="../js/reveal.js"></script>
     29 		<script src="qunit-2.5.0.js"></script>
     30 
     31 		<script>
     32 
     33 			QUnit.module( 'Plugins' );
     34 
     35 			var initCounter = { PluginB: 0, PluginC: 0, PluginD: 0 };
     36 
     37 			// Plugin with no init method
     38 			var PluginA = {};
     39 
     40 			// Plugin with init method
     41 			var PluginB = { init: function() {
     42 				initCounter['PluginB'] += 1;
     43 			} };
     44 
     45 			// Async plugin with init method
     46 			var PluginC = { init: function() {
     47 				return new Promise(function( resolve ) {
     48 					setTimeout( () => {
     49 						initCounter['PluginC'] += 1;
     50 						resolve();
     51 					}, 1000 );
     52 				});
     53 			} };
     54 
     55 			// Plugin initialized after reveal.js is ready
     56 			var PluginD = { init: function() {
     57 				initCounter['PluginD'] += 1;
     58 			} };
     59 
     60 			var PluginE = {};
     61 
     62 			Reveal.registerPlugin( 'PluginA', PluginA );
     63 			Reveal.registerPlugin( 'PluginB', PluginB );
     64 			Reveal.registerPlugin( 'PluginC', PluginC );
     65 
     66 			Reveal.initialize();
     67 
     68 			QUnit.test( 'Can initialize synchronously', function( assert ) {
     69 				assert.strictEqual( initCounter['PluginB'], 1 );
     70 
     71 				Reveal.registerPlugin( 'PluginB', PluginB );
     72 
     73 				assert.strictEqual( initCounter['PluginB'], 1, 'prevents duplicate registration' );
     74 			});
     75 
     76 			QUnit.test( 'Can initialize asynchronously', function( assert ) {
     77 				assert.expect( 3 );
     78 				var done = assert.async( 2 );
     79 
     80 				assert.strictEqual( initCounter['PluginC'], 0, 'async plugin not immediately initialized' );
     81 
     82 				Reveal.addEventListener( 'ready', function() {
     83 					assert.strictEqual( initCounter['PluginC'], 1, 'finsihed initializing when reveal.js dispatches "ready"' );
     84 					done();
     85 
     86 					Reveal.registerPlugin( 'PluginD', PluginD );
     87 					assert.strictEqual( initCounter['PluginD'], 1, 'plugin registered after reveal.js is ready still initiailizes' );
     88 					done();
     89 				});
     90 			} );
     91 
     92 			QUnit.test( 'Can check if plugin is registered', function( assert ) {
     93 				assert.strictEqual( Reveal.hasPlugin( 'PluginA' ), true );
     94 				assert.strictEqual( Reveal.hasPlugin( 'PluginE' ), false );
     95 				Reveal.registerPlugin( 'PluginE', PluginE );
     96 				assert.strictEqual( Reveal.hasPlugin( 'PluginE' ), true );
     97 			} );
     98 
     99 			QUnit.test( 'Can retrieve plugin instance', function( assert ) {
    100 				assert.strictEqual( Reveal.getPlugin( 'PluginB' ), PluginB );
    101 			} );
    102 		</script>
    103 
    104 	</body>
    105 </html>