Skip to content

Commit 1197f6f

Browse files
committed
- Adding more tests
1 parent 9b7be96 commit 1197f6f

File tree

2 files changed

+187
-0
lines changed

2 files changed

+187
-0
lines changed

tests/functions2.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/qunit/qunit-1.18.0.css">
5+
<meta charset="utf-8">
6+
7+
<title>fullpage.js - Tests</title>
8+
9+
<style>
10+
#qunit-fixture{
11+
12+
}
13+
</style>
14+
</head>
15+
<body>
16+
<div id="qunit"></div>
17+
<div id="qunit-fixture">
18+
19+
<div id="fullpage">
20+
<div class="section" id="section1">Some section</div>
21+
<div class="section" id="section2">
22+
<div class="slide"> Slide 1 </div>
23+
<div class="slide"> Slide 2 </div>
24+
<div class="slide"> Slide 3 </div>
25+
<div class="slide"> Slide 4 </div>
26+
</div>
27+
<div class="section" id="section3">Some section</div>
28+
<div class="section" id="section4">Some section</div>
29+
</div>
30+
</div>
31+
32+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
33+
<script type="text/javascript" src="http://code.jquery.com/qunit/qunit-2.1.0.js"></script>
34+
<script type="text/javascript" src="../jquery.fullPage.js"></script>
35+
<script type="text/javascript">
36+
37+
</script>
38+
<script type="text/javascript" src="functions2.js"></script>
39+
40+
</body>
41+
</html>

