Skip to content

Commit cfdba8a

Browse files
committed
add more tests
1 parent becc9bd commit cfdba8a

12 files changed

+892
-0
lines changed

test/test-config.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>reveal.js - Test Config</title>
6+
7+
<!-- Reveal.js styles -->
8+
<link rel="stylesheet" href="../dist/reveal.css">
9+
10+
<!-- QUnit styles -->
11+
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
12+
13+
<!-- QUnit -->
14+
<script src="../node_modules/qunit/qunit/qunit.js"></script>
15+
</head>
16+
17+
<body style="overflow: auto;">
18+
19+
<div id="qunit"></div>
20+
<div id="qunit-fixture"></div>
21+
22+
<div class="reveal" style="display: none;">
23+
<div class="slides">
24+
<section>Slide 1</section>
25+
<section>Slide 2</section>
26+
<section>Slide 3</section>
27+
</div>
28+
</div>
29+
30+
<!-- Reveal.js -->
31+
<script src="../dist/reveal.js"></script>
32+
33+
<!-- External test script -->
34+
<script src="./test-config.js"></script>
35+
</body>
36+
</html>

test/test-config.js

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
Reveal.initialize().then(() => {
2+
QUnit.module('Configuration');
3+
4+
QUnit.test('Width and height config', function(assert) {
5+
Reveal.configure({ width: 1200, height: 800 });
6+
const config = Reveal.getConfig();
7+
assert.strictEqual(config.width, 1200, 'width updated');
8+
assert.strictEqual(config.height, 800, 'height updated');
9+
});
10+
11+
QUnit.test('Margin config', function(assert) {
12+
Reveal.configure({ margin: 0.1 });
13+
assert.strictEqual(Reveal.getConfig().margin, 0.1, 'margin updated');
14+
});
15+
16+
QUnit.test('Min/Max scale config', function(assert) {
17+
Reveal.configure({ minScale: 0.5, maxScale: 3.0 });
18+
const config = Reveal.getConfig();
19+
assert.strictEqual(config.minScale, 0.5, 'minScale updated');
20+
assert.strictEqual(config.maxScale, 3.0, 'maxScale updated');
21+
});
22+
23+
QUnit.test('Loop config', function(assert) {
24+
Reveal.configure({ loop: true });
25+
assert.strictEqual(Reveal.getConfig().loop, true, 'loop enabled');
26+
27+
Reveal.slide(2); // Last slide
28+
Reveal.next();
29+
assert.strictEqual(Reveal.getIndices().h, 0, 'loops to first slide');
30+
31+
Reveal.configure({ loop: false });
32+
});
33+
34+
QUnit.test('RTL config', function(assert) {
35+
Reveal.configure({ rtl: true });
36+
assert.strictEqual(Reveal.getConfig().rtl, true, 'RTL enabled');
37+
38+
Reveal.configure({ rtl: false });
39+
});
40+
41+
QUnit.test('Center config', function(assert) {
42+
Reveal.configure({ center: false });
43+
assert.strictEqual(Reveal.getConfig().center, false, 'center disabled');
44+
45+
Reveal.configure({ center: true });
46+
});
47+
48+
QUnit.test('Touch config', function(assert) {
49+
Reveal.configure({ touch: false });
50+
assert.strictEqual(Reveal.getConfig().touch, false, 'touch disabled');
51+
52+
Reveal.configure({ touch: true });
53+
});
54+
55+
QUnit.test('Shuffle config', function(assert) {
56+
Reveal.configure({ shuffle: true });
57+
assert.strictEqual(Reveal.getConfig().shuffle, true, 'shuffle enabled');
58+
59+
Reveal.configure({ shuffle: false });
60+
});
61+
62+
QUnit.test('Transition config', function(assert) {
63+
const transitions = ['none', 'fade', 'slide', 'convex', 'concave', 'zoom'];
64+
transitions.forEach(transition => {
65+
Reveal.configure({ transition });
66+
assert.strictEqual(Reveal.getConfig().transition, transition, `${transition} transition set`);
67+
});
68+
});
69+
70+
QUnit.test('Transition speed config', function(assert) {
71+
const speeds = ['default', 'fast', 'slow'];
72+
speeds.forEach(speed => {
73+
Reveal.configure({ transitionSpeed: speed });
74+
assert.strictEqual(Reveal.getConfig().transitionSpeed, speed, `${speed} speed set`);
75+
});
76+
});
77+
78+
QUnit.test('Background transition config', function(assert) {
79+
Reveal.configure({ backgroundTransition: 'zoom' });
80+
assert.strictEqual(Reveal.getConfig().backgroundTransition, 'zoom', 'background transition set');
81+
});
82+
83+
QUnit.test('View distance config', function(assert) {
84+
Reveal.configure({ viewDistance: 5 });
85+
assert.strictEqual(Reveal.getConfig().viewDistance, 5, 'viewDistance updated');
86+
});
87+
88+
QUnit.test('Mobile view distance config', function(assert) {
89+
Reveal.configure({ mobileViewDistance: 1 });
90+
assert.strictEqual(Reveal.getConfig().mobileViewDistance, 1, 'mobileViewDistance updated');
91+
});
92+
93+
QUnit.test('Display config', function(assert) {
94+
Reveal.configure({ display: 'flex' });
95+
assert.strictEqual(Reveal.getConfig().display, 'flex', 'display mode updated');
96+
97+
Reveal.configure({ display: 'block' });
98+
});
99+
100+
QUnit.test('Hash config', function(assert) {
101+
Reveal.configure({ hash: true });
102+
assert.strictEqual(Reveal.getConfig().hash, true, 'hash enabled');
103+
104+
Reveal.configure({ hash: false });
105+
});
106+
107+
QUnit.test('History config', function(assert) {
108+
Reveal.configure({ history: true });
109+
assert.strictEqual(Reveal.getConfig().history, true, 'history enabled');
110+
111+
Reveal.configure({ history: false });
112+
});
113+
114+
QUnit.test('Slide number config', function(assert) {
115+
Reveal.configure({ slideNumber: 'c/t' });
116+
assert.strictEqual(Reveal.getConfig().slideNumber, 'c/t', 'slideNumber format set');
117+
118+
Reveal.configure({ slideNumber: false });
119+
});
120+
121+
QUnit.test('Show notes config', function(assert) {
122+
Reveal.configure({ showNotes: true });
123+
assert.strictEqual(Reveal.getConfig().showNotes, true, 'showNotes enabled');
124+
125+
Reveal.configure({ showNotes: false });
126+
});
127+
128+
QUnit.test('Auto-animate config', function(assert) {
129+
Reveal.configure({ autoAnimate: false });
130+
assert.strictEqual(Reveal.getConfig().autoAnimate, false, 'autoAnimate disabled');
131+
132+
Reveal.configure({ autoAnimate: true });
133+
});
134+
135+
QUnit.test('Help config', function(assert) {
136+
Reveal.configure({ help: false });
137+
assert.strictEqual(Reveal.getConfig().help, false, 'help disabled');
138+
139+
Reveal.configure({ help: true });
140+
});
141+
142+
QUnit.test('Pause config', function(assert) {
143+
Reveal.configure({ pause: false });
144+
assert.strictEqual(Reveal.getConfig().pause, false, 'pause disabled');
145+
146+
Reveal.configure({ pause: true });
147+
});
148+
});

