From c5ee83c9402f5c516e9690622e06ed2e82eda4b5 Mon Sep 17 00:00:00 2001 From: Antonio Laguna Date: Mon, 29 May 2017 10:16:40 +0200 Subject: [PATCH] Linting --- package.json | 3 + src/js/utils/scroll-to.js | 6 +- static/js/webslides.js | 77 +++++++++++---------- static/js/webslides.min.js | 4 +- test/modules/slide.test.js | 7 +- test/modules/webslides.test.js | 21 +++--- test/plugins/autoslide.test.js | 6 +- test/plugins/click-nav.test.js | 5 +- test/plugins/keyboard.test.js | 14 ++-- test/plugins/navigation.test.js | 2 +- test/plugins/scroll.test.js | 9 +-- test/plugins/touch.test.js | 41 ++++++------ test/plugins/video.test.js | 28 +++----- test/plugins/youtube.test.js | 50 +++++++------- test/plugins/zoom.test.js | 11 ++- test/utils/dom.test.js | 3 +- test/utils/webslides.js | 115 -------------------------------- 17 files changed, 147 insertions(+), 255 deletions(-) delete mode 100644 test/utils/webslides.js diff --git a/package.json b/package.json index a5a40ce..c995b64 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,9 @@ "jest": { "collectCoverage": true }, + "pre-commit": [ + "lint" + ], "babel": { "presets": [ [ diff --git a/src/js/utils/scroll-to.js b/src/js/utils/scroll-to.js index 6bf4b7a..844fe0c 100644 --- a/src/js/utils/scroll-to.js +++ b/src/js/utils/scroll-to.js @@ -1,6 +1,6 @@ import Easings from './easing'; -const SCROLLABLE_CONTAINER = document.getElementById('webslides'); +let SCROLLABLE_CONTAINER = null; /** * Smoothly scrolls to a given Y position using Easing.Swing. It'll run a @@ -10,6 +10,10 @@ const SCROLLABLE_CONTAINER = document.getElementById('webslides'); * @param {function} cb Callback function to call upon completion. */ export default function scrollTo(y, duration = 500, cb = () => {}) { + if (!SCROLLABLE_CONTAINER) { + SCROLLABLE_CONTAINER = document.getElementById('webslides'); + } + const delta = y - SCROLLABLE_CONTAINER.scrollTop; const startLocation = SCROLLABLE_CONTAINER.scrollTop; const increment = 16; diff --git a/static/js/webslides.js b/static/js/webslides.js index 604afd6..da5dcc7 100644 --- a/static/js/webslides.js +++ b/static/js/webslides.js @@ -1,7 +1,7 @@ /*! * Name: WebSlides * Version: 1.3.1 - * Date: 2017-05-05 + * Date: 2017-05-29 * Description: Making HTML presentations easy * URL: https://github.com/webslides/webslides#readme * Credits: @jlantunez, @LuisSacristan, @Belelros @@ -71,7 +71,7 @@ /******/ __webpack_require__.p = "/static/js/"; /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 5); +/******/ return __webpack_require__(__webpack_require__.s = 6); /******/ }) /************************************************************************/ /******/ ([ @@ -79,7 +79,7 @@ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__custom_event__ = __webpack_require__(18); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__custom_event__ = __webpack_require__(19); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -115,7 +115,9 @@ var DOM = function () { var text = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; var node = document.createElement(tag); - node.id = id; + if (id) { + node.id = id; + } if (text) { node.textContent = text; @@ -360,9 +362,9 @@ var DOM = function () { /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils_dom__ = __webpack_require__(0); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Slide; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return Events; }); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils_dom__ = __webpack_require__(0); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -683,10 +685,10 @@ var MobileDetector = function () { /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__plugins_plugins__ = __webpack_require__(12); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__plugins_plugins__ = __webpack_require__(13); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__slide__ = __webpack_require__(1); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__utils_dom__ = __webpack_require__(0); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__utils_scroll_to__ = __webpack_require__(20); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__utils_scroll_to__ = __webpack_require__(21); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -1192,17 +1194,24 @@ var WebSlides = function () { /***/ }), /* 5 */ +/***/ (function(module, exports) { + +// removed by extract-text-webpack-plugin + +/***/ }), +/* 6 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__modules_webslides__ = __webpack_require__(4); +__webpack_require__(5); window.WebSlides = __WEBPACK_IMPORTED_MODULE_0__modules_webslides__["a" /* default */]; /***/ }), -/* 6 */ +/* 7 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -1305,7 +1314,7 @@ var AutoSlide = function () { /* harmony default export */ __webpack_exports__["a"] = (AutoSlide); /***/ }), -/* 7 */ +/* 8 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -1361,7 +1370,7 @@ var ClickNav = function () { /* harmony default export */ __webpack_exports__["a"] = (ClickNav); /***/ }), -/* 8 */ +/* 9 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -1431,7 +1440,7 @@ var Grid = function () { /* harmony default export */ __webpack_exports__["a"] = (Grid); /***/ }), -/* 9 */ +/* 10 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -1538,7 +1547,7 @@ var Hash = function () { /* harmony default export */ __webpack_exports__["a"] = (Hash); /***/ }), -/* 10 */ +/* 11 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -1632,7 +1641,7 @@ var Keyboard = function () { /* harmony default export */ __webpack_exports__["a"] = (Keyboard); /***/ }), -/* 11 */ +/* 12 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -1808,21 +1817,21 @@ var Navigation = function () { /* harmony default export */ __webpack_exports__["a"] = (Navigation); /***/ }), -/* 12 */ +/* 13 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__autoslide__ = __webpack_require__(6); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__click_nav__ = __webpack_require__(7); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__grid__ = __webpack_require__(8); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__hash__ = __webpack_require__(9); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__keyboard__ = __webpack_require__(10); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__navigation__ = __webpack_require__(11); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__scroll__ = __webpack_require__(13); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__touch__ = __webpack_require__(14); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__video__ = __webpack_require__(15); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__youtube__ = __webpack_require__(16); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__zoom__ = __webpack_require__(17); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__autoslide__ = __webpack_require__(7); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__click_nav__ = __webpack_require__(8); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__grid__ = __webpack_require__(9); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__hash__ = __webpack_require__(10); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__keyboard__ = __webpack_require__(11); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__navigation__ = __webpack_require__(12); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__scroll__ = __webpack_require__(14); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__touch__ = __webpack_require__(15); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__video__ = __webpack_require__(16); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__youtube__ = __webpack_require__(17); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__zoom__ = __webpack_require__(18); @@ -1850,7 +1859,7 @@ var Navigation = function () { }); /***/ }), -/* 13 */ +/* 14 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -1990,7 +1999,7 @@ var Scroll = function () { /* harmony default export */ __webpack_exports__["a"] = (Scroll); /***/ }), -/* 14 */ +/* 15 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -2240,7 +2249,7 @@ var Touch = function () { /* harmony default export */ __webpack_exports__["a"] = (Touch); /***/ }), -/* 15 */ +/* 16 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -2327,7 +2336,7 @@ var Video = function () { /* harmony default export */ __webpack_exports__["a"] = (Video); /***/ }), -/* 16 */ +/* 17 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -2663,7 +2672,7 @@ var YouTube = function () { /* harmony default export */ __webpack_exports__["a"] = (YouTube); /***/ }), -/* 17 */ +/* 18 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -2924,7 +2933,7 @@ var Zoom = function () { /* harmony default export */ __webpack_exports__["a"] = (Zoom); /***/ }), -/* 18 */ +/* 19 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -2972,7 +2981,7 @@ var WSCustomEvent = canIuseNativeCustom() ? NativeCustomEvent : IECustomEvent; /* harmony default export */ __webpack_exports__["a"] = (WSCustomEvent); /***/ }), -/* 19 */ +/* 20 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -2997,12 +3006,12 @@ function linear(p) { /* harmony default export */ __webpack_exports__["a"] = ({ swing: swing, linear: linear }); /***/ }), -/* 20 */ +/* 21 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__easing__ = __webpack_require__(19); /* harmony export (immutable) */ __webpack_exports__["a"] = scrollTo; +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__easing__ = __webpack_require__(20); var SCROLLABLE_CONTAINER = document.getElementById('webslides'); diff --git a/static/js/webslides.min.js b/static/js/webslides.min.js index cb29c8e..9792a80 100644 --- a/static/js/webslides.min.js +++ b/static/js/webslides.min.js @@ -1,9 +1,9 @@ /*! * Name: WebSlides * Version: 1.3.1 - * Date: 2017-05-05 + * Date: 2017-05-29 * Description: Making HTML presentations easy * URL: https://github.com/webslides/webslides#readme * Credits: @jlantunez, @LuisSacristan, @Belelros */ -!function(e){function t(n){if(i[n])return i[n].exports;var s=i[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var i={};t.m=e,t.c=i,t.i=function(e){return e},t.d=function(e,i,n){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/static/js/",t(t.s=5)}([function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(18),o=function(){function e(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:"",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=document.createElement(e);return n.id=t,i&&(n.textContent=i),n}},{key:"once",value:function(e,t,i){var n=function n(s){s.target===e&&(e.removeEventListener(t,n),i(s))};e.addEventListener(t,n,!1)}},{key:"getTransitionEvent",value:function(e){if(a&&!e)return a;a="";for(var t=e||document.createElement("ws"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"},n=Object.keys(i),s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:{},n=new s.a(t,{detail:i});e.dispatchEvent(n)}},{key:"toArray",value:function(e){return[].slice.call(e)}},{key:"isFocusableElement",value:function(){var e=!1;if(document.activeElement){var t="inherit"!==document.activeElement.contentEditable&&void 0!==document.activeElement.contentEditable;e=["INPUT","SELECT","OPTION","TEXTAREA"].indexOf(document.activeElement.tagName)>-1||t}return e}},{key:"parseSize",value:function(e){return Number(e.replace(/[^\d\.]/g,""))}},{key:"wrap",value:function(e,t){var i=document.createElement(t);return e.parentElement.insertBefore(i,e),i.appendChild(e),i}},{key:"after",value:function(e,t){var i=t.parentNode;i.lastChild===t?i.appendChild(e):i.insertBefore(e,t.nextSibling)}}]),e}();t.a=l},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(0);i.d(t,"a",function(){return l}),i.d(t,"b",function(){return r});var o=function(){function e(e,t){for(var i=0;i0&&void 0!==arguments[0]?arguments[0]:{},i=t.autoslide,s=void 0!==i&&i,o=t.changeOnClick,a=void 0!==o&&o,r=t.loop,l=void 0===r||r,c=t.minWheelDelta,h=void 0===c?40:c,d=t.navigateOnScroll,f=void 0===d||d,v=t.scrollWait,y=void 0===v?450:v,p=t.slideOffset,w=void 0===p?50:p;if(n(this,e),this.el=document.getElementById("webslides"),!this.el)throw new Error("Couldn't find the webslides container!");this.isMoving=!1,this.slides=null,this.currentSlideI_=-1,this.currentSlide_=null,this.maxSlide_=0,this.isVertical=this.el.classList.contains(u.VERTICAL),this.plugins={},this.options={autoslide:s,changeOnClick:a,loop:l,minWheelDelta:h,navigateOnScroll:f,scrollWait:y,slideOffset:w},this.initialised=!1,this.removeChildren_(),this.grabSlides_(),this.createPlugins_(),this.initSlides_(),this.onInit_()}return l(e,[{key:"removeChildren_",value:function(){for(var e=this.el.childNodes,t=e.length;t--;){var i=e[t];o.a.isCandidate(i)||this.el.removeChild(i)}}},{key:"createPlugins_",value:function(){var e=this;Object.keys(c).forEach(function(t){var i=c[t];e.plugins[t]=new i(e)})}},{key:"onInit_",value:function(){this.initialised=!0,a.a.fireEvent(this.el,"ws:init"),document.documentElement.classList.add(u.READY)}},{key:"grabSlides_",value:function(){this.slides=a.a.toArray(this.el.childNodes).map(function(e,t){return new o.a(e,t)}),this.maxSlide_=this.slides.length}},{key:"goToSlide",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(this.isValidIndexSlide_(e)&&!this.isMoving&&this.currentSlideI_!==e){this.isMoving=!0;var i=!1;null!==t?i=t:this.currentSlideI_>=0&&(i=e>this.currentSlideI_);var n=this.slides[e];null===this.currentSlide_||!this.isVertical||this.plugins.touch&&this.plugins.touch.isEnabled?this.transitionToSlide_(i,n,this.onSlideChange_):this.scrollTransitionToSlide_(i,n,this.onSlideChange_)}}},{key:"scrollTransitionToSlide_",value:function(e,t,n){var s=this;this.el.style.overflow="hidden",e?t.show():(t.moveBeforeFirst(),t.show(),i.i(r.a)(this.currentSlide_.el.offsetTop,0)),i.i(r.a)(t.el.offsetTop,500,function(){s.currentSlide_.hide(),e&&s.currentSlide_.moveAfterLast(),s.el.style.overflow="auto",setTimeout(function(){n.call(s,t)},150)})}},{key:"transitionToSlide_",value:function(e,t,n){var s=this;i.i(r.a)(0,0);var o="slideInRight";e||(t.moveBeforeFirst(),o="slideInLeft"),this.currentSlide_&&(e&&this.currentSlide_.moveAfterLast(),this.currentSlide_.hide()),t.show(),this.initialised&&this.plugins.touch&&this.plugins.touch.isEnabled?(a.a.once(t.el,a.a.getAnimationEvent(),function(){t.el.classList.remove(o),n.call(s,t)}),t.el.classList.add(o)):n.call(this,t)}},{key:"onSlideChange_",value:function(e){this.currentSlide_&&this.currentSlide_.disable(),this.currentSlide_=e,this.currentSlideI_=e.i,this.currentSlide_.enable(),this.isMoving=!1,a.a.fireEvent(this.el,"ws:slide-change",{slides:this.maxSlide_,currentSlide0:this.currentSlideI_,currentSlide:this.currentSlideI_+1})}},{key:"goNext",value:function(){var e=this.currentSlideI_+1;if(e>=this.maxSlide_){if(!this.options.loop)return;e=0}this.goToSlide(e,!0)}},{key:"goPrev",value:function(){var e=this.currentSlideI_-1;if(e<0){if(!this.options.loop)return;e=this.maxSlide_-1}this.goToSlide(e,!1)}},{key:"isValidIndexSlide_",value:function(e){return e>=0&&e=this.maxSlide_)&&(e=0),0!==e)for(var t=0;t0&&(this.interval_=setInterval(this.ws_.goNext.bind(this.ws_),e))}},{key:"stop",value:function(){this.interval_&&(clearInterval(this.interval_),this.interval_=null)}}]),e}();t.a=a},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=function(){function e(e,t){for(var i=0;iMath.abs(t);if(this.isGoingUp_=t<0,this.isGoingLeft_=i<0,s){if(n)return;e.preventDefault()}(Math.abs(t)>=this.ws_.options.minWheelDelta||Math.abs(i)>=this.ws_.options.minWheelDelta)&&(s&&this.isGoingLeft_||!s&&this.isGoingUp_?this.ws_.goPrev():this.ws_.goNext(),e.preventDefault())}}}]),e}();t.a=a},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(3),o=function(){function e(e,t){for(var i=0;i1&&(this.startTouches=e.getTouchCoordinates(t),this.endTouches=this.startTouches,this.isGesture=!0)}}},{key:"onMove_",value:function(t){if(!this.ws_.isDisabled()){var i=e.normalizeEventInfo(t);this.isGesture?this.endTouches=e.getTouchCoordinates(t):(this.endX_=i.x,this.endY_=i.y)}}},{key:"onStop_",value:function(){if(!this.ws_.isDisabled())if(this.isGesture){var e=Math.sqrt(Math.pow(this.startTouches[0].x-this.startTouches[1].x,2)+Math.pow(this.startTouches[0].y-this.startTouches[1].y,2)),t=Math.sqrt(Math.pow(this.endTouches[0].x-this.endTouches[1].x,2)+Math.pow(this.endTouches[0].y-this.endTouches[1].y,2));e>t&&this.ws_.toggleZoom(),this.isGesture=!1}else{var i=this.startX_-this.endX_,n=this.startY_-this.endY_;Math.abs(i)>Math.abs(n)&&(i<-this.ws_.options.slideOffset?this.ws_.goPrev():i>this.ws_.options.slideOffset&&this.ws_.goNext())}}}],[{key:"getTouchCoordinates",value:function(e){return[{x:e.touches[0].clientX,y:e.touches[0].clientY},{x:e.touches[1].clientX,y:e.touches[1].clientY}]}},{key:"normalizeEventInfo",value:function(e){var t={pageX:0,pageY:0};return void 0!==e.changedTouches?t=e.changedTouches[0]:void 0!==e.originalEvent&&void 0!==e.originalEvent.changedTouches&&(t=e.originalEvent.changedTouches[0]),{x:e.offsetX||e.layerX||t.pageX,y:e.offsetY||e.layerY||t.pageY}}}]),e}();t.a=r},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(0),o=i(1),a=function(){function e(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:500,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},n=e-o.scrollTop,a=o.scrollTop;if(!t)return o.scrollTop=e,void i();!function r(l){l+=16;var u=Math.min(1,l/t),c=s.a.swing(u,l*u,e,n,t);o.scrollTop=Math.floor(a+c*n),l1&&void 0!==arguments[1]?arguments[1]:"",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=document.createElement(e);return t&&(n.id=t),i&&(n.textContent=i),n}},{key:"once",value:function(e,t,i){var n=function n(s){s.target===e&&(e.removeEventListener(t,n),i(s))};e.addEventListener(t,n,!1)}},{key:"getTransitionEvent",value:function(e){if(a&&!e)return a;a="";for(var t=e||document.createElement("ws"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"},n=Object.keys(i),s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:{},n=new s.a(t,{detail:i});e.dispatchEvent(n)}},{key:"toArray",value:function(e){return[].slice.call(e)}},{key:"isFocusableElement",value:function(){var e=!1;if(document.activeElement){var t="inherit"!==document.activeElement.contentEditable&&void 0!==document.activeElement.contentEditable;e=["INPUT","SELECT","OPTION","TEXTAREA"].indexOf(document.activeElement.tagName)>-1||t}return e}},{key:"parseSize",value:function(e){return Number(e.replace(/[^\d\.]/g,""))}},{key:"wrap",value:function(e,t){var i=document.createElement(t);return e.parentElement.insertBefore(i,e),i.appendChild(e),i}},{key:"after",value:function(e,t){var i=t.parentNode;i.lastChild===t?i.appendChild(e):i.insertBefore(e,t.nextSibling)}}]),e}();t.a=l},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}i.d(t,"a",function(){return l}),i.d(t,"b",function(){return r});var s=i(0),o=function(){function e(e,t){for(var i=0;i0&&void 0!==arguments[0]?arguments[0]:{},i=t.autoslide,s=void 0!==i&&i,o=t.changeOnClick,a=void 0!==o&&o,r=t.loop,l=void 0===r||r,c=t.minWheelDelta,h=void 0===c?40:c,d=t.navigateOnScroll,f=void 0===d||d,v=t.scrollWait,y=void 0===v?450:v,p=t.slideOffset,w=void 0===p?50:p;if(n(this,e),this.el=document.getElementById("webslides"),!this.el)throw new Error("Couldn't find the webslides container!");this.isMoving=!1,this.slides=null,this.currentSlideI_=-1,this.currentSlide_=null,this.maxSlide_=0,this.isVertical=this.el.classList.contains(u.VERTICAL),this.plugins={},this.options={autoslide:s,changeOnClick:a,loop:l,minWheelDelta:h,navigateOnScroll:f,scrollWait:y,slideOffset:w},this.initialised=!1,this.removeChildren_(),this.grabSlides_(),this.createPlugins_(),this.initSlides_(),this.onInit_()}return l(e,[{key:"removeChildren_",value:function(){for(var e=this.el.childNodes,t=e.length;t--;){var i=e[t];o.a.isCandidate(i)||this.el.removeChild(i)}}},{key:"createPlugins_",value:function(){var e=this;Object.keys(c).forEach(function(t){var i=c[t];e.plugins[t]=new i(e)})}},{key:"onInit_",value:function(){this.initialised=!0,a.a.fireEvent(this.el,"ws:init"),document.documentElement.classList.add(u.READY)}},{key:"grabSlides_",value:function(){this.slides=a.a.toArray(this.el.childNodes).map(function(e,t){return new o.a(e,t)}),this.maxSlide_=this.slides.length}},{key:"goToSlide",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(this.isValidIndexSlide_(e)&&!this.isMoving&&this.currentSlideI_!==e){this.isMoving=!0;var i=!1;null!==t?i=t:this.currentSlideI_>=0&&(i=e>this.currentSlideI_);var n=this.slides[e];null===this.currentSlide_||!this.isVertical||this.plugins.touch&&this.plugins.touch.isEnabled?this.transitionToSlide_(i,n,this.onSlideChange_):this.scrollTransitionToSlide_(i,n,this.onSlideChange_)}}},{key:"scrollTransitionToSlide_",value:function(e,t,n){var s=this;this.el.style.overflow="hidden",e?t.show():(t.moveBeforeFirst(),t.show(),i.i(r.a)(this.currentSlide_.el.offsetTop,0)),i.i(r.a)(t.el.offsetTop,500,function(){s.currentSlide_.hide(),e&&s.currentSlide_.moveAfterLast(),s.el.style.overflow="auto",setTimeout(function(){n.call(s,t)},150)})}},{key:"transitionToSlide_",value:function(e,t,n){var s=this;i.i(r.a)(0,0);var o="slideInRight";e||(t.moveBeforeFirst(),o="slideInLeft"),this.currentSlide_&&(e&&this.currentSlide_.moveAfterLast(),this.currentSlide_.hide()),t.show(),this.initialised&&this.plugins.touch&&this.plugins.touch.isEnabled?(a.a.once(t.el,a.a.getAnimationEvent(),function(){t.el.classList.remove(o),n.call(s,t)}),t.el.classList.add(o)):n.call(this,t)}},{key:"onSlideChange_",value:function(e){this.currentSlide_&&this.currentSlide_.disable(),this.currentSlide_=e,this.currentSlideI_=e.i,this.currentSlide_.enable(),this.isMoving=!1,a.a.fireEvent(this.el,"ws:slide-change",{slides:this.maxSlide_,currentSlide0:this.currentSlideI_,currentSlide:this.currentSlideI_+1})}},{key:"goNext",value:function(){var e=this.currentSlideI_+1;if(e>=this.maxSlide_){if(!this.options.loop)return;e=0}this.goToSlide(e,!0)}},{key:"goPrev",value:function(){var e=this.currentSlideI_-1;if(e<0){if(!this.options.loop)return;e=this.maxSlide_-1}this.goToSlide(e,!1)}},{key:"isValidIndexSlide_",value:function(e){return e>=0&&e=this.maxSlide_)&&(e=0),0!==e)for(var t=0;t0&&(this.interval_=setInterval(this.ws_.goNext.bind(this.ws_),e))}},{key:"stop",value:function(){this.interval_&&(clearInterval(this.interval_),this.interval_=null)}}]),e}();t.a=a},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=function(){function e(e,t){for(var i=0;iMath.abs(t);if(this.isGoingUp_=t<0,this.isGoingLeft_=i<0,s){if(n)return;e.preventDefault()}(Math.abs(t)>=this.ws_.options.minWheelDelta||Math.abs(i)>=this.ws_.options.minWheelDelta)&&(s&&this.isGoingLeft_||!s&&this.isGoingUp_?this.ws_.goPrev():this.ws_.goNext(),e.preventDefault())}}}]),e}();t.a=a},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(3),o=function(){function e(e,t){for(var i=0;i1&&(this.startTouches=e.getTouchCoordinates(t),this.endTouches=this.startTouches,this.isGesture=!0)}}},{key:"onMove_",value:function(t){if(!this.ws_.isDisabled()){var i=e.normalizeEventInfo(t);this.isGesture?this.endTouches=e.getTouchCoordinates(t):(this.endX_=i.x,this.endY_=i.y)}}},{key:"onStop_",value:function(){if(!this.ws_.isDisabled())if(this.isGesture){var e=Math.sqrt(Math.pow(this.startTouches[0].x-this.startTouches[1].x,2)+Math.pow(this.startTouches[0].y-this.startTouches[1].y,2)),t=Math.sqrt(Math.pow(this.endTouches[0].x-this.endTouches[1].x,2)+Math.pow(this.endTouches[0].y-this.endTouches[1].y,2));e>t&&this.ws_.toggleZoom(),this.isGesture=!1}else{var i=this.startX_-this.endX_,n=this.startY_-this.endY_;Math.abs(i)>Math.abs(n)&&(i<-this.ws_.options.slideOffset?this.ws_.goPrev():i>this.ws_.options.slideOffset&&this.ws_.goNext())}}}],[{key:"getTouchCoordinates",value:function(e){return[{x:e.touches[0].clientX,y:e.touches[0].clientY},{x:e.touches[1].clientX,y:e.touches[1].clientY}]}},{key:"normalizeEventInfo",value:function(e){var t={pageX:0,pageY:0};return void 0!==e.changedTouches?t=e.changedTouches[0]:void 0!==e.originalEvent&&void 0!==e.originalEvent.changedTouches&&(t=e.originalEvent.changedTouches[0]),{x:e.offsetX||e.layerX||t.pageX,y:e.offsetY||e.layerY||t.pageY}}}]),e}();t.a=r},function(e,t,i){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=i(0),o=i(1),a=function(){function e(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:500,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},n=e-o.scrollTop,a=o.scrollTop;if(!t)return o.scrollTop=e,void i();!function r(l){l+=16;var u=Math.min(1,l/t),c=s.a.swing(u,l*u,e,n,t);o.scrollTop=Math.floor(a+c*n),l { - const slides = '
Content
'.repeat(5); + const slides = '
Content
' + .repeat(5); document.body.innerHTML = `
${slides}
`; }); @@ -19,9 +20,9 @@ test('Slide utility', () => { }; expect(Slide.isCandidate(slides[0])).toBe(true); - slides.forEach( (slide, i) => webslides.slides.push(new Slide(slide, i))); + slides.forEach((slide, i) => webslides.slides.push(new Slide(slide, i))); expect(webslides.slides.length).toBe(slides.length); - webslides.slides.forEach( (slide, i) => { + webslides.slides.forEach((slide, i) => { expect(typeof slide).toBe('object'); expect(slide.el).toBe(slides[i]); expect(slide.el.id).toBe(`section-${i+1}`); diff --git a/test/modules/webslides.test.js b/test/modules/webslides.test.js index eda27ae..96db655 100644 --- a/test/modules/webslides.test.js +++ b/test/modules/webslides.test.js @@ -1,32 +1,32 @@ -import DOM from '../../src/js/utils/dom'; +import WebSlides from '../../src/js/modules/webslides'; jest.useFakeTimers(); beforeAll(() => { - const slides = '
Content
'.repeat(20); - document.body.innerHTML = `
${slides}
`; + const slides = + '
Content
'.repeat(20); + document.body.innerHTML = + `
${slides}
`; }); test('WebSlides utility', () => { let webslides; - // Needs to be required and not imported because const defined in top level - // in utils/scroll-to - const WebSlides = require('../../src/js/modules/webslides'); const ws = document.getElementById('webslides'); const change = jest.fn(); expect(() => { ws.setAttribute('id', ''); - webslides = new WebSlides.default(); + webslides = new WebSlides(); }).toThrow(); ws.setAttribute('id', 'webslides'); expect(() => { - webslides = new WebSlides.default(); + webslides = new WebSlides(); }).not.toThrow(); webslides.el.addEventListener('ws:slide-change', change); expect(document.getElementById('other')).toBe(null); - expect(webslides.slides.length).toBe(document.querySelectorAll('#webslides .slide').length); - webslides.slides.forEach( slide => { + expect(webslides.slides.length) + .toBe(document.querySelectorAll('#webslides .slide').length); + webslides.slides.forEach(slide => { expect(typeof slide).toBe('object'); }); expect(webslides.plugins.autoslide).not.toBe(null); @@ -72,5 +72,4 @@ test('WebSlides utility', () => { expect(webslides.isDisabled()).toBe(true); webslides.enable(); expect(webslides.isDisabled()).toBe(false); - }); diff --git a/test/plugins/autoslide.test.js b/test/plugins/autoslide.test.js index 0bf1ee3..2e9675d 100644 --- a/test/plugins/autoslide.test.js +++ b/test/plugins/autoslide.test.js @@ -4,7 +4,8 @@ import AutoSlide from '../../src/js/plugins/autoslide'; jest.useFakeTimers(); beforeAll(() => { - document.body.innerHTML = `
`; + document.body.innerHTML = + `
`; }); test('AutoSlide plugin', () => { @@ -20,7 +21,7 @@ test('AutoSlide plugin', () => { expect(next).not.toBeCalled(); - const autoslide = new AutoSlide(webslides); + new AutoSlide(webslides); DOM.fireEvent(ws, 'ws:init'); // Wait until next execution @@ -39,5 +40,4 @@ test('AutoSlide plugin', () => { jest.runTimersToTime(101); expect(next.mock.calls.length).toBe(2); - }); diff --git a/test/plugins/click-nav.test.js b/test/plugins/click-nav.test.js index 6c27716..96d4737 100644 --- a/test/plugins/click-nav.test.js +++ b/test/plugins/click-nav.test.js @@ -2,7 +2,8 @@ import DOM from '../../src/js/utils/dom'; import ClickNav from '../../src/js/plugins/click-nav'; beforeAll(() => { - document.body.innerHTML = `

Text

`; + document.body.innerHTML = + `

Text

`; }); test('Click nav plugin', () => { @@ -20,7 +21,7 @@ test('Click nav plugin', () => { expect(next).not.toBeCalled(); - const clicknav = new ClickNav(webslides); + new ClickNav(webslides); DOM.fireEvent(ws, 'click'); expect(next.mock.calls.length).toBe(1); }); diff --git a/test/plugins/keyboard.test.js b/test/plugins/keyboard.test.js index 8843e6b..0aa1d9b 100644 --- a/test/plugins/keyboard.test.js +++ b/test/plugins/keyboard.test.js @@ -1,9 +1,9 @@ -import DOM from '../../src/js/utils/dom'; import Keyboard from '../../src/js/plugins/keyboard'; import Keys from '../../src/js/utils/keys'; +// @TODO: Check to do this with simulant const simulateKeyEvent = (el, code) => { - const evt = new KeyboardEvent("keydown", { + const evt = new KeyboardEvent('keydown', { bubbles: true, cancelableCode: true, which: code, @@ -12,7 +12,10 @@ const simulateKeyEvent = (el, code) => { }; beforeAll(() => { - document.body.innerHTML = `

Text

`; + document.body.innerHTML = `
+

Text

+
+ `; }); test('Keyboard plugin', () => { @@ -20,7 +23,6 @@ test('Keyboard plugin', () => { const next = jest.fn(); const prev = jest.fn(); const ws = document.getElementById('webslides'); - const focusable = document.getElementById('focusable'); let disabled = true; @@ -29,11 +31,11 @@ test('Keyboard plugin', () => { goNext: next, goPrev: prev, isVertical: false, - isDisabled: () => {return disabled;}, + isDisabled: () => disabled, el: ws }; - const keyboard = new Keyboard(webslides); + new Keyboard(webslides); expect(goto).not.toBeCalled(); expect(next).not.toBeCalled(); diff --git a/test/plugins/navigation.test.js b/test/plugins/navigation.test.js index be81866..bc110e4 100644 --- a/test/plugins/navigation.test.js +++ b/test/plugins/navigation.test.js @@ -31,7 +31,7 @@ test('Navigation plugin', () => { expect(fakeCounter.childNodes[0].href).toBe('about:blank#'); expect(fakeCounter.childNodes[0].title).toBe('View all slides'); - const nav = new Navigation(webslides); + new Navigation(webslides); const navElem = ws.querySelector('#navigation'); const counter = navElem.querySelector('#counter'); diff --git a/test/plugins/scroll.test.js b/test/plugins/scroll.test.js index 7325db7..8fea2c2 100644 --- a/test/plugins/scroll.test.js +++ b/test/plugins/scroll.test.js @@ -18,7 +18,9 @@ beforeAll(() => { test('Scroll utility', () => { // Forces mobile detection - window.navigator = {userAgent: 'Android'}; + window.navigator = { + userAgent: 'Android' + }; const ws = document.getElementById('webslides'); const next = jest.fn(); const prev = jest.fn(); @@ -26,7 +28,7 @@ test('Scroll utility', () => { let disabled = true; const webslides = { el: ws, - isDisabled: () => {return disabled;}, + isDisabled: () => disabled, isMoving: false, isVertical: false, goNext: next, @@ -38,7 +40,7 @@ test('Scroll utility', () => { } }; - const scroll = new Scroll(webslides); + new Scroll(webslides); fireEvent(ws, 'wheel', 300, 200); expect(next).not.toBeCalled(); @@ -61,5 +63,4 @@ test('Scroll utility', () => { jest.runTimersToTime(201); expect(next.mock.calls.length).toBe(1); expect(prev.mock.calls.length).toBe(1); - }); diff --git a/test/plugins/touch.test.js b/test/plugins/touch.test.js index 8f3c371..2dcd55c 100644 --- a/test/plugins/touch.test.js +++ b/test/plugins/touch.test.js @@ -1,13 +1,14 @@ +import Touch from '../../src/js/plugins/touch'; // Copy of DOM.fireEvent, but using touch offets -const fireEvent = (target, eventType, offsetX, offsetY, touches) => { +const getEvent = (eventType, offsetX, offsetY, touches) => { const event = new CustomEvent(eventType); event.offsetX = offsetX; event.offsetY = offsetY; event.touches = touches; - target.dispatchEvent(event); + return event; }; beforeAll(() => { @@ -17,11 +18,9 @@ beforeAll(() => { test('Touch utility', () => { // Overrides userAgent to force mobile detection - const UAProp = Object.getOwnPropertyDescriptor(window.navigator.__proto__, 'userAgent'); + Object.getOwnPropertyDescriptor(window.navigator.__proto__, 'userAgent'); Object.defineProperty(window.navigator, 'userAgent', {get: () => 'Android'}); - const Touch = require('../../src/js/plugins/touch'); - const ws = document.getElementById('webslides'); const next = jest.fn(); const prev = jest.fn(); @@ -30,7 +29,7 @@ test('Touch utility', () => { let disabled = true; const webslides = { el: ws, - isDisabled: () => {return disabled;}, + isDisabled: () => disabled, isMoving: false, isVertical: false, goNext: next, @@ -41,10 +40,10 @@ test('Touch utility', () => { } }; - const touch = new Touch.default(webslides); - fireEvent(document, 'touchstart', 200, 200, [1]); - fireEvent(document, 'touchmove', 200, 400, [1]); - fireEvent(document, 'touchend', 200, 200, [1]); + const touch = new Touch(webslides); + touch.onStart_(getEvent('touchstart', 200, 200, [1])); + touch.onMove_(getEvent('touchstart', 200, 400, [1])); + touch.onStop_(getEvent('touchstart', 200, 200, [1])); expect(next).not.toBeCalled(); expect(prev).not.toBeCalled(); @@ -52,28 +51,30 @@ test('Touch utility', () => { disabled = false; - fireEvent(document, 'touchstart', 800, 200, [1]); - fireEvent(document, 'touchmove', 400, 200, [1]); - fireEvent(document, 'touchend', 400, 200, [1]); + touch.onStart_(getEvent('touchstart', 800, 200, [1])); + touch.onMove_(getEvent('touchstart', 400, 400, [1])); + touch.onStop_(getEvent('touchstart', 400, 200, [1])); expect(next.mock.calls.length).toBe(1); expect(prev.mock.calls.length).toBe(0); expect(zoom.mock.calls.length).toBe(0); - fireEvent(document, 'touchstart', 200, 200, [1]); - fireEvent(document, 'touchmove', 400, 200, [1]); - fireEvent(document, 'touchend', 400, 200, [1]); + touch.onStart_(getEvent('touchstart', 200, 200, [1])); + touch.onMove_(getEvent('touchstart', 400, 200, [1])); + touch.onStop_(getEvent('touchstart', 400, 200, [1])); expect(next.mock.calls.length).toBe(1); expect(prev.mock.calls.length).toBe(1); expect(zoom.mock.calls.length).toBe(0); - fireEvent(document, 'touchstart', 200, 200, [{clientX: 100, clientY: 100}, {clientX: 400, clientY: 400}]); - fireEvent(document, 'touchmove', 400, 200, [{clientX: 200, clientY: 200}, {clientX: 300, clientY: 300}]); - fireEvent(document, 'touchend', 400, 200, [{clientX: 200, clientY: 200}, {clientX: 300, clientY: 300}]); + touch.onStart_(getEvent('touchstart', 200, 200, + [{clientX: 100, clientY: 100}, {clientX: 400, clientY: 400}])); + touch.onMove_(getEvent('touchstart', 400, 200, + [{clientX: 200, clientY: 200}, {clientX: 300, clientY: 300}])); + touch.onStop_(getEvent('touchstart', 400, 200, + [{clientX: 200, clientY: 200}, {clientX: 300, clientY: 300}])); expect(next.mock.calls.length).toBe(1); expect(prev.mock.calls.length).toBe(1); expect(zoom.mock.calls.length).toBe(1); - }); diff --git a/test/plugins/video.test.js b/test/plugins/video.test.js index 3ad9cad..294e465 100644 --- a/test/plugins/video.test.js +++ b/test/plugins/video.test.js @@ -1,52 +1,40 @@ import Video from '../../src/js/plugins/video'; import DOM from '../../src/js/utils/dom'; -// Copy of DOM.fireEvent, but using touch offets -const fireEvent = (target, eventType, offsetX, offsetY, touches) => { - const event = new CustomEvent(eventType); - - event.offsetX = offsetX; - event.offsetY = offsetY; - event.touches = touches; - - target.dispatchEvent(event); -}; - beforeAll(() => { - const slides = '12345'.replace(/(\d)/g, '
'); + const slides = '12345'.replace(/(\d)/g, + '
'); document.body.innerHTML = `
${slides}
`; }); test('Video utility', () => { - const ws = document.getElementById('webslides'); const slides = ws.querySelectorAll('.slide'); const videos = ws.querySelectorAll('video'); const play = jest.fn(); const pause = jest.fn(); - videos.forEach( video => { + videos.forEach(video => { video.play = play; video.pause = pause; - }) + }); const webslides = { el: ws, slides: [] }; - slides.forEach( slide => webslides.slides.push({el: slide})); + slides.forEach(slide => webslides.slides.push({el: slide})); expect(ws.querySelectorAll('video[autoplay]').length).toBe(5); - const video = new Video(webslides); + new Video(webslides); expect(ws.querySelectorAll('video[autoplay]').length).toBe(0); expect(pause.mock.calls.length).toBe(5); - webslides.slides.forEach( slide => { + webslides.slides.forEach(slide => { DOM.fireEvent(slide.el, 'slide:enable', {slide: slide}); DOM.fireEvent(slide.el, 'slide:disable', {slide: slide}); - }) + }); expect(pause.mock.calls.length).toBe(10); - }); diff --git a/test/plugins/youtube.test.js b/test/plugins/youtube.test.js index 3cc847f..2773675 100644 --- a/test/plugins/youtube.test.js +++ b/test/plugins/youtube.test.js @@ -1,24 +1,16 @@ import YouTube from '../../src/js/plugins/youtube'; import DOM from '../../src/js/utils/dom'; -// Copy of DOM.fireEvent, but using touch offets -const fireEvent = (target, eventType, offsetX, offsetY, touches) => { - const event = new CustomEvent(eventType); - - event.offsetX = offsetX; - event.offsetY = offsetY; - event.touches = touches; - - target.dispatchEvent(event); -}; - beforeAll(() => { - const video = '
'; - document.body.innerHTML = `
${video}
`; + const video = '
' + + '
'; + document.body.innerHTML = + `
${video}
`; }); test('YouTube utility', () => { - const ws = document.getElementById('webslides'); const slides = ws.querySelectorAll('.slide'); const play = jest.fn(); @@ -30,23 +22,32 @@ test('YouTube utility', () => { el: ws, slides: [] }; - slides.forEach( slide => webslides.slides.push({el: slide})); + slides.forEach(slide => webslides.slides.push({el: slide})); window.YT = { Player: function(a, b) { - return { getIframe: () => { - const div = DOM.createNode('div'); - div.innerHTML = ''; - webslides.slides[0].el.appendChild(div); - return div.querySelector('iframe'); - } } + return { + getIframe: () => { + const div = DOM.createNode('div'); + div.innerHTML = + ``; + webslides.slides[0].el.appendChild(div); + return div.querySelector('iframe'); + } + }; } - } + }; - const youtube = new YouTube(webslides); + new YouTube(webslides); expect(typeof window.onYouTubeIframeAPIReady).toBe('function'); - webslides.el.querySelector('[data-youtube]').dataset = {autoplay: true, youtubeId: 'CQY3KUR3VzM'}; + webslides.el.querySelector('[data-youtube]').dataset = { + autoplay: true, + youtubeId: 'CQY3KUR3VzM' + }; window.onYouTubeIframeAPIReady(); @@ -85,5 +86,4 @@ test('YouTube utility', () => { expect(pause.mock.calls.length).toBe(1); expect(destroy.mock.calls.length).toBe(1); expect(create.mock.calls.length).toBe(1); - }); diff --git a/test/plugins/zoom.test.js b/test/plugins/zoom.test.js index c84dbff..5d246a2 100644 --- a/test/plugins/zoom.test.js +++ b/test/plugins/zoom.test.js @@ -5,7 +5,7 @@ jest.useFakeTimers(); // Copy of DOM.fireEvent, but using keydown const simulateKeyEvent = (el, code) => { - const evt = new KeyboardEvent("keydown", { + const evt = new KeyboardEvent('keydown', { bubbles: true, cancelableCode: true, which: code, @@ -14,12 +14,12 @@ const simulateKeyEvent = (el, code) => { }; beforeAll(() => { - const slides = '12345'.replace(/(\d)/g, '
Slide $1
'); + const slides = '12345'.replace(/(\d)/g, + '
Slide $1
'); document.body.innerHTML = `
${slides}
`; }); test('Zoom utility', () => { - const ws = document.getElementById('webslides'); const slides = ws.querySelectorAll('.slide'); const goto = jest.fn(); @@ -33,9 +33,9 @@ test('Zoom utility', () => { enable: enable, disable: disable }; - slides.forEach( slide => webslides.slides.push({el: slide})); + slides.forEach(slide => webslides.slides.push({el: slide})); - const zoom = new Zoom(webslides); + new Zoom(webslides); const zws = document.querySelector('#webslides-zoomed'); const zoomSlides = zws.querySelectorAll('.slide'); @@ -62,5 +62,4 @@ test('Zoom utility', () => { expect(disable.mock.calls.length).toBe(1); expect(enable.mock.calls.length).toBe(1); expect(goto.mock.calls.length).toBe(1); - }); diff --git a/test/utils/dom.test.js b/test/utils/dom.test.js index 53bf72d..a83f2fa 100644 --- a/test/utils/dom.test.js +++ b/test/utils/dom.test.js @@ -142,7 +142,6 @@ describe('Animation', () => { expect(DOM.getAnimationEvent(fakeEl)).toBe('oAnimationEnd'); }); - test('Prefixed Gecko', () => { const fakeEl = { style: { @@ -153,7 +152,6 @@ describe('Animation', () => { expect(DOM.getAnimationEvent(fakeEl)).toBe('animationend'); }); - test('Prefixed Webkit', () => { const fakeEl = { style: { @@ -268,3 +266,4 @@ describe('Focusble Element', () => { expect(DOM.isFocusableElement()).toBe(true); }); }); + diff --git a/test/utils/webslides.js b/test/utils/webslides.js deleted file mode 100644 index cd1617e..0000000 --- a/test/utils/webslides.js +++ /dev/null @@ -1,115 +0,0 @@ -let phantom = require("phantom"); -import test from 'ava'; - -let ph_, page_, status_; - -/** - * Functions - */ -const load = async () => { - const log = console.log; - const nolog = function() {}; - await phantom.create([], { logger: { warn: log, debug: nolog, error: log } } - ).then(async ph => { - ph_ = ph; - return await ph_.createPage(); - }).then(page => { - page_ = page; - return page_.open('file:///'+__dirname.replace(/\\/g, '/')+'/../../index.html'); - }).then(async status => { - const content = await page_.property('content'); - status_ = status; - return true; - }).catch(e => console.log(e)); -} - -const timeout = async ms => { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -const onlyOneVisible = async t => { - await page_ - .evaluate( () => window.ws.slides.filter( - slide => slide.el.style.display != 'none' - ).length == 1 ) - .then( ok => { t.true(ok); } ); -} - -/** - * Tests - */ -test.serial("Page loaded", async t => { - await load(); - t.is(status_, 'success'); -}); - -test.serial('#webslides exits', async t => { - await page_ - .evaluate( () => document.querySelector('#webslides') != null ) - .then( ok => { t.true(ok); } ); -}); - -test.serial('WebSlides object exits', async t => { - await page_ - .evaluate( () => window.ws != null ) - .then( ok => { t.true(ok); } ); -}); - -test.serial('Has slides', async t => { - await page_ - .evaluate( () => window.ws.slides.length > 0 ) - .then( ok => { t.true(ok); } ); -}); - -test.serial('First slide visible', async t => { - await page_ - .evaluate( () => window.ws.slides[0].el.style.display != 'none' ) - .then( ok => { t.true(ok); } ); -}); - -test.serial('Has only one slide visible', onlyOneVisible); - -test.serial('goNext', async t => { - // First needs to execute the function - page_ - .evaluate( () => { - window.ws.goNext(); - return true; - }); - // Then wait - await timeout(600); - // Finally test - await page_ - .evaluate( () => window.ws.slides[1].el.style.display != 'none' ) - .then( ok => { t.true(ok); } ); -}); - -test.serial('Has only one slide visible', onlyOneVisible); - - -test.serial('goPrev', async t => { - // First needs to execute the function - page_ - .evaluate( () => { - window.ws.goPrev(); - return true; - }); - // Then wait - await timeout(600); - // Finally test - await page_ - .evaluate( () => window.ws.slides[0].el.style.display != 'none' ) - .then( ok => { t.true(ok); } ); -}); - -test.serial('Has only one slide visible', onlyOneVisible); - - -/** - * Last test - */ -test.serial('Closing', async t => { - await page_.close(); - ph_.exit(); - t.true(true); -});