blob: c2d50557a29285f0e8aa3059634a634cae26fed1 [file] [log] [blame]
Marc Kupietz09b75752023-10-07 09:32:19 +02001<!doctype html>
2<html lang="en">
3
4 <head>
5 <meta charset="utf-8">
6
7 <title>reveal.js - Test State</title>
8
9 <link rel="stylesheet" href="../dist/reveal.css">
10 <link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
11 <script src="../node_modules/qunit/qunit/qunit.js"></script>
12 </head>
13
14 <body style="overflow: auto;">
15
16 <div id="qunit"></div>
17 <div id="qunit-fixture"></div>
18
19 <div class="reveal" style="display: none;">
20
21 <div class="slides">
22
23 <section>No state</section>
24 <section id="slide2" data-state="state1">State 1</section>
25 <section data-state="state1">State 1</section>
26 <section data-state="state2">State 2</section>
27 <section>
28 <section>No state</section>
29 <section data-state="state1">State 1</section>
30 <section data-state="state3">State 3</section>
31 <section>No state</section>
32 </section>
33 <section>No state</section>
34
35 </div>
36
37 </div>
38
39 <script src="../dist/reveal.js"></script>
40 <script>
41
42 Reveal.initialize();
43
44 QUnit.module( 'State' );
45
46 QUnit.test( 'Fire events when changing slide', function( assert ) {
47 assert.expect( 2 );
48 var state1 = assert.async();
49 var state2 = assert.async();
50
51 var _onState1 = function( event ) {
52 assert.ok( true, 'state1 fired' );
53 state1();
54 }
55
56 var _onState2 = function( event ) {
57 assert.ok( true, 'state2 fired' );
58 state2();
59 }
60
61 Reveal.on( 'state1', _onState1 );
62 Reveal.on( 'state2', _onState2 );
63
64 Reveal.slide( 1 );
65 Reveal.slide( 3 );
66
67 Reveal.off( 'state1', _onState1 );
68 Reveal.off( 'state2', _onState2 );
69 });
70
71 QUnit.test( 'Fire state events for vertical slides', function( assert ) {
72 assert.expect( 2 );
73 var done = assert.async( 2 );
74
75 var _onState1 = function( event ) {
76 assert.ok( true, 'state1 fired' );
77 done();
78 }
79
80 var _onState3 = function( event ) {
81 assert.ok( true, 'state3 fired' );
82 done();
83 }
84
85 Reveal.on( 'state1', _onState1 );
86 Reveal.on( 'state3', _onState3 );
87
88 Reveal.slide( 0 );
89 Reveal.slide( 4, 1 );
90 Reveal.slide( 4, 2 );
91
92 Reveal.off( 'state1', _onState1 );
93 Reveal.off( 'state3', _onState3 );
94 });
95
96 QUnit.test( 'No events if state remains unchanged', function( assert ) {
97 var stateChanges = 0;
98
99 var _onEvent = function( event ) {
100 stateChanges += 1;
101 }
102
103 Reveal.on( 'state1', _onEvent );
104
105 Reveal.slide( 0 ); // no state
106 Reveal.slide( 1 ); // state1
107 Reveal.slide( 2 ); // state1
108 Reveal.prev(); // state1
109 Reveal.next(); // state1
110 Reveal.slide( 4, 1 ); // state1
111 Reveal.slide( 0 ); // no state
112
113 Reveal.off( 'state1', _onEvent );
114
115 assert.strictEqual( stateChanges, 1, 'no event was fired when going to slide with same state' );
116 });
117
118 QUnit.test( 'Event order', function( assert ) {
119 var _onEvent = function( event ) {
120 assert.ok( Reveal.getCurrentSlide() == document.querySelector( '#slide2' ), 'correct current slide immediately after state event' );
121 }
122
123 Reveal.on( 'state1', _onEvent );
124
125 Reveal.slide( 0 );
126 Reveal.slide( 1 );
127
128 Reveal.off( 'state1', _onEvent );
129 });
130
131 </script>
132
133 </body>
134</html>