From 0814176f3c22f511afd88fc0dc514e4c7338a5e7 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Sat, 7 Mar 2020 18:19:08 +0100 Subject: [PATCH] refactor unit tests, now consistently initializing reveal.js in the same way --- test/test-auto-animate.html | 7 +-- test/test-dependencies-async.html | 3 +- test/test-dependencies.html | 19 ++++---- test/test-grid-navigation.html | 7 +-- test/test-iframe-backgrounds.html | 10 +--- test/test-iframes.html | 10 +--- test/test-markdown-element-attributes.html | 53 +++++++++++++++++++-- test/test-markdown-element-attributes.js | 44 ------------------ test/test-markdown-external.html | 28 ++++++++--- test/test-markdown-external.js | 20 -------- test/test-markdown-options.html | 31 ++++++++++++- test/test-markdown-options.js | 27 ----------- test/test-markdown-slide-attributes.html | 54 ++++++++++++++++++++-- test/test-markdown-slide-attributes.js | 44 ------------------ test/test-markdown.html | 20 ++++++-- test/test-markdown.js | 11 ----- test/test-pdf.html | 15 +++++- test/test-pdf.js | 12 ----- test/test-plugins.html | 29 ++++++------ test/test-state.html | 7 +-- test/test.html | 3 +- test/test.js | 4 +- 22 files changed, 214 insertions(+), 244 deletions(-) delete mode 100644 test/test-markdown-element-attributes.js delete mode 100644 test/test-markdown-external.js delete mode 100644 test/test-markdown-options.js delete mode 100644 test/test-markdown-slide-attributes.js delete mode 100644 test/test-markdown.js delete mode 100644 test/test-pdf.js diff --git a/test/test-auto-animate.html b/test/test-auto-animate.html index 19e04199..d3d9b4f5 100644 --- a/test/test-auto-animate.html +++ b/test/test-auto-animate.html @@ -8,6 +8,7 @@ + @@ -46,8 +47,6 @@ - - diff --git a/test/test-dependencies-async.html b/test/test-dependencies-async.html index 78e9f011..2a54fae2 100644 --- a/test/test-dependencies-async.html +++ b/test/test-dependencies-async.html @@ -8,6 +8,7 @@ + @@ -26,8 +27,6 @@ - - @@ -26,12 +27,16 @@ - - diff --git a/test/test-grid-navigation.html b/test/test-grid-navigation.html index b53dcb38..2a943fe7 100644 --- a/test/test-grid-navigation.html +++ b/test/test-grid-navigation.html @@ -8,6 +8,7 @@ + @@ -38,10 +39,8 @@ - - diff --git a/test/test-iframe-backgrounds.html b/test/test-iframe-backgrounds.html index 59e7aed5..e09b2d73 100644 --- a/test/test-iframe-backgrounds.html +++ b/test/test-iframe-backgrounds.html @@ -8,6 +8,7 @@ + @@ -31,12 +32,9 @@ - - diff --git a/test/test-iframes.html b/test/test-iframes.html index b2b7d96d..44b5e232 100644 --- a/test/test-iframes.html +++ b/test/test-iframes.html @@ -8,6 +8,7 @@ + @@ -31,12 +32,9 @@ - - diff --git a/test/test-markdown-element-attributes.html b/test/test-markdown-element-attributes.html index ce8ca465..acc93d1d 100644 --- a/test/test-markdown-element-attributes.html +++ b/test/test-markdown-element-attributes.html @@ -8,6 +8,7 @@ + @@ -122,11 +123,55 @@ - - - + + QUnit.module( 'Markdown' ); + + QUnit.test( 'Vertical separator', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 4, 'found four slides' ); + }); + + QUnit.test( 'Attributes on element header in vertical slides', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides section>section h2.fragment.fade-out' ).length, 1, 'found one vertical slide with class fragment.fade-out on header' ); + assert.strictEqual( document.querySelectorAll( '.reveal .slides section>section h2.fragment.shrink' ).length, 1, 'found one vertical slide with class fragment.shrink on header' ); + }); + + QUnit.test( 'Attributes on element paragraphs in vertical slides', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides section>section p.fragment.grow' ).length, 2, 'found a vertical slide with two paragraphs with class fragment.grow' ); + }); + + QUnit.test( 'Attributes on element list items in vertical slides', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides section>section li.fragment.grow' ).length, 3, 'found a vertical slide with three list items with class fragment.grow' ); + }); + + QUnit.test( 'Attributes on element paragraphs in horizontal slides', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides section p.fragment.highlight-red' ).length, 4, 'found a horizontal slide with four paragraphs with class fragment.grow' ); + }); + + QUnit.test( 'Attributes on element list items in horizontal slides', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides section li.fragment.highlight-green' ).length, 5, 'found a horizontal slide with five list items with class fragment.roll-in' ); + }); + + QUnit.test( 'Attributes on element image in horizontal slides', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides section img.reveal.stretch' ).length, 1, 'found a horizontal slide with stretched image, class img.reveal.stretch' ); + }); + + QUnit.test( 'Attributes on elements in vertical slides with default element attribute separator', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides section h2.fragment.highlight-red' ).length, 2, 'found two h2 titles with fragment highlight-red in vertical slides with default element attribute separator' ); + }); + + QUnit.test( 'Attributes on elements in single slides with default element attribute separator', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides section p.fragment.highlight-blue' ).length, 3, 'found three elements with fragment highlight-blue in single slide with default element attribute separator' ); + }); + + } ); + diff --git a/test/test-markdown-element-attributes.js b/test/test-markdown-element-attributes.js deleted file mode 100644 index fc87b7b0..00000000 --- a/test/test-markdown-element-attributes.js +++ /dev/null @@ -1,44 +0,0 @@ -Reveal.addEventListener( 'ready', function() { - - QUnit.module( 'Markdown' ); - - QUnit.test( 'Vertical separator', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 4, 'found four slides' ); - }); - - QUnit.test( 'Attributes on element header in vertical slides', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides section>section h2.fragment.fade-out' ).length, 1, 'found one vertical slide with class fragment.fade-out on header' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides section>section h2.fragment.shrink' ).length, 1, 'found one vertical slide with class fragment.shrink on header' ); - }); - - QUnit.test( 'Attributes on element paragraphs in vertical slides', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides section>section p.fragment.grow' ).length, 2, 'found a vertical slide with two paragraphs with class fragment.grow' ); - }); - - QUnit.test( 'Attributes on element list items in vertical slides', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides section>section li.fragment.grow' ).length, 3, 'found a vertical slide with three list items with class fragment.grow' ); - }); - - QUnit.test( 'Attributes on element paragraphs in horizontal slides', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides section p.fragment.highlight-red' ).length, 4, 'found a horizontal slide with four paragraphs with class fragment.grow' ); - }); - - QUnit.test( 'Attributes on element list items in horizontal slides', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides section li.fragment.highlight-green' ).length, 5, 'found a horizontal slide with five list items with class fragment.roll-in' ); - }); - - QUnit.test( 'Attributes on element image in horizontal slides', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides section img.reveal.stretch' ).length, 1, 'found a horizontal slide with stretched image, class img.reveal.stretch' ); - }); - - QUnit.test( 'Attributes on elements in vertical slides with default element attribute separator', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides section h2.fragment.highlight-red' ).length, 2, 'found two h2 titles with fragment highlight-red in vertical slides with default element attribute separator' ); - }); - - QUnit.test( 'Attributes on elements in single slides with default element attribute separator', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides section p.fragment.highlight-blue' ).length, 3, 'found three elements with fragment highlight-blue in single slide with default element attribute separator' ); - }); - -} ); - -Reveal.initialize(); diff --git a/test/test-markdown-external.html b/test/test-markdown-external.html index 4db4228e..333bbbd5 100644 --- a/test/test-markdown-external.html +++ b/test/test-markdown-external.html @@ -18,20 +18,34 @@ - - - - + - + diff --git a/test/test-markdown-external.js b/test/test-markdown-external.js deleted file mode 100644 index f9249865..00000000 --- a/test/test-markdown-external.js +++ /dev/null @@ -1,20 +0,0 @@ -Reveal.addEventListener( 'ready', function() { - - QUnit.module( 'Markdown' ); - - QUnit.test( 'Vertical separator', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 2, 'found two slides' ); - }); - - QUnit.test( 'Horizontal separator', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section' ).length, 2, 'found two slides' ); - }); - - QUnit.test( 'Language highlighter', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.hljs-keyword' ).length, 1, 'got rendered highlight tag.' ); - assert.strictEqual( document.querySelector( '.hljs-keyword' ).innerHTML, 'var', 'the same keyword: var.' ); - }); - -} ); - -Reveal.initialize(); diff --git a/test/test-markdown-options.html b/test/test-markdown-options.html index 653f858e..7b2a631e 100644 --- a/test/test-markdown-options.html +++ b/test/test-markdown-options.html @@ -31,10 +31,37 @@ - + - + diff --git a/test/test-markdown-options.js b/test/test-markdown-options.js deleted file mode 100644 index ef616594..00000000 --- a/test/test-markdown-options.js +++ /dev/null @@ -1,27 +0,0 @@ -Reveal.addEventListener( 'ready', function() { - - QUnit.module( 'Markdown' ); - - QUnit.test( 'Options are set', function( assert ) { - assert.strictEqual( marked.defaults.smartypants, true ); - }); - - QUnit.test( 'Smart quotes are activated', function( assert ) { - var text = document.querySelector( '.reveal .slides>section>p' ).textContent; - - assert.strictEqual( /['"]/.test( text ), false ); - assert.strictEqual( /[“”‘’]/.test( text ), true ); - }); - -} ); - -Reveal.initialize({ - dependencies: [ - { src: '../plugin/markdown/marked.js' }, - // Test loading JS files with query strings - { src: '../plugin/markdown/markdown.js?query=string' }, - ], - markdown: { - smartypants: true - } -}); diff --git a/test/test-markdown-slide-attributes.html b/test/test-markdown-slide-attributes.html index a596019d..274a87fe 100644 --- a/test/test-markdown-slide-attributes.html +++ b/test/test-markdown-slide-attributes.html @@ -116,12 +116,58 @@ - - - + - + diff --git a/test/test-markdown-slide-attributes.js b/test/test-markdown-slide-attributes.js deleted file mode 100644 index b44323a1..00000000 --- a/test/test-markdown-slide-attributes.js +++ /dev/null @@ -1,44 +0,0 @@ -Reveal.addEventListener( 'ready', function() { - - QUnit.module( 'Markdown' ); - - QUnit.test( 'Vertical separator', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 6, 'found six vertical slides' ); - }); - - QUnit.test( 'Id on slide', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section#slide2' ).length, 1, 'found one slide with id slide2' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section a[href="#/slide2"]' ).length, 1, 'found one slide with a link to slide2' ); - }); - - QUnit.test( 'data-background attributes', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#A0C66B"]' ).length, 1, 'found one vertical slide with data-background="#A0C66B"' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#ff0000"]' ).length, 1, 'found one vertical slide with data-background="#ff0000"' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section[data-background="#C6916B"]' ).length, 1, 'found one slide with data-background="#C6916B"' ); - }); - - QUnit.test( 'data-transition attributes', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="zoom"]' ).length, 1, 'found one vertical slide with data-transition="zoom"' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="fade"]' ).length, 1, 'found one vertical slide with data-transition="fade"' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides section [data-transition="zoom"]' ).length, 1, 'found one slide with data-transition="zoom"' ); - }); - - QUnit.test( 'data-background attributes with default separator', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#A7C66B"]' ).length, 1, 'found one vertical slide with data-background="#A0C66B"' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#f70000"]' ).length, 1, 'found one vertical slide with data-background="#ff0000"' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section[data-background="#C7916B"]' ).length, 1, 'found one slide with data-background="#C6916B"' ); - }); - - QUnit.test( 'data-transition attributes with default separator', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="concave"]' ).length, 1, 'found one vertical slide with data-transition="zoom"' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="page"]' ).length, 1, 'found one vertical slide with data-transition="fade"' ); - assert.strictEqual( document.querySelectorAll( '.reveal .slides section [data-transition="concave"]' ).length, 1, 'found one slide with data-transition="zoom"' ); - }); - - QUnit.test( 'data-transition attributes with inline content', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section[data-background="#ff0000"]' ).length, 3, 'found three horizontal slides with data-background="#ff0000"' ); - }); - -} ); - -Reveal.initialize(); diff --git a/test/test-markdown.html b/test/test-markdown.html index c6b55425..9233fe42 100644 --- a/test/test-markdown.html +++ b/test/test-markdown.html @@ -8,6 +8,7 @@ + @@ -41,11 +42,22 @@ - - - + + QUnit.module( 'Markdown' ); + + QUnit.test( 'Vertical separator', function( assert ) { + assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 2, 'found two slides' ); + }); + + } ); + diff --git a/test/test-markdown.js b/test/test-markdown.js deleted file mode 100644 index 5ea8bf2c..00000000 --- a/test/test-markdown.js +++ /dev/null @@ -1,11 +0,0 @@ -Reveal.addEventListener( 'ready', function() { - - QUnit.module( 'Markdown' ); - - QUnit.test( 'Vertical separator', function( assert ) { - assert.strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 2, 'found two slides' ); - }); - -} ); - -Reveal.initialize(); diff --git a/test/test-pdf.html b/test/test-pdf.html index 09ffa22d..ee9591d5 100644 --- a/test/test-pdf.html +++ b/test/test-pdf.html @@ -9,6 +9,7 @@ + @@ -74,9 +75,19 @@ - + + // Only one test for now, we're mainly ensuring that there + // are no execution errors when running PDF mode + + QUnit.test( 'Reveal.isReady', function( assert ) { + assert.strictEqual( Reveal.isReady(), true, 'returns true' ); + }); + + } ); + + diff --git a/test/test-pdf.js b/test/test-pdf.js deleted file mode 100644 index 1ebf997b..00000000 --- a/test/test-pdf.js +++ /dev/null @@ -1,12 +0,0 @@ -Reveal.addEventListener( 'ready', function() { - - // Only one test for now, we're mainly ensuring that there - // are no execution errors when running PDF mode - - QUnit.test( 'Reveal.isReady', function( assert ) { - assert.strictEqual( Reveal.isReady(), true, 'returns true' ); - }); - -} ); - -Reveal.initialize({ pdf: true }); diff --git a/test/test-plugins.html b/test/test-plugins.html index 4bdbfd22..47f530bd 100644 --- a/test/test-plugins.html +++ b/test/test-plugins.html @@ -8,6 +8,7 @@ + @@ -26,8 +27,6 @@ - - diff --git a/test/test-state.html b/test/test-state.html index 61736d03..9fca96e1 100644 --- a/test/test-state.html +++ b/test/test-state.html @@ -8,6 +8,7 @@ + @@ -36,12 +37,10 @@ - - diff --git a/test/test.html b/test/test.html index 2e9b3d20..5f64d6e9 100644 --- a/test/test.html +++ b/test/test.html @@ -8,6 +8,7 @@ + @@ -77,8 +78,6 @@ - - diff --git a/test/test.js b/test/test.js index 14bb690f..a6bb0ccd 100644 --- a/test/test.js +++ b/test/test.js @@ -7,7 +7,7 @@ // 3 - Two fragments with same data-fragment-index // 4 -Reveal.addEventListener( 'ready', function() { +Reveal.initialize().then( function() { // --------------------------------------------------------------- // DOM TESTS @@ -610,5 +610,3 @@ Reveal.addEventListener( 'ready', function() { }); } ); - -Reveal.initialize();