mirror of
https://github.com/webslides/WebSlides.git
synced 2025-08-14 17:14:43 +02:00
Linting
This commit is contained in:
@@ -70,6 +70,9 @@
|
||||
"jest": {
|
||||
"collectCoverage": true
|
||||
},
|
||||
"pre-commit": [
|
||||
"lint"
|
||||
],
|
||||
"babel": {
|
||||
"presets": [
|
||||
[
|
||||
|
@@ -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;
|
||||
|
@@ -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');
|
||||
|
4
static/js/webslides.min.js
vendored
4
static/js/webslides.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,7 +1,8 @@
|
||||
import Slide from '../../src/js/modules/slide';
|
||||
|
||||
beforeAll(() => {
|
||||
const slides = '<section class="slide"><div class="content">Content</section>'.repeat(5);
|
||||
const slides = '<section class="slide"><div class="content">Content</section>'
|
||||
.repeat(5);
|
||||
document.body.innerHTML = `<div id="webslides">${slides}</div>`;
|
||||
});
|
||||
|
||||
@@ -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}`);
|
||||
|
@@ -1,32 +1,32 @@
|
||||
import DOM from '../../src/js/utils/dom';
|
||||
import WebSlides from '../../src/js/modules/webslides';
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
beforeAll(() => {
|
||||
const slides = '<section class="slide"><div class="content">Content</section>'.repeat(20);
|
||||
document.body.innerHTML = `<div id="webslides">${slides}<div id="other"></div></div>`;
|
||||
const slides =
|
||||
'<section class="slide"><div class="content">Content</section>'.repeat(20);
|
||||
document.body.innerHTML =
|
||||
`<div id="webslides">${slides}<div id="other"></div></div>`;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
|
@@ -4,7 +4,8 @@ import AutoSlide from '../../src/js/plugins/autoslide';
|
||||
jest.useFakeTimers();
|
||||
|
||||
beforeAll(() => {
|
||||
document.body.innerHTML = `<div id="webslides"></div><input id="focusable" />`;
|
||||
document.body.innerHTML =
|
||||
`<div id="webslides"></div><input id="focusable" />`;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
|
@@ -2,7 +2,8 @@ import DOM from '../../src/js/utils/dom';
|
||||
import ClickNav from '../../src/js/plugins/click-nav';
|
||||
|
||||
beforeAll(() => {
|
||||
document.body.innerHTML = `<div id="webslides" data-test="test"><p>Text</p></div>`;
|
||||
document.body.innerHTML =
|
||||
`<div id="webslides" data-test="test"><p>Text</p></div>`;
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
@@ -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 = `<div id="webslides" data-test="test"><p>Text</p></div><input id="focusable" />`;
|
||||
document.body.innerHTML = `<div id="webslides" data-test="test">
|
||||
<p>Text</p>
|
||||
</div>
|
||||
<input id="focusable" />`;
|
||||
});
|
||||
|
||||
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();
|
||||
|
@@ -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');
|
||||
|
@@ -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);
|
||||
|
||||
});
|
||||
|
@@ -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);
|
||||
|
||||
});
|
||||
|
@@ -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, '<div id="section-$1" class="slide"><video autoplay="true" /></div>');
|
||||
const slides = '12345'.replace(/(\d)/g,
|
||||
'<div id="section-$1" class="slide"><video autoplay="true" /></div>');
|
||||
document.body.innerHTML = `<div id="webslides">${slides}</div>`;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
|
@@ -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 = '<div id="section-1" class="slide"><div class="embed"><div data-youtube="video" data-youtube-id="CQY3KUR3VzM" data-autoplay data-loop></div></div></div>';
|
||||
document.body.innerHTML = `<script></script><div id="webslides">${video}</div>`;
|
||||
const video = '<div id="section-1" class="slide"><div class="embed">' +
|
||||
'<div data-youtube="video" ' +
|
||||
' data-youtube-id="CQY3KUR3VzM" ' +
|
||||
' data-autoplay data-loop></div></div></div>';
|
||||
document.body.innerHTML =
|
||||
`<script></script><div id="webslides">${video}</div>`;
|
||||
});
|
||||
|
||||
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 = '<iframe id="widget8" src="https://www.youtube.com/embed/_m67JbGjWnc" title="YouTube video player" allowfullscreen="1" data-youtube-id="_m67JbGjWnc" frameborder="0" height="360" width="640"></iframe>';
|
||||
webslides.slides[0].el.appendChild(div);
|
||||
return div.querySelector('iframe');
|
||||
} }
|
||||
return {
|
||||
getIframe: () => {
|
||||
const div = DOM.createNode('div');
|
||||
div.innerHTML =
|
||||
`<iframe id="widget8"
|
||||
src="https://www.youtube.com/embed/_m67JbGjWnc"
|
||||
data-youtube-id="_m67JbGjWnc"
|
||||
frameborder="0" height="360" width="640"></iframe>`;
|
||||
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);
|
||||
|
||||
});
|
||||
|
@@ -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, '<div id="section-$1" class="slide"><div>Slide $1</div></div>');
|
||||
const slides = '12345'.replace(/(\d)/g,
|
||||
'<div id="section-$1" class="slide"><div>Slide $1</div></div>');
|
||||
document.body.innerHTML = `<div id="webslides">${slides}</div>`;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -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);
|
||||
});
|
Reference in New Issue
Block a user