|
| 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