test/test-controls.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>reveal.js - Test Controls</title>
6+
7+
<!-- Reveal.js styles -->
8+
<link rel="stylesheet" href="../dist/reveal.css">
9+
10+
<!-- QUnit styles -->
11+
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
12+
13+
<!-- QUnit script -->
14+
<script src="../node_modules/qunit/qunit/qunit.js"></script>
15+
</head>
16+
17+
<body style="overflow: auto;">
18+
<div id="qunit"></div>
19+
<div id="qunit-fixture"></div>
20+
21+
<div class="reveal" style="display: none;">
22+
<div class="slides">
23+
<section>Slide 1</section>
24+
<section>
25+
<section>Slide 2.1</section>
26+
<section>Slide 2.2</section>
27+
</section>
28+
<section>Slide 3</section>
29+
</div>
30+
</div>
31+
32+
<!-- Reveal.js -->
33+
<script src="../dist/reveal.js"></script>
34+
35+
<!-- Our separate test script -->
36+
<script src="./test-controls.js"></script>
37+
</body>
38+
</html>

test/test-controls.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Reveal.initialize({ controls: true }).then(() => {
2+
QUnit.module('Controls');
3+
4+
QUnit.test('Controls are rendered', function(assert) {
5+
const controls = document.querySelector('.controls');
6+
assert.ok(controls, 'controls element exists');
7+
assert.ok(controls.querySelector('.navigate-left'), 'left button exists');
8+
assert.ok(controls.querySelector('.navigate-right'), 'right button exists');
9+
assert.ok(controls.querySelector('.navigate-up'), 'up button exists');
10+
assert.ok(controls.querySelector('.navigate-down'), 'down button exists');
11+
});
12+
13+
QUnit.test('Controls visibility config', function(assert) {
14+
const controls = document.querySelector('.controls');
15+
16+
Reveal.configure({ controls: true });
17+
assert.strictEqual(controls.style.display, 'block', 'visible when controls: true');
18+
19+
Reveal.configure({ controls: false });
20+
assert.strictEqual(controls.style.display, 'none', 'hidden when controls: false');
21+
22+
Reveal.configure({ controls: true });
23+
});
24+
25+
QUnit.test('Controls update based on available routes', function(assert) {
26+
Reveal.slide(0, 0);
27+
const leftBtn = document.querySelector('.controls .navigate-left');
28+
const rightBtn = document.querySelector('.controls .navigate-right');
29+
30+
assert.notOk(leftBtn.classList.contains('enabled'), 'left disabled on first slide');
31+
assert.ok(rightBtn.classList.contains('enabled'), 'right enabled on first slide');
32+
33+
Reveal.slide(1, 0);
34+
assert.ok(leftBtn.classList.contains('enabled'), 'left enabled on middle slide');
35+
assert.ok(rightBtn.classList.contains('enabled'), 'right enabled on middle slide');
36+
});
37+
38+
QUnit.test('Controls update for vertical slides', function(assert) {
39+
Reveal.slide(1, 0);
40+
const upBtn = document.querySelector('.controls .navigate-up');
41+
const downBtn = document.querySelector('.controls .navigate-down');
42+
43+
assert.notOk(upBtn.classList.contains('enabled'), 'up disabled on first vertical');
44+
assert.ok(downBtn.classList.contains('enabled'), 'down enabled when vertical slides exist');
45+
46+
Reveal.slide(1, 1);
47+
assert.ok(upBtn.classList.contains('enabled'), 'up enabled on second vertical');
48+
});
49+
50+
QUnit.test('Controls layout attribute', function(assert) {
51+
const controls = document.querySelector('.controls');
52+
53+
Reveal.configure({ controlsLayout: 'bottom-right' });
54+
assert.strictEqual(controls.getAttribute('data-controls-layout'), 'bottom-right');
55+
56+
Reveal.configure({ controlsLayout: 'edges' });
57+
assert.strictEqual(controls.getAttribute('data-controls-layout'), 'edges');
58+
});
59+
60+
QUnit.test('Controls back arrows attribute', function(assert) {
61+
const controls = document.querySelector('.controls');
62+
63+
Reveal.configure({ controlsBackArrows: 'faded' });
64+
assert.strictEqual(controls.getAttribute('data-controls-back-arrows'), 'faded');
65+
66+
Reveal.configure({ controlsBackArrows: 'hidden' });
67+
assert.strictEqual(controls.getAttribute('data-controls-back-arrows'), 'hidden');
68+
});
69+
});

