summaryrefslogtreecommitdiff
path: root/2024-06-18-guix-social/reveal.js/test/test-scroll.html
blob: 74a16e36ef8842758b3820e089ef5e7d263c8889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!doctype html>
<html lang="en">

	<head>
		<meta charset="utf-8">

		<title>reveal.js - Test Scroll View</title>

		<link rel="stylesheet" href="../dist/reveal.css">
		<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
		<script src="../node_modules/qunit/qunit/qunit.js"></script>
	</head>

	<body style="overflow: auto;">

		<div id="qunit"></div>
		<div id="qunit-fixture"></div>

		<div class="reveal" style="opacity: 0; pointer-events: none;">

			<div class="slides">

				<section>
					<h1>slide 1</h1>
				</section>

				<section>
					<h1>slide 2</h1>
				</section>

				<section>
					<h1>slide 3</h1>
					<p class="fragment">fragment 1</p>
					<p class="fragment">fragment 2</p>
					<p class="fragment">fragment 3</p>
				</section>

				<section>
					<h1>slide 4</h1>
				</section>

			</div>

		</div>

		<script src="../dist/reveal.js"></script>
		<script>

			QUnit.config.testTimeout = 30000;
			QUnit.config.reorder = false;

			function getScrollHeight() {
				return Reveal.getViewportElement().scrollHeight;
			}

			function getViewportHeight() {
				return Reveal.getViewportElement().offsetHeight;
			}

			Reveal.initialize({ view: 'scroll' }).then( async () => {

				QUnit.module( 'Scroll View' );

				QUnit.test( 'Activates', assert => {
					assert.ok( getScrollHeight() > getViewportHeight(), 'Is overflowing' );
				});

				QUnit.test( 'Can be toggled via API', assert => {
					Reveal.toggleScrollView( false );
					assert.ok( getScrollHeight() <= getViewportHeight(), 'Is not overflowing' );
					Reveal.toggleScrollView( true );
					assert.ok( getScrollHeight() > getViewportHeight(), 'Is overflowing' );
				});

				QUnit.test( 'Changes present slide when scrolling', assert => {
					assert.timeout( 200 );
					assert.expect( 2 );

					const slides = document.querySelectorAll( '.reveal .slides section' );

					assert.ok( slides[0].classList.contains( 'present' ), 'First slide is present' );
					Reveal.getViewportElement().scrollTop = getViewportHeight() * 1;

					return new Promise( resolve => {
						setTimeout(() => {
							assert.ok( slides[1].classList.contains( 'present' ), 'Second slide is present' );
							resolve();
						}, 100);
					} );
				});

				QUnit.test( 'Fires slideschanged event when scrolling', assert => {
					assert.timeout( 200 );
					assert.expect( 2 );

					const slides = document.querySelectorAll( '.reveal .slides section' );

					return new Promise( resolve => {
						let callback = ( event ) => {
							Reveal.off( 'slidechanged', callback );
							assert.ok( true, 'slidechanged event fired' );
							assert.ok( event.currentSlide.classList.contains( 'present' ), 'slidechanged provides reference to currentSlide' );
							resolve();
						}

						Reveal.on( 'slidechanged', callback );
						Reveal.getViewportElement().scrollTop = getViewportHeight() * 2;
					});
				});

				QUnit.test( 'Fires fragmentshown event when scrolling', assert => {
					assert.timeout( 200 );
					assert.expect( 2 );

					const slides = document.querySelectorAll( '.reveal .slides section' );

					return new Promise( resolve => {
						let callback = ( event ) => {
							Reveal.off( 'fragmentshown', callback );
							assert.ok( true, 'fragmentshown event fired' );
							assert.ok( event.fragments.length > 0, 'fragmentshown provides reference to fragment nodes' );
							resolve();
						}

						Reveal.on( 'fragmentshown', callback );

						Reveal.getViewportElement().scrollTop = 0;
						Reveal.next();
						Reveal.next();
						Reveal.getViewportElement().scrollTop += getViewportHeight();
					});
				});

				QUnit.test( 'Fires fragmenthidden event when scrolling', assert => {
					assert.timeout( 200 );
					assert.expect( 2 );

					const slides = document.querySelectorAll( '.reveal .slides section' );

					return new Promise( resolve => {
						let callback = ( event ) => {
							Reveal.off( 'fragmenthidden', callback );
							assert.ok( true, 'fragmenthidden event fired' );
							assert.ok( event.fragments.length > 0, 'fragmenthidden provides reference to fragment nodes' );
							resolve();
						}

						Reveal.on( 'fragmenthidden', callback );

						Reveal.getViewportElement().scrollTop = 0;
						Reveal.next();
						Reveal.next();
						Reveal.next();
						Reveal.getViewportElement().scrollTop -= getViewportHeight();
					});
				});

			} );
		</script>

	</body>
</html>