mirror of
https://github.com/webslides/WebSlides.git
synced 2025-08-17 18:37:00 +02:00
Testing love
This commit is contained in:
@@ -15,6 +15,7 @@ function canIuseNativeCustom() {
|
|||||||
return 't' === p.type && 'b' === p.detail.a;
|
return 't' === p.type && 'b' === p.detail.a;
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
|
|
||||||
|
/* istanbul ignore next: hard to reproduce on test environment */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ function canIuseNativeCustom() {
|
|||||||
* @return {Event}
|
* @return {Event}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
/* istanbul ignore next: hard to reproduce on test environment */
|
||||||
const IECustomEvent = function CustomEvent(type, params) {
|
const IECustomEvent = function CustomEvent(type, params) {
|
||||||
const e = document.createEvent('CustomEvent');
|
const e = document.createEvent('CustomEvent');
|
||||||
|
|
||||||
@@ -37,6 +39,7 @@ const IECustomEvent = function CustomEvent(type, params) {
|
|||||||
return e;
|
return e;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* istanbul ignore next: hard to reproduce on test environment */
|
||||||
const WSCustomEvent = canIuseNativeCustom() ? NativeCustomEvent : IECustomEvent;
|
const WSCustomEvent = canIuseNativeCustom() ? NativeCustomEvent : IECustomEvent;
|
||||||
|
|
||||||
export default WSCustomEvent;
|
export default WSCustomEvent;
|
||||||
|
@@ -191,6 +191,23 @@ describe('Show/hide', () => {
|
|||||||
DOM.hide(el);
|
DOM.hide(el);
|
||||||
expect(el.style.display).toBe('none');
|
expect(el.style.display).toBe('none');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Is visible', () => {
|
||||||
|
// offsetParent doesn't work nice with JSDom
|
||||||
|
const el = DOM.createNode('div');
|
||||||
|
let offsetParent = document.body;
|
||||||
|
el.style.display = 'block';
|
||||||
|
|
||||||
|
document.body.appendChild(el);
|
||||||
|
Object.defineProperty(el, 'offsetParent', {get: () => offsetParent});
|
||||||
|
expect(DOM.isVisible(el)).toBe(true);
|
||||||
|
|
||||||
|
DOM.hide(el);
|
||||||
|
offsetParent = null;
|
||||||
|
|
||||||
|
expect(DOM.isVisible(el)).toBe(false);
|
||||||
|
document.body.removeChild(el);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Custom Event', () => {
|
describe('Custom Event', () => {
|
||||||
@@ -229,7 +246,7 @@ describe('To Array', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Focusble Element', () => {
|
describe('Focusable Element', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
document.body.innerHTML = `
|
document.body.innerHTML = `
|
||||||
<p id="noContent" tabindex="0"></p>
|
<p id="noContent" tabindex="0"></p>
|
||||||
|
@@ -7,17 +7,52 @@ beforeAll(() => {
|
|||||||
document.body.innerHTML = `<div id="webslides">${brs}</div>`;
|
document.body.innerHTML = `<div id="webslides">${brs}</div>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ScrollTo utility', () => {
|
afterAll(() => {
|
||||||
|
jest.clearAllTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('ScrollTo with defaults', () => {
|
||||||
const ws = document.getElementById('webslides');
|
const ws = document.getElementById('webslides');
|
||||||
const cb = jest.fn();
|
|
||||||
|
|
||||||
scrollTo(100, 500, cb);
|
scrollTo(100);
|
||||||
|
|
||||||
expect(cb).not.toBeCalled();
|
|
||||||
expect(ws.scrollTop).toBe(0);
|
expect(ws.scrollTop).toBe(0);
|
||||||
|
|
||||||
|
jest.runTimersToTime(400);
|
||||||
|
|
||||||
|
expect(ws.scrollTop).toBeLessThan(100);
|
||||||
|
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
|
|
||||||
expect(cb).toBeCalled();
|
|
||||||
expect(ws.scrollTop).toBe(100);
|
expect(ws.scrollTop).toBe(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('ScrollTo with custom duration', () => {
|
||||||
|
const ws = document.getElementById('webslides');
|
||||||
|
ws.scrollTop = 0;
|
||||||
|
scrollTo(100, 2000);
|
||||||
|
|
||||||
|
expect(ws.scrollTop).toBe(0);
|
||||||
|
jest.runTimersToTime(500);
|
||||||
|
expect(ws.scrollTop).toBeLessThan(100);
|
||||||
|
jest.runTimersToTime(700);
|
||||||
|
expect(ws.scrollTop).toBeLessThan(100);
|
||||||
|
jest.runAllTimers();
|
||||||
|
|
||||||
|
expect(ws.scrollTop).toBe(100);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('ScrollTo with custom callback', () => {
|
||||||
|
const ws = document.getElementById('webslides');
|
||||||
|
ws.scrollTop = 0;
|
||||||
|
const cb = jest.fn();
|
||||||
|
|
||||||
|
scrollTo(100, 500, cb);
|
||||||
|
expect(ws.scrollTop).toBe(0);
|
||||||
|
expect(cb).not.toBeCalled();
|
||||||
|
|
||||||
|
jest.runAllTimers();
|
||||||
|
|
||||||
|
expect(ws.scrollTop).toBe(100);
|
||||||
|
expect(cb).toBeCalled();
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user