tests/functions2.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
2+
var sectionLoaded = [];
3+
4+
var WRAPPER = 'fullpage-wrapper';
5+
var WRAPPER_SEL = '.' + WRAPPER;
6+
7+
var ACTIVE = 'active';
8+
var ACTIVE_SEL = '.' + ACTIVE;
9+
var ENABLED = 'fp-enabled';
10+
var SECTION = 'fp-section';
11+
var SECTION_SEL = '.' + SECTION;
12+
var SECTION_ACTIVE_SEL = SECTION_SEL + ACTIVE_SEL;
13+
var SLIDE = 'fp-slide';
14+
var SLIDE_SEL = '.' + SLIDE;
15+
var SLIDE_ACTIVE_SEL = SLIDE_SEL + ACTIVE_SEL;
16+
var VIEWING_PREFIX = 'fp-viewing';
17+
18+
$html = $('html'), // listed separately because we should check each individually
19+
$body = $('body');
20+
$window = $(window);
21+
22+
// "Loaded" flag for each section to fill "onLoad"
23+
$('.section').each(function(index){
24+
sectionLoaded.push(false);
25+
});
26+
27+
function getTransform(el) {
28+
var results = $(el).css('-webkit-transform').match(/matrix(?:(3d)\(\d+(?:, \d+)*(?:, (\d+))(?:, (\d+))(?:, (\d+)), \d+\)|\(\d+(?:, \d+)*(?:, (\d+))(?:, (\d+))\))/)
29+
30+
if(!results) return [0, 0, 0];
31+
if(results[1] == '3d') return results.slice(2,5);
32+
33+
results.push(0);
34+
return results.slice(5, 8);
35+
}
36+
37+
38+
QUnit.module("autoScrolling:false", function(hooks){
39+
40+
hooks.beforeEach(function(assert){
41+
$('#fullpage').fullpage({
42+
autoScrolling:false
43+
});
44+
});
45+
46+
hooks.afterEach(function(assert){
47+
//destroying it if it existed
48+
$.fn.fullpage.destroy('all');
49+
50+
//removing the URL hash
51+
window.location.hash = '';
52+
53+
//resetting the loaded sections array flag
54+
$.each(sectionLoaded, function(index, value){
55+
sectionLoaded[index] = false;
56+
});
57+
});
58+
59+
QUnit.test( "Testing option autoScrolling:false", function(assert) {
60+
assert.equal( $html.css('overflow'), 'visible', 'We expect html to have overflow:visible');
61+
assert.equal( $html[0].style.height, 'initial', 'We expect html to have height:initial');
62+
63+
assert.equal( $body.css('overflow'), 'visible', 'We expect body to have overflow:visible');
64+
assert.equal( $body[0].style.height, 'initial', 'We expect body to have height:initial');
65+
66+
assert.equal( $(WRAPPER_SEL).css('touch-action'), 'auto', 'We expect the wrapper to have touch-action:auto');
67+
});
68+
69+
QUnit.test( "Testing option setAutoScrolling(true)", function(assert) {
70+
$.fn.fullpage.setAutoScrolling(true);
71+
72+
assert.equal( $html.css('overflow'), 'hidden', 'We expect html to have overflow:hidden');
73+
assert.equal( $html[0].style.height, '100%', 'We expect html to have height :100%');
74+
75+
assert.equal( $body.css('overflow'), 'hidden', 'We expect body to have overflow:hidden');
76+
assert.equal( $body[0].style.height, '100%', 'We expect body to have height:100%');
77+
78+
assert.equal( $(WRAPPER_SEL).css('touch-action'), 'none', 'We expect the wrapper to have touch-action:none');
79+
});
80+
});
81+
82+
83+
QUnit.module("autoScrolling:true", function(hooks){
84+
85+
hooks.beforeEach(function(assert){
86+
$('#fullpage').fullpage({
87+
autoScrolling:true
88+
});
89+
});
90+
91+
hooks.afterEach(function(assert){
92+
//destroying it if it existed
93+
$.fn.fullpage.destroy('all');
94+
95+
//removing the URL hash
96+
window.location.hash = '';
97+
98+
//resetting the loaded sections array flag
99+
$.each(sectionLoaded, function(index, value){
100+
sectionLoaded[index] = false;
101+
});
102+
});
103+
104+
QUnit.test( "Testing option autoScrolling:true", function(assert) {
105+
assert.equal( $html.css('overflow'), 'hidden', 'We expect html to have overflow:hidden');
106+
assert.equal( $html[0].style.height, '100%', 'We expect html to have height :100%');
107+
108+
assert.equal( $body.css('overflow'), 'hidden', 'We expect body to have overflow:hidden');
109+
assert.equal( $body[0].style.height, '100%', 'We expect body to have height:100%');
110+
111+
assert.equal( $(WRAPPER_SEL).css('touch-action'), 'none', 'We expect the wrapper to have touch-action:none');
112+
});
113+
114+
QUnit.test( "Testing option setAutoScrolling(false)", function(assert) {
115+
$.fn.fullpage.setAutoScrolling(false);
116+
117+
assert.equal( $html.css('overflow'), 'visible', 'We expect html to have overflow:visible');
118+
assert.equal( $html[0].style.height, 'initial', 'We expect html to have height:initial');
119+
120+
assert.equal( $body.css('overflow'), 'visible', 'We expect body to have overflow:visible');
121+
assert.equal( $body[0].style.height, 'initial', 'We expect body to have height:initial');
122+
123+
assert.equal( $(WRAPPER_SEL).css('touch-action'), 'auto', 'We expect the wrapper to have touch-action:auto');
124+
});
125+
126+
QUnit.test( "Testing option setAutoScrolling(false) - not 1st section active", function(assert) {
127+
$.fn.fullpage.silentMoveTo(2);
128+
$.fn.fullpage.setAutoScrolling(false);
129+
130+
assert.equal( $(SECTION_ACTIVE_SEL).index(), 1, 'We expect section 2 to be active');
131+
132+
var sectionBottomPosition = $(SECTION_ACTIVE_SEL).position().top + $(SECTION_ACTIVE_SEL).height();
133+
var viewportBottomPosition = $window.scrollTop() + $(SECTION_ACTIVE_SEL).height();
134+
135+
console.log('$window.scrollTop()', $window.scrollTop());
136+
console.log('viewportBottomPosition', viewportBottomPosition);
137+
console.log('sectionBottomPosition', sectionBottomPosition);
138+
139+
assert.equal($(WRAPPER_SEL).css('transform')[5], 0, 'We expect no transform3d');
140+
assert.equal(sectionBottomPosition , viewportBottomPosition, 'We expect section 2 bottom to be at the bottom of the viewport');
141+
142+
});
143+
144+
});
145+
146+

0 commit comments

Comments
 (0)