1
0
Fork 0
why-cant-we-deploy-today/test/test-plugins.html

107 lines
2.7 KiB
HTML
Raw Normal View History

2019-03-14 16:03:55 +01:00
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>reveal.js - Test Plugins</title>
2020-03-06 20:12:20 +01:00
<link rel="stylesheet" href="../dist/reveal.css">
2019-03-14 16:03:55 +01:00
<link rel="stylesheet" href="qunit-2.5.0.css">
<script src="qunit-2.5.0.js"></script>
2019-03-14 16:03:55 +01:00
</head>
<body style="overflow: auto;">
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div class="reveal" style="display: none;">
<div class="slides">
<section>Slide content</section>
</div>
</div>
2020-03-06 20:12:20 +01:00
<script src="../dist/reveal.min.js"></script>
2019-03-14 16:03:55 +01:00
<script>
QUnit.module( 'Plugins' );
var initCounter = { PluginB: 0, PluginC: 0, PluginD: 0 };
// Plugin with no init method
var PluginA = {};
// Plugin with init method
var PluginB = { init: function() {
initCounter['PluginB'] += 1;
} };
// Async plugin with init method
var PluginC = { init: function() {
return new Promise(function( resolve ) {
setTimeout( () => {
initCounter['PluginC'] += 1;
resolve();
}, 1000 );
});
} };
// Plugin initialized after reveal.js is ready
var PluginD = { init: function() {
initCounter['PluginD'] += 1;
} };
var PluginE = {};
var reveal = new Reveal( document.querySelector( '.reveal' ) );
reveal.registerPlugin( 'PluginA', PluginA );
reveal.registerPlugin( 'PluginB', PluginB );
reveal.registerPlugin( 'PluginC', PluginC );
2019-03-14 16:03:55 +01:00
reveal.initialize();
2019-03-14 16:03:55 +01:00
QUnit.test( 'Can initialize synchronously', function( assert ) {
assert.strictEqual( initCounter['PluginB'], 1 );
reveal.registerPlugin( 'PluginB', PluginB );
2019-03-14 16:03:55 +01:00
assert.strictEqual( initCounter['PluginB'], 1, 'prevents duplicate registration' );
});
QUnit.test( 'Can initialize asynchronously', function( assert ) {
2019-03-14 16:03:55 +01:00
assert.expect( 3 );
var done = assert.async( 2 );
assert.strictEqual( initCounter['PluginC'], 0, 'async plugin not immediately initialized' );
reveal.addEventListener( 'ready', function() {
2019-03-14 16:03:55 +01:00
assert.strictEqual( initCounter['PluginC'], 1, 'finsihed initializing when reveal.js dispatches "ready"' );
done();
reveal.registerPlugin( 'PluginD', PluginD );
2019-03-14 16:03:55 +01:00
assert.strictEqual( initCounter['PluginD'], 1, 'plugin registered after reveal.js is ready still initiailizes' );
done();
});
} );
QUnit.test( 'Can check if plugin is registered', function( assert ) {
assert.strictEqual( reveal.hasPlugin( 'PluginA' ), true );
assert.strictEqual( reveal.hasPlugin( 'PluginE' ), false );
reveal.registerPlugin( 'PluginE', PluginE );
assert.strictEqual( reveal.hasPlugin( 'PluginE' ), true );
} );
QUnit.test( 'Can retrieve plugin instance', function( assert ) {
assert.strictEqual( reveal.getPlugin( 'PluginB' ), PluginB );
} );
2019-03-14 16:03:55 +01:00
</script>
</body>
</html>