blob: ab44922aee7139f8a9537efbdc75eda9e1e0e575 [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 - Tests</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="visibility: hidden;">
20
21 <div class="slides">
22
23 <section data-visibility="hidden">
24 This should be remove by reveal.js before our tests run.
25 </section>
26
27 <section data-background-image="examples/assets/image1.png">
28 <h1>1</h1>
29 <img data-src="">
30 <video data-src=""></video>
31 <audio data-src=""></audio>
32 <aside class="notes">speaker notes 1</aside>
33 </section>
34
35 <section>
36 <section data-background="examples/assets/image2.png" data-notes="speaker notes 2">
37 <h1>2.1</h1>
38 </section>
Christophe Dervieux8afae132021-12-06 15:16:42 +010039 <section data-background-image="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/">
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020040 <h1>2.2</h1>
41 </section>
42 <section>
43 <h1>2.3</h1>
44 </section>
45 </section>
46
47 <section id="fragment-slides">
48 <section>
49 <h1>3.1</h1>
50 <ul>
51 <li class="fragment">4.1</li>
52 <li class="fragment">4.2</li>
53 <li class="fragment">4.3</li>
54 </ul>
55 </section>
56
57 <section>
58 <h1>3.2</h1>
59 <ul>
60 <li class="fragment" data-fragment-index="0">4.1</li>
61 <li class="fragment" data-fragment-index="0">4.2</li>
62 </ul>
63 <iframe data-src="http://example.com"></iframe>
64 </section>
65
66 <section id="fragments3">
67 <h1>3.3</h1>
68 <ul>
69 <li class="fragment" data-fragment-index="1">3.3.1</li>
70 <li class="fragment" data-fragment-index="4">3.3.2</li>
71 <li class="fragment" data-fragment-index="4">3.3.3</li>
72 </ul>
73 </section>
74 </section>
75
76 <section>
77 <h1>4</h1>
78 </section>
79
80 </div>
81
82 </div>
83
84 <script src="../dist/reveal.js"></script>
85 <script>
Marc Kupietz09b75752023-10-07 09:32:19 +020086 QUnit.config.testTimeout = 30000;
87
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020088 window.location.hash = '';
89
90 Reveal.configure({maxScale: 1.11});
91
92 // These tests expect the DOM to contain a presentation
93 // with the following slide structure:
94 //
95 // 1
96 // 2 - Three sub-slides
97 // 3 - Three fragment elements
98 // 3 - Two fragments with same data-fragment-index
99 // 4
100 Reveal.initialize().then( function() {
101
Christophe Dervieux8afae132021-12-06 15:16:42 +0100102 // Helper methods
103 function triggerKeyboardEvent(config) {
104 document.dispatchEvent( new KeyboardEvent( 'keydown', config ) );
105 }
106
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200107 // ---------------------------------------------------------------
108 // DOM TESTS
109
110 QUnit.module( 'DOM' );
111
112 QUnit.test( 'Initial slides classes', function( assert ) {
113 var horizontalSlides = document.querySelectorAll( '.reveal .slides>section' )
114
115 assert.strictEqual( document.querySelectorAll( '.reveal .slides section[data-visibility="hidden"]' ).length, 0, 'no data-visibility="hidden" slides' );
116 assert.strictEqual( document.querySelectorAll( '.reveal .slides section.past' ).length, 0, 'no .past slides' );
117 assert.strictEqual( document.querySelectorAll( '.reveal .slides section.present' ).length, 1, 'one .present slide' );
118 assert.strictEqual( document.querySelectorAll( '.reveal .slides>section.future' ).length, horizontalSlides.length - 1, 'remaining horizontal slides are .future' );
119
120 assert.strictEqual( document.querySelectorAll( '.reveal .slides section.stack' ).length, 2, 'two .stacks' );
121
122 assert.ok( document.querySelectorAll( '.reveal .slides section.stack' )[0].querySelectorAll( '.future' ).length > 0, 'vertical slides are given .future' );
123 });
124
125 // ---------------------------------------------------------------
126 // API TESTS
127
128 QUnit.module( 'API' );
129
130 QUnit.test( 'Reveal.configure before initialization', function( assert ) {
131 assert.strictEqual( Reveal.getConfig().maxScale, 1.11 );
132 });
133
134 QUnit.test( 'Reveal.isReady', function( assert ) {
135 assert.strictEqual( Reveal.isReady(), true, 'returns true' );
136 });
137
138 QUnit.test( 'Reveal.isOverview', function( assert ) {
139 assert.strictEqual( Reveal.isOverview(), false, 'false by default' );
140
141 Reveal.toggleOverview();
142 assert.strictEqual( Reveal.isOverview(), true, 'true after toggling on' );
143
144 Reveal.toggleOverview();
145 assert.strictEqual( Reveal.isOverview(), false, 'false after toggling off' );
146 });
147
148 QUnit.test( 'Reveal.isPaused', function( assert ) {
149 assert.strictEqual( Reveal.isPaused(), false, 'false by default' );
150
151 Reveal.togglePause();
152 assert.strictEqual( Reveal.isPaused(), true, 'true after pausing' );
153
154 Reveal.togglePause();
155 assert.strictEqual( Reveal.isPaused(), false, 'false after resuming' );
156 });
157
158 QUnit.test( 'Reveal.isFirstSlide', function( assert ) {
159 Reveal.slide( 0, 0 );
160 assert.strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' );
161
162 Reveal.slide( 1, 0 );
163 assert.strictEqual( Reveal.isFirstSlide(), false, 'false after Reveal.slide( 1, 0 )' );
164
165 Reveal.slide( 0, 0 );
166 assert.strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )' );
167 });
168
169 QUnit.test( 'Reveal.isFirstSlide after vertical slide', function( assert ) {
170 Reveal.slide( 1, 1 );
171 Reveal.slide( 0, 0 );
172 assert.strictEqual( Reveal.isFirstSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( 0, 0 )' );
173 });
174
175 QUnit.test( 'Reveal.isLastSlide', function( assert ) {
176 Reveal.slide( 0, 0 );
177 assert.strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
178
179 var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
180
181 Reveal.slide( lastSlideIndex, 0 );
182 assert.strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( '+ lastSlideIndex +', 0 )' );
183
184 Reveal.slide( 0, 0 );
185 assert.strictEqual( Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )' );
186 });
187
188 QUnit.test( 'Reveal.isLastSlide after vertical slide', function( assert ) {
189 var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
190
191 Reveal.slide( 1, 1 );
192 Reveal.slide( lastSlideIndex );
193 assert.strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( '+ lastSlideIndex +', 0 )' );
194 });
195
196 QUnit.test( 'Reveal.getTotalSlides', function( assert ) {
197 assert.strictEqual( Reveal.getTotalSlides(), 8, 'eight slides in total' );
198 });
199
200 QUnit.test( 'Reveal.getIndices', function( assert ) {
201 var indices = Reveal.getIndices();
202
203 assert.ok( indices.hasOwnProperty( 'h' ), 'h exists' );
204 assert.ok( indices.hasOwnProperty( 'v' ), 'v exists' );
205 assert.ok( indices.hasOwnProperty( 'f' ), 'f exists' );
206
207 Reveal.slide( 1, 0 );
208 assert.strictEqual( Reveal.getIndices().h, 1, 'h 1' );
209 assert.strictEqual( Reveal.getIndices().v, 0, 'v 0' );
210
211 Reveal.slide( 1, 2 );
212 assert.strictEqual( Reveal.getIndices().h, 1, 'h 1' );
213 assert.strictEqual( Reveal.getIndices().v, 2, 'v 2' );
214
215 Reveal.slide( 0, 0 );
216 assert.strictEqual( Reveal.getIndices().h, 0, 'h 0' );
217 assert.strictEqual( Reveal.getIndices().v, 0, 'v 0' );
218 });
219
220 QUnit.test( 'Reveal.getSlide', function( assert ) {
221 assert.equal( Reveal.getSlide( 0 ), document.querySelector( '.reveal .slides>section:first-child' ), 'gets correct first slide' );
222 assert.equal( Reveal.getSlide( 1 ), document.querySelector( '.reveal .slides>section:nth-child(2)' ), 'no v index returns stack' );
223 assert.equal( Reveal.getSlide( 1, 0 ), document.querySelector( '.reveal .slides>section:nth-child(2)>section:nth-child(1)' ), 'v index 0 returns first vertical child' );
224 assert.equal( Reveal.getSlide( 1, 1 ), document.querySelector( '.reveal .slides>section:nth-child(2)>section:nth-child(2)' ), 'v index 1 returns second vertical child' );
225
226 assert.strictEqual( Reveal.getSlide( 100 ), undefined, 'undefined when out of horizontal bounds' );
227 assert.strictEqual( Reveal.getSlide( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
228 });
229
230 QUnit.test( 'Reveal.getSlideBackground', function( assert ) {
231 assert.equal( Reveal.getSlideBackground( 0 ), document.querySelector( '.reveal .backgrounds>.slide-background:first-child' ), 'gets correct first background' );
232 assert.equal( Reveal.getSlideBackground( 1 ), document.querySelector( '.reveal .backgrounds>.slide-background:nth-child(2)' ), 'no v index returns stack' );
233 assert.equal( Reveal.getSlideBackground( 1, 0 ), document.querySelector( '.reveal .backgrounds>.slide-background:nth-child(2) .slide-background:nth-child(2)' ), 'v index 0 returns first vertical child' );
234 assert.equal( Reveal.getSlideBackground( 1, 1 ), document.querySelector( '.reveal .backgrounds>.slide-background:nth-child(2) .slide-background:nth-child(3)' ), 'v index 1 returns second vertical child' );
235
236 assert.strictEqual( Reveal.getSlideBackground( 100 ), undefined, 'undefined when out of horizontal bounds' );
237 assert.strictEqual( Reveal.getSlideBackground( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
238 });
239
240 QUnit.test( 'Reveal.getSlideNotes', function( assert ) {
241 Reveal.slide( 0, 0 );
242 assert.ok( Reveal.getSlideNotes() === 'speaker notes 1', 'works with <aside class="notes">' );
243
244 Reveal.slide( 1, 0 );
245 assert.ok( Reveal.getSlideNotes() === 'speaker notes 2', 'works with <section data-notes="">' );
246 });
247
248 QUnit.test( 'Reveal.getPreviousSlide/getCurrentSlide', function( assert ) {
249 Reveal.slide( 0, 0 );
250 Reveal.slide( 1, 0 );
251
252 var firstSlide = document.querySelector( '.reveal .slides>section:first-child' );
253 var secondSlide = document.querySelector( '.reveal .slides>section:nth-child(2)>section' );
254
255 assert.equal( Reveal.getPreviousSlide(), firstSlide, 'previous is slide #0' );
256 assert.equal( Reveal.getCurrentSlide(), secondSlide, 'current is slide #1' );
257 });
258
259 QUnit.test( 'Reveal.getProgress', function( assert ) {
260 Reveal.slide( 0, 0 );
261 assert.strictEqual( Reveal.getProgress(), 0, 'progress is 0 on first slide' );
262
263 var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
264
265 Reveal.slide( lastSlideIndex, 0 );
266 assert.strictEqual( Reveal.getProgress(), 1, 'progress is 1 on last slide' );
267 });
268
269 QUnit.test( 'Reveal.getScale', function( assert ) {
270 assert.ok( typeof Reveal.getScale() === 'number', 'has scale' );
271 });
272
273 QUnit.test( 'Reveal.getConfig', function( assert ) {
274 assert.ok( typeof Reveal.getConfig() === 'object', 'has config' );
275 });
276
277 QUnit.test( 'Reveal.configure', function( assert ) {
278 assert.strictEqual( Reveal.getConfig().loop, false, '"loop" is false to start with' );
279
280 Reveal.configure({ loop: true });
281 assert.strictEqual( Reveal.getConfig().loop, true, '"loop" has changed to true' );
282
283 Reveal.configure({ loop: false, customTestValue: 1 });
284 assert.strictEqual( Reveal.getConfig().customTestValue, 1, 'supports custom values' );
285 });
286
287 QUnit.test( 'Reveal.availableRoutes', function( assert ) {
288 Reveal.slide( 0, 0 );
289 assert.deepEqual( Reveal.availableRoutes(), { left: false, up: false, down: false, right: true }, 'correct for first slide' );
290
291 Reveal.slide( 1, 0 );
292 assert.deepEqual( Reveal.availableRoutes(), { left: true, up: false, down: true, right: true }, 'correct for vertical slide' );
293
294 Reveal.slide( 0, 0 );
295 assert.deepEqual( Reveal.availableRoutes({ includeFragments: true }), { left: false, up: false, down: false, right: true }, 'correct with fragments included' );
296 });
297
298 QUnit.test( 'Reveal.next', function( assert ) {
299 Reveal.slide( 0, 0 );
300
301 // Step through vertical child slides
302 Reveal.next();
303 assert.deepEqual( Reveal.getIndices(), { h: 1, v: 0, f: undefined } );
304
305 Reveal.next();
306 assert.deepEqual( Reveal.getIndices(), { h: 1, v: 1, f: undefined } );
307
308 Reveal.next();
309 assert.deepEqual( Reveal.getIndices(), { h: 1, v: 2, f: undefined } );
310
311 // Step through fragments
312 Reveal.next();
313 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: -1 } );
314
315 Reveal.next();
316 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 } );
317
318 Reveal.next();
319 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 } );
320
321 Reveal.next();
322 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 } );
323 });
324
325 QUnit.test( 'Reveal.next at end', function( assert ) {
326 Reveal.slide( 3 );
327
328 // We're at the end, this should have no effect
329 Reveal.next();
330 assert.deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
331
332 Reveal.next();
333 assert.deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
334 });
335
336
337 // ---------------------------------------------------------------
338 // URL TESTS
339
340 QUnit.module( 'URL' );
341
342 QUnit.test( 'Write (fragmentInURL: false)', function( assert ) {
343 Reveal.configure({ hash: true, fragmentInURL: false });
344
345 Reveal.slide( 2, 0 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200346 assert.strictEqual( Reveal.getSlidePath(), '/2' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200347
348 Reveal.slide( 2, 1 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200349 assert.strictEqual( Reveal.getSlidePath(), '/2/1' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200350
351 Reveal.slide( 2, 0, 1 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200352 assert.strictEqual( Reveal.getSlidePath(), '/2' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200353
354 Reveal.slide( 2, 2, 0 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200355 assert.strictEqual( Reveal.getSlidePath(), '/fragments3' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200356
357 Reveal.slide( 2, 2, 1 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200358 assert.strictEqual( Reveal.getSlidePath(), '/fragments3' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200359 });
360
361 QUnit.test( 'Write (fragmentInURL: true)', function( assert ) {
362 Reveal.configure({ hash: true, fragmentInURL: true });
363
364 Reveal.slide( 2, 0, -1 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200365 assert.strictEqual( Reveal.getSlidePath(), '/2' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200366
367 Reveal.slide( 2, 1, -1 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200368 assert.strictEqual( Reveal.getSlidePath(), '/2/1' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200369
370 Reveal.slide( 2, 0, 1 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200371 assert.strictEqual( Reveal.getSlidePath(), '/2/0/1' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200372
373 Reveal.slide( 2, 2, -1 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200374 assert.strictEqual( Reveal.getSlidePath(), '/fragments3' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200375
376 Reveal.slide( 2, 2, 1 );
Marc Kupietz09b75752023-10-07 09:32:19 +0200377 assert.strictEqual( Reveal.getSlidePath(), '/fragments3/1' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200378 });
379
380 QUnit.test( 'Read', async function( assert ) {
381 Reveal.configure({ hash: true, fragmentInURL: true });
382
383 let test = function( hash, indices ) {
384 return new Promise( resolve => {
385 window.onhashchange = () => {
386 assert.deepEqual( Reveal.getIndices(), indices );
387 resolve();
388 };
389 window.location.hash = hash;
390 } );
391 }
392
393 await test( '#/0', { h: 0, v: 0, f: undefined } ); // horizontal
394 await test( '#/1/1', { h: 1, v: 1, f: undefined } ); // vertical
395 await test( '#/0/', { h: 0, v: 0, f: undefined } ); // trailing /
396 await test( '#/1/1/', { h: 1, v: 1, f: undefined } ); // trailing /
397 await test( '#/2/0/1', { h: 2, v: 0, f: 1 } ); // fragment
398 });
399
400 // ---------------------------------------------------------------
401 // KEYBOARD TESTS
402
403 QUnit.module( 'Keyboard' );
404
405 QUnit.test( 'Add key bindings', function( assert ) {
406 var done = assert.async( 1 );
407
408 Reveal.addKeyBinding({keyCode: 88, key: 'X', description: 'X-SHORTCUT-X'}, function() {
409 assert.ok( true, 'callback triggered' );
410 done();
411 } );
412
413 Reveal.toggleHelp( true );
414 assert.ok( /X\-SHORTCUT\-X/.test( document.body.innerHTML ), 'binding is added to help overlay' );
415 Reveal.toggleHelp( false );
416
Christophe Dervieux8afae132021-12-06 15:16:42 +0100417 triggerKeyboardEvent({ keyCode: 88 });
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200418
419 Reveal.removeKeyBinding( 88 );
420
421 // should do nothing
Christophe Dervieux8afae132021-12-06 15:16:42 +0100422 triggerKeyboardEvent({ keyCode: 88 });
423 });
424
425 QUnit.test( 'Navigation bindings', function( assert ) {
426 Reveal.slide( 0 );
427
428 // right arrow
429 triggerKeyboardEvent({ keyCode: 39 });
430 assert.strictEqual( Reveal.getIndices().h, 1 );
431
432 // down arrow + shift
433 triggerKeyboardEvent({ keyCode: 40, shiftKey: true });
434 assert.strictEqual( Reveal.getIndices().v, 2, 'shift + down arrow goes to last vertical slide' );
435
436 // up arrow
437 triggerKeyboardEvent({ keyCode: 38 });
438 assert.strictEqual( Reveal.getIndices().v, 1 );
439
440 // right arrow + shift
441 triggerKeyboardEvent({ keyCode: 39, shiftKey: true });
442 assert.ok( Reveal.isLastSlide(), 'shift + right arrow goes to last horizontal slide' );
443
444
445 // right arrow on slide with fragments
446 Reveal.slide( 2, 0, -1 );
447 triggerKeyboardEvent({ keyCode: 39 });
448 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'right arrow shows fragment' );
449
450 triggerKeyboardEvent({ keyCode: 39, altKey: true });
451 assert.strictEqual( Reveal.getIndices().h, 3, 'right arrow skips fragments when alt key is pressed' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200452 });
453
454 // ---------------------------------------------------------------
455 // FRAGMENT TESTS
456
457 QUnit.module( 'Fragments' );
458
459 QUnit.test( 'Sliding to fragments', function( assert ) {
460 Reveal.slide( 2, 0, -1 );
461 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: -1 }, 'Reveal.slide( 2, 0, -1 )' );
462
463 Reveal.slide( 2, 0, 0 );
464 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'Reveal.slide( 2, 0, 0 )' );
465
466 Reveal.slide( 2, 0, 2 );
467 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'Reveal.slide( 2, 0, 2 )' );
468
469 Reveal.slide( 2, 0, 1 );
470 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'Reveal.slide( 2, 0, 1 )' );
471 });
472
473 QUnit.test( 'data-fragment is set on slide <section>', function( assert ) {
474 Reveal.slide( 2, 0, -1 );
475 assert.deepEqual( Reveal.getCurrentSlide().getAttribute( 'data-fragment' ), '-1' );
476
477 Reveal.slide( 2, 0, 2 );
478 assert.deepEqual( Reveal.getCurrentSlide().getAttribute( 'data-fragment' ), '2' );
479
480 Reveal.slide( 2, 0, 0 );
481 assert.deepEqual( Reveal.getCurrentSlide().getAttribute( 'data-fragment' ), '0' );
482
483 var fragmentSlide = Reveal.getCurrentSlide();
484
485 Reveal.slide( 3, 0 );
486 assert.deepEqual( fragmentSlide.getAttribute( 'data-fragment' ), '0', 'data-fragment persists when jumping to another slide' );
487 });
488
489 QUnit.test( 'Hiding all fragments', function( assert ) {
490 var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
491
492 Reveal.slide( 2, 0, 0 );
493 assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 1, 'one fragment visible when index is 0' );
494
495 Reveal.slide( 2, 0, -1 );
496 assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 0, 'no fragments visible when index is -1' );
497 });
498
499 QUnit.test( 'Current fragment', function( assert ) {
500 var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
501 var lastFragmentIndex = [].slice.call( fragmentSlide.querySelectorAll( '.fragment' ) ).pop().getAttribute( 'data-fragment-index' );
502
503 Reveal.slide( 2, 0 );
504 assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment at index -1' );
505
506 Reveal.slide( 2, 0, 0 );
507 assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 1, 'one current fragment at index 0' );
508
509 Reveal.slide( 1, 0, 0 );
510 assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment when navigating to previous slide' );
511
512 Reveal.slide( 3, 0, 0 );
513 assert.strictEqual( fragmentSlide.querySelectorAll( '.fragment.current-fragment' ).length, 0, 'no current fragment when navigating to next slide' );
514
515 Reveal.slide( 2, 1, -1 );
516 Reveal.prev();
517 assert.strictEqual( fragmentSlide.querySelector( '.fragment.current-fragment' ).getAttribute( 'data-fragment-index' ), lastFragmentIndex, 'last fragment is current fragment when returning from future slide' );
518 });
519
520 QUnit.test( 'Stepping through fragments', function( assert ) {
521 Reveal.slide( 2, 0, -1 );
522
523 // forwards:
524
525 Reveal.next();
526 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'next() goes to next fragment' );
527
528 Reveal.right();
529 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'right() goes to next fragment' );
530
531 Reveal.down();
532 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'down() goes to next fragment' );
533
534 Reveal.down(); // moves to f #3
535
536 // backwards:
537
538 Reveal.prev();
539 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'prev() goes to prev fragment' );
540
541 Reveal.left();
542 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'left() goes to prev fragment' );
543
544 Reveal.up();
545 assert.deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'up() goes to prev fragment' );
546 });
547
548 QUnit.test( 'Stepping past fragments', function( assert ) {
549 var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
550
551 Reveal.slide( 0, 0, 0 );
552 assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 0, 'no fragments visible when on previous slide' );
553
554 Reveal.slide( 3, 0, 0 );
555 assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 3, 'all fragments visible when on future slide' );
556 });
557
558 QUnit.test( 'Fragment indices', function( assert ) {
559 var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(2)' );
560
561 Reveal.slide( 3, 0, 0 );
562 assert.equal( fragmentSlide.querySelectorAll( '.fragment.visible' ).length, 2, 'both fragments of same index are shown' );
563
564 // This slide has three fragments, first one is index 0, second and third have index 1
565 Reveal.slide( 2, 2, 0 );
566 assert.equal( Reveal.getIndices().f, 0, 'returns correct index for first fragment' );
567
568 Reveal.slide( 2, 2, 1 );
569 assert.equal( Reveal.getIndices().f, 1, 'returns correct index for two fragments with same index' );
570 });
571
572 QUnit.test( 'Index generation', function( assert ) {
573 var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(1)' );
574
575 // These have no indices defined to start with
576 assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[0].getAttribute( 'data-fragment-index' ), '0' );
577 assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[1].getAttribute( 'data-fragment-index' ), '1' );
578 assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[2].getAttribute( 'data-fragment-index' ), '2' );
579 });
580
581 QUnit.test( 'Index normalization', function( assert ) {
582 var fragmentSlide = document.querySelector( '#fragment-slides>section:nth-child(3)' );
583
584 // These start out as 1-4-4 and should normalize to 0-1-1
585 assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[0].getAttribute( 'data-fragment-index' ), '0' );
586 assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[1].getAttribute( 'data-fragment-index' ), '1' );
587 assert.equal( fragmentSlide.querySelectorAll( '.fragment' )[2].getAttribute( 'data-fragment-index' ), '1' );
588 });
589
590 QUnit.test( 'fragmentshown event', function( assert ) {
591 assert.expect( 2 );
592 var done = assert.async( 2 );
593
594 var _onEvent = function( event ) {
595 assert.ok( true, 'event fired' );
596 done();
597 }
598
599 Reveal.on( 'fragmentshown', _onEvent );
600
601 Reveal.slide( 2, 0 );
602 Reveal.slide( 2, 0 ); // should do nothing
603 Reveal.slide( 2, 0, 0 ); // should do nothing
604 Reveal.next();
605 Reveal.next();
606 Reveal.prev(); // shouldn't fire fragmentshown
607
608 Reveal.off( 'fragmentshown', _onEvent );
609 });
610
611 QUnit.test( 'fragmenthidden event', function( assert ) {
612 assert.expect( 2 );
613 var done = assert.async( 2 );
614
615 var _onEvent = function( event ) {
616 assert.ok( true, 'event fired' );
617 done();
618 }
619
620 Reveal.on( 'fragmenthidden', _onEvent );
621
622 Reveal.slide( 2, 0, 2 );
623 Reveal.slide( 2, 0, 2 ); // should do nothing
624 Reveal.prev();
625 Reveal.prev();
626 Reveal.next(); // shouldn't fire fragmenthidden
627
628 Reveal.off( 'fragmenthidden', _onEvent );
629 });
630
631
632 // ---------------------------------------------------------------
633 // AUTO-SLIDE TESTS
634
635 QUnit.module( 'Auto Sliding' );
636
637 QUnit.test( 'Reveal.isAutoSliding', function( assert ) {
638 assert.strictEqual( Reveal.isAutoSliding(), false, 'false by default' );
639
640 Reveal.configure({ autoSlide: 10000 });
641 assert.strictEqual( Reveal.isAutoSliding(), true, 'true after starting' );
642
643 Reveal.configure({ autoSlide: 0 });
644 assert.strictEqual( Reveal.isAutoSliding(), false, 'false after setting to 0' );
645 });
646
647 QUnit.test( 'Reveal.toggleAutoSlide', function( assert ) {
648 Reveal.configure({ autoSlide: 10000 });
649
650 Reveal.toggleAutoSlide();
651 assert.strictEqual( Reveal.isAutoSliding(), false, 'false after first toggle' );
652 Reveal.toggleAutoSlide();
653 assert.strictEqual( Reveal.isAutoSliding(), true, 'true after second toggle' );
654
655 Reveal.configure({ autoSlide: 0 });
656 });
657
658 QUnit.test( 'autoslidepaused', function( assert ) {
659 assert.expect( 1 );
660 var done = assert.async();
661
662 var _onEvent = function( event ) {
663 assert.ok( true, 'event fired' );
664 done();
665 }
666
667 Reveal.on( 'autoslidepaused', _onEvent );
668 Reveal.configure({ autoSlide: 10000 });
669 Reveal.toggleAutoSlide();
670
671 // cleanup
672 Reveal.configure({ autoSlide: 0 });
673 Reveal.off( 'autoslidepaused', _onEvent );
674 });
675
676 QUnit.test( 'autoslideresumed', function( assert ) {
677 assert.expect( 1 );
678 var done = assert.async();
679
680 var _onEvent = function( event ) {
681 assert.ok( true, 'event fired' );
682 done();
683 }
684
685 Reveal.on( 'autoslideresumed', _onEvent );
686 Reveal.configure({ autoSlide: 10000 });
687 Reveal.toggleAutoSlide();
688 Reveal.toggleAutoSlide();
689
690 // cleanup
691 Reveal.configure({ autoSlide: 0 });
692 Reveal.off( 'autoslideresumed', _onEvent );
693 });
694
695
696 // ---------------------------------------------------------------
697 // CONFIGURATION VALUES
698
699 QUnit.module( 'Configuration' );
700
701 QUnit.test( 'Controls', function( assert ) {
702 var controlsElement = document.querySelector( '.reveal>.controls' );
703
704 Reveal.configure({ controls: false });
705 assert.equal( controlsElement.style.display, 'none', 'controls are hidden' );
706
707 Reveal.configure({ controls: true });
708 assert.equal( controlsElement.style.display, 'block', 'controls are visible' );
709 });
710
711 QUnit.test( 'Progress', function( assert ) {
712 var progressElement = document.querySelector( '.reveal>.progress' );
713
714 Reveal.configure({ progress: false });
715 assert.equal( progressElement.style.display, 'none', 'progress are hidden' );
716
717 Reveal.configure({ progress: true });
718 assert.equal( progressElement.style.display, 'block', 'progress are visible' );
719 });
720
721 QUnit.test( 'Loop', function( assert ) {
722 Reveal.configure({ loop: true });
723
724 Reveal.slide( 0, 0 );
725
726 Reveal.left();
727 assert.notEqual( Reveal.getIndices().h, 0, 'looped from start to end' );
728
729 Reveal.right();
730 assert.equal( Reveal.getIndices().h, 0, 'looped from end to start' );
731
Christophe Dervieux8afae132021-12-06 15:16:42 +0100732 Reveal.configure({ navigationMode: 'linear' });
733 Reveal.slide( 0, 0 );
734
735 Reveal.prev();
736 assert.notEqual( Reveal.getIndices().h, 0, 'looped from start to end in linear mode' );
737
738 Reveal.next();
739 assert.equal( Reveal.getIndices().h, 0, 'looped from end to start in linear mode' );
740
741 Reveal.configure({ loop: false, navigationMode: 'default' });
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200742 });
743
744
745 // ---------------------------------------------------------------
746 // LAZY-LOADING TESTS
747
748 QUnit.module( 'Lazy-Loading' );
749
750 QUnit.test( 'img with data-src', function( assert ) {
751 assert.strictEqual( document.querySelectorAll( '.reveal section img[src]' ).length, 1, 'Image source has been set' );
752 });
753
754 QUnit.test( 'video with data-src', function( assert ) {
755 assert.strictEqual( document.querySelectorAll( '.reveal section video[src]' ).length, 1, 'Video source has been set' );
756 });
757
758 QUnit.test( 'audio with data-src', function( assert ) {
759 assert.strictEqual( document.querySelectorAll( '.reveal section audio[src]' ).length, 1, 'Audio source has been set' );
760 });
761
762 QUnit.test( 'iframe with data-src', function( assert ) {
763 Reveal.slide( 0, 0 );
764 assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
765 Reveal.slide( 2, 1 );
766 assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 1, 'Iframe source is set' );
767 Reveal.slide( 2, 2 );
768 assert.strictEqual( document.querySelectorAll( '.reveal section iframe[src]' ).length, 0, 'Iframe source is not set' );
769 });
770
771 QUnit.test( 'background images', function( assert ) {
772 var imageSource1 = Reveal.getSlide( 0 ).getAttribute( 'data-background-image' );
773 var imageSource2 = Reveal.getSlide( 1, 0 ).getAttribute( 'data-background' );
Christophe Dervieux8afae132021-12-06 15:16:42 +0100774 var imageSource3 = Reveal.getSlide( 1, 1 ).getAttribute( 'data-background-image' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200775
776 // check that the images are applied to the background elements
777 assert.ok( Reveal.getSlideBackground( 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource1 ) !== -1, 'data-background-image worked' );
778 assert.ok( Reveal.getSlideBackground( 1, 0 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource2 ) !== -1, 'data-background worked' );
Christophe Dervieux8afae132021-12-06 15:16:42 +0100779 assert.ok( Reveal.getSlideBackground( 1, 1 ).querySelector( '.slide-background-content' ).style.backgroundImage.indexOf( imageSource3 ) !== -1, 'data-background worked' );
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200780 });
781
782
783 // ---------------------------------------------------------------
784 // EVENT TESTS
785
786 QUnit.module( 'Events' );
787
Christophe Dervieux8afae132021-12-06 15:16:42 +0100788 QUnit.test( 'beforeslidechange', function( assert ) {
789 var done = assert.async( 2 );
790
791 var normalEvent = function( event ) {
792 assert.ok( true, 'event fired' );
793 done();
794 }
795 var blockingEvent = function( event ) {
796 event.preventDefault();
797 assert.ok( true, 'event fired' );
798 done();
799 }
800
801 Reveal.on( 'beforeslidechange', normalEvent );
802 Reveal.slide( 2, 0 );
803 Reveal.off( 'beforeslidechange', normalEvent );
804
805 Reveal.on( 'beforeslidechange', blockingEvent );
806 Reveal.slide( 3, 0 );
807 Reveal.off( 'beforeslidechange', blockingEvent );
808
809 assert.strictEqual( Reveal.getIndices().h, 2, 'preventing "beforeslidechange" blocks navigation ' );
810
811 });
812
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200813 QUnit.test( 'slidechanged', function( assert ) {
814 assert.expect( 3 );
815 var done = assert.async( 3 );
816
817 var _onEvent = function( event ) {
818 assert.ok( true, 'event fired' );
819 done();
820 }
821
822 Reveal.on( 'slidechanged', _onEvent );
823
824 Reveal.slide( 1, 0 ); // should trigger
825 Reveal.slide( 1, 0 ); // should do nothing
826 Reveal.next(); // should trigger
827 Reveal.slide( 3, 0 ); // should trigger
828 Reveal.next(); // should do nothing
829
830 Reveal.off( 'slidechanged', _onEvent );
831
832 });
833
834 /* Fails intermittently...
835 QUnit.test( 'slidetransitionend', function( assert ) {
836 assert.expect( 2 );
837 let done = assert.async( 2 );
838 let time = Date.now();
839
840 let horizontalCallback = event => {
841 assert.ok( Date.now() - time > 200, 'horizontal event fired' );
842 done();
843
844 let verticalCallback = event => {
845 assert.ok( true, 'vertical event fired' );
846 done();
847 Reveal.off( 'slidetransitionend', verticalCallback );
848 }
849
850 Reveal.off( 'slidetransitionend', horizontalCallback );
851 Reveal.on( 'slidetransitionend', verticalCallback );
852 Reveal.slide( 1, 1 );
853 }
854
855 Reveal.slide( 0, 0 );
856 Reveal.on( 'slidetransitionend', horizontalCallback );
857 Reveal.slide( 1, 0 );
858
859 });
860 */
861
862 QUnit.test( 'paused', function( assert ) {
863 assert.expect( 1 );
864 var done = assert.async();
865
866 var _onEvent = function( event ) {
867 assert.ok( true, 'event fired' );
868 done();
869 }
870
871 Reveal.on( 'paused', _onEvent );
872
873 Reveal.togglePause();
874 Reveal.togglePause();
875
876 Reveal.off( 'paused', _onEvent );
877 });
878
879 QUnit.test( 'resumed', function( assert ) {
880 assert.expect( 1 );
881 var done = assert.async();
882
883 var _onEvent = function( event ) {
884 assert.ok( true, 'event fired' );
885 done();
886 }
887
888 Reveal.on( 'resumed', _onEvent );
889
890 Reveal.togglePause();
891 Reveal.togglePause();
892
893 Reveal.off( 'resumed', _onEvent );
894 });
895
896 } );
897 </script>
898
899 </body>
900</html>