test/test-fragments-advanced.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>reveal.js - Test Fragments Advanced</title>
6+
7+
<!-- Reveal core CSS -->
8+
<link rel="stylesheet" href="../dist/reveal.css">
9+
10+
<!-- QUnit test CSS -->
11+
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
12+
13+
<!-- QUnit library -->
14+
<script src="../node_modules/qunit/qunit/qunit.js"></script>
15+
</head>
16+
17+
<body style="overflow: auto;">
18+
19+
<div id="qunit"></div>
20+
<div id="qunit-fixture"></div>
21+
22+
<div class="reveal" style="display: none;">
23+
<div class="slides">
24+
<section>
25+
<p class="fragment fade-in">Fragment 1</p>
26+
<p class="fragment fade-out">Fragment 2</p>
27+
<p class="fragment grow">Fragment 3</p>
28+
</section>
29+
<section>
30+
<p class="fragment" data-fragment-index="2">Index 2</p>
31+
<p class="fragment" data-fragment-index="1">Index 1</p>
32+
<p class="fragment" data-fragment-index="1">Also Index 1</p>
33+
</section>
34+
<section>
35+
<p class="fragment disabled">Disabled fragment</p>
36+
<p class="fragment">Normal fragment</p>
37+
</section>
38+
</div>
39+
</div>
40+
41+
<!-- Reveal.js core -->
42+
<script src="../dist/reveal.js"></script>
43+
44+
<!-- External script with all tests -->
45+
<script src="./test-fragments-advanced.js"></script>
46+
47+
</body>
48+
</html>

0 commit comments

Comments
 (0)