blob: ef97e8c87367fa35bc895e129056e4c3120657a0 [file] [log] [blame]
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +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().then( function() {
43 console.log(Reveal);
44
45 QUnit.module( 'State' );
46
47 QUnit.test( 'Fire events when changing slide', function( assert ) {
48 assert.expect( 2 );
49 var state1 = assert.async();
50 var state2 = assert.async();
51
52 var _onState1 = function( event ) {
53 assert.ok( true, 'state1 fired' );
54 state1();
55 }
56
57 var _onState2 = function( event ) {
58 assert.ok( true, 'state2 fired' );
59 state2();
60 }
61
62 Reveal.on( 'state1', _onState1 );
63 Reveal.on( 'state2', _onState2 );
64
65 Reveal.slide( 1 );
66 Reveal.slide( 3 );
67
68 Reveal.off( 'state1', _onState1 );
69 Reveal.off( 'state2', _onState2 );
70 });
71
72 QUnit.test( 'Fire state events for vertical slides', function( assert ) {
73 assert.expect( 2 );
74 var done = assert.async( 2 );
75
76 var _onState1 = function( event ) {
77 assert.ok( true, 'state1 fired' );
78 done();
79 }
80
81 var _onState3 = function( event ) {
82 assert.ok( true, 'state3 fired' );
83 done();
84 }
85
86 Reveal.on( 'state1', _onState1 );
87 Reveal.on( 'state3', _onState3 );
88
89 Reveal.slide( 0 );
90 Reveal.slide( 4, 1 );
91 Reveal.slide( 4, 2 );
92
93 Reveal.off( 'state1', _onState1 );
94 Reveal.off( 'state3', _onState3 );
95 });
96
97 QUnit.test( 'No events if state remains unchanged', function( assert ) {
98 var stateChanges = 0;
99
100 var _onEvent = function( event ) {
101 stateChanges += 1;
102 }
103
104 Reveal.on( 'state1', _onEvent );
105
106 Reveal.slide( 0 ); // no state
107 Reveal.slide( 1 ); // state1
108 Reveal.slide( 2 ); // state1
109 Reveal.prev(); // state1
110 Reveal.next(); // state1
111 Reveal.slide( 4, 1 ); // state1
112 Reveal.slide( 0 ); // no state
113
114 Reveal.off( 'state1', _onEvent );
115
116 assert.strictEqual( stateChanges, 1, 'no event was fired when going to slide with same state' );
117 });
118
119 QUnit.test( 'Event order', function( assert ) {
120 var _onEvent = function( event ) {
121 assert.ok( Reveal.getCurrentSlide() == document.querySelector( '#slide2' ), 'correct current slide immediately after state event' );
122 }
123
124 Reveal.on( 'state1', _onEvent );
125
126 Reveal.slide( 0 );
127 Reveal.slide( 1 );
128
129 Reveal.off( 'state1', _onEvent );
130 });
131
132 } );
133 </script>
134
135 </body>
136</html>