// These tests expect the DOM to contain a presentation // with the following slide structure: // // 1 // 2 - Three sub-slides // 3 - Three fragment elements // 3 - Two fragments with same data-fragment-index // 4 Reveal.addEventListener('ready', function () { // --------------------------------------------------------------- // DOM TESTS QUnit.module('DOM'); QUnit.test('Initial slides classes', function (assert) { var horizontalSlides = document.querySelectorAll('.reveal .slides>section'); assert.strictEqual(document.querySelectorAll('.reveal .slides section.past').length, 0, 'no .past slides'); assert.strictEqual(document.querySelectorAll('.reveal .slides section.present').length, 1, 'one .present slide'); assert.strictEqual(document.querySelectorAll('.reveal .slides>section.future').length, horizontalSlides.length - 1, 'remaining horizontal slides are .future'); assert.strictEqual(document.querySelectorAll('.reveal .slides section.stack').length, 2, 'two .stacks'); assert.ok(document.querySelectorAll('.reveal .slides section.stack')[0].querySelectorAll('.future').length > 0, 'vertical slides are given .future'); }); // --------------------------------------------------------------- // API TESTS QUnit.module('API'); QUnit.test('Reveal.isReady', function (assert) { assert.strictEqual(Reveal.isReady(), true, 'returns true'); }); QUnit.test('Reveal.isOverview', function (assert) { assert.strictEqual(Reveal.isOverview(), false, 'false by default'); Reveal.toggleOverview(); assert.strictEqual(Reveal.isOverview(), true, 'true after toggling on'); Reveal.toggleOverview(); assert.strictEqual(Reveal.isOverview(), false, 'false after toggling off'); }); QUnit.test('Reveal.isPaused', function (assert) { assert.strictEqual(Reveal.isPaused(), false, 'false by default'); Reveal.togglePause(); assert.strictEqual(Reveal.isPaused(), true, 'true after pausing'); Reveal.togglePause(); assert.strictEqual(Reveal.isPaused(), false, 'false after resuming'); }); QUnit.test('Reveal.isFirstSlide', function (assert) { Reveal.slide(0, 0); assert.strictEqual(Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )'); Reveal.slide(1, 0); assert.strictEqual(Reveal.isFirstSlide(), false, 'false after Reveal.slide( 1, 0 )'); Reveal.slide(0, 0); assert.strictEqual(Reveal.isFirstSlide(), true, 'true after Reveal.slide( 0, 0 )'); }); QUnit.test('Reveal.isFirstSlide after vertical slide', function (assert) { Reveal.slide(1, 1); Reveal.slide(0, 0); assert.strictEqual(Reveal.isFirstSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( 0, 0 )'); }); QUnit.test('Reveal.isLastSlide', function (assert) { Reveal.slide(0, 0); assert.strictEqual(Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )'); var lastSlideIndex = document.querySelectorAll('.reveal .slides>section').length - 1; Reveal.slide(lastSlideIndex, 0); assert.strictEqual(Reveal.isLastSlide(), true, 'true after Reveal.slide( ' + lastSlideIndex + ', 0 )'); Reveal.slide(0, 0); assert.strictEqual(Reveal.isLastSlide(), false, 'false after Reveal.slide( 0, 0 )'); }); QUnit.test('Reveal.isLastSlide after vertical slide', function (assert) { var lastSlideIndex = document.querySelectorAll('.reveal .slides>section').length - 1; Reveal.slide(1, 1); Reveal.slide(lastSlideIndex); assert.strictEqual(Reveal.isLastSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( ' + lastSlideIndex + ', 0 )'); }); QUnit.test('Reveal.getTotalSlides', function (assert) { assert.strictEqual(Reveal.getTotalSlides(), 8, 'eight slides in total'); }); QUnit.test('Reveal.getIndices', function (assert) { var indices = Reveal.getIndices(); assert.ok(indices.hasOwnProperty('h'), 'h exists'); assert.ok(indices.hasOwnProperty('v'), 'v exists'); assert.ok(indices.hasOwnProperty('f'), 'f exists'); Reveal.slide(1, 0); assert.strictEqual(Reveal.getIndices().h, 1, 'h 1'); assert.strictEqual(Reveal.getIndices().v, 0, 'v 0'); Reveal.slide(1, 2); assert.strictEqual(Reveal.getIndices().h, 1, 'h 1'); assert.strictEqual(Reveal.getIndices().v, 2, 'v 2'); Reveal.slide(0, 0); assert.strictEqual(Reveal.getIndices().h, 0, 'h 0'); assert.strictEqual(Reveal.getIndices().v, 0, 'v 0'); }); QUnit.test('Reveal.getSlide', function (assert) { assert.equal(Reveal.getSlide(0), document.querySelector('.reveal .slides>section:first-child'), 'gets correct first slide'); assert.equal(Reveal.getSlide(1), document.querySelector('.reveal .slides>section:nth-child(2)'), 'no v index returns stack'); 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'); 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'); assert.strictEqual(Reveal.getSlide(100), undefined, 'undefined when out of horizontal bounds'); assert.strictEqual(Reveal.getSlide(1, 100), undefined, 'undefined when out of vertical bounds'); }); QUnit.test('Reveal.getSlideBackground', function (assert) { assert.equal(Reveal.getSlideBackground(0), document.querySelector('.reveal .backgrounds>.slide-background:first-child'), 'gets correct first background'); assert.equal(Reveal.getSlideBackground(1), document.querySelector('.reveal .backgrounds>.slide-background:nth-child(2)'), 'no v index returns stack'); 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'); 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'); assert.strictEqual(Reveal.getSlideBackground(100), undefined, 'undefined when out of horizontal bounds'); assert.strictEqual(Reveal.getSlideBackground(1, 100), undefined, 'undefined when out of vertical bounds'); }); QUnit.test('Reveal.getSlideNotes', function (assert) { Reveal.slide(0, 0); assert.ok(Reveal.getSlideNotes() === 'speaker notes 1', 'works with