summaryrefslogtreecommitdiff
path: root/2024-06-18-guix-social/reveal.js/test/test-destroy.html
blob: 1fa9cd2cea7e67e7a3b38ea9fe196b90969a9298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!doctype html>
<html lang="en">

	<head>
		<meta charset="utf-8">

		<title>reveal.js - Test Dependencies</title>

		<link rel="stylesheet" href="../dist/reveal.css">
		<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
		<script src="../node_modules/qunit/qunit/qunit.js"></script>
	</head>

	<body style="overflow: auto;">

		<div id="qunit"></div>
		<div id="qunit-fixture"></div>

		<div class="reveal deck1" style="display: none;">
			<div class="slides">
				<section>Slide content</section>
			</div>
		</div>

		<div class="reveal deck2" style="display: none;">
			<div class="slides">
				<section>Slide content</section>
			</div>
		</div>

		<script type="module">
			import Reveal from '../dist/reveal.esm.js'
			import Markdown from '../plugin/markdown/markdown.esm.js'

			QUnit.module( 'Destroy' );

			QUnit.test( 'Destruction during initialization', function( assert ) {

				let deck = new Reveal( document.querySelector( '.deck1' ) );

				deck.initialize({ plugins: [ Markdown ] });

				let firstAttemptSuccess = false;
				let repeatedAttemptSuccess = false;

				try {
					deck.destroy();
					firstAttemptSuccess = true;
				}
				catch( error ) {
					console.error( error );
				}

				assert.ok( firstAttemptSuccess, 'was successful' );

				// should be able to destroy twice with no side effect
				try {
					deck.destroy();
					repeatedAttemptSuccess = true;
				}
				catch( error ) {
					console.error( error );
				}

				assert.ok( repeatedAttemptSuccess, 'destroyed twice with no exceptions' );

			} );

			QUnit.test( 'Destruction after initialization', function( assert ) {

				assert.expect( 1 );
				let done = assert.async( 1 );
				let deck = new Reveal( document.querySelector( '.deck2' ) );

				deck.initialize({ plugins: [ Markdown ] }).then(() => {
					let wasSuccessful = false;

					try {
						deck.destroy();
						wasSuccessful = true;
					}
					catch( error ) {
						console.error( error );
					}

					if( wasSuccessful ) {
						assert.ok( true, 'was successful' );
					}

					done();
				});

			} );
		</script>

	</body>
</html>