summaryrefslogtreecommitdiff
path: root/2024-06-18-guix-social/reveal.js/test/test-state.html
blob: c2d50557a29285f0e8aa3059634a634cae26fed1 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!doctype html>
<html lang="en">

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

		<title>reveal.js - Test State</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" style="display: none;">

			<div class="slides">

				<section>No state</section>
				<section id="slide2" data-state="state1">State 1</section>
				<section data-state="state1">State 1</section>
				<section data-state="state2">State 2</section>
				<section>
					<section>No state</section>
					<section data-state="state1">State 1</section>
					<section data-state="state3">State 3</section>
					<section>No state</section>
				</section>
				<section>No state</section>

			</div>

		</div>

		<script src="../dist/reveal.js"></script>
		<script>

			Reveal.initialize();

			QUnit.module( 'State' );

			QUnit.test( 'Fire events when changing slide', function( assert ) {
				assert.expect( 2 );
				var state1 = assert.async();
				var state2 = assert.async();

				var _onState1 = function( event ) {
					assert.ok( true, 'state1 fired' );
					state1();
				}

				var _onState2 = function( event ) {
					assert.ok( true, 'state2 fired' );
					state2();
				}

				Reveal.on( 'state1', _onState1 );
				Reveal.on( 'state2', _onState2 );

				Reveal.slide( 1 );
				Reveal.slide( 3 );

				Reveal.off( 'state1', _onState1 );
				Reveal.off( 'state2', _onState2 );
			});

			QUnit.test( 'Fire state events for vertical slides', function( assert ) {
				assert.expect( 2 );
				var done = assert.async( 2 );

				var _onState1 = function( event ) {
					assert.ok( true, 'state1 fired' );
					done();
				}

				var _onState3 = function( event ) {
					assert.ok( true, 'state3 fired' );
					done();
				}

				Reveal.on( 'state1', _onState1 );
				Reveal.on( 'state3', _onState3 );

				Reveal.slide( 0 );
				Reveal.slide( 4, 1 );
				Reveal.slide( 4, 2 );

				Reveal.off( 'state1', _onState1 );
				Reveal.off( 'state3', _onState3 );
			});

			QUnit.test( 'No events if state remains unchanged', function( assert ) {
				var stateChanges = 0;

				var _onEvent = function( event ) {
					stateChanges += 1;
				}

				Reveal.on( 'state1', _onEvent );

				Reveal.slide( 0 );      // no state
				Reveal.slide( 1 );      // state1
				Reveal.slide( 2 );      // state1
				Reveal.prev();          // state1
				Reveal.next();          // state1
				Reveal.slide( 4, 1 );   // state1
				Reveal.slide( 0 );      // no state

				Reveal.off( 'state1', _onEvent );

				assert.strictEqual( stateChanges, 1, 'no event was fired when going to slide with same state' );
			});

			QUnit.test( 'Event order', function( assert ) {
				var _onEvent = function( event ) {
					assert.ok( Reveal.getCurrentSlide() == document.querySelector( '#slide2' ), 'correct current slide immediately after state event' );
				}

				Reveal.on( 'state1', _onEvent );

				Reveal.slide( 0 );
				Reveal.slide( 1 );

				Reveal.off( 'state1', _onEvent );
			});

		</script>

	</body>
</html>