yeet
This commit is contained in:
50
node_modules/@egjs/hammerjs/tests/unit/assets/utils.js
generated
vendored
Normal file
50
node_modules/@egjs/hammerjs/tests/unit/assets/utils.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
var utils = {
|
||||
/**
|
||||
* trigger simple dom event
|
||||
* @param obj
|
||||
* @param name
|
||||
*/
|
||||
triggerDomEvent: function(obj, name) {
|
||||
var event = document.createEvent('Event');
|
||||
event.initEvent(name, true, true);
|
||||
obj.dispatchEvent(event);
|
||||
},
|
||||
|
||||
|
||||
createTouchEvent: function(name, x, y, identifier) {
|
||||
var event = document.createEvent('Event');
|
||||
event.initEvent('touch' + name, true, true);
|
||||
|
||||
event.touches = event.targetTouches = [{
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
identifier: identifier || 0
|
||||
}];
|
||||
|
||||
//https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent.changedTouches
|
||||
event.changedTouches = [{
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
identifier: identifier || 0
|
||||
}];
|
||||
|
||||
return event;
|
||||
},
|
||||
|
||||
dispatchTouchEvent: function(el, name, x, y, identifier) {
|
||||
var event = utils.createTouchEvent(name, x, y, identifier);
|
||||
el.dispatchEvent(event);
|
||||
},
|
||||
|
||||
createHitArea: function(parent) {
|
||||
if (parent == null) {
|
||||
parent = document.getElementById('qunit-fixture')
|
||||
}
|
||||
var hitArea = document.createElement('div');
|
||||
hitArea.style.background = '#eee';
|
||||
hitArea.style.height = '300px';
|
||||
|
||||
parent.appendChild(hitArea);
|
||||
return hitArea;
|
||||
}
|
||||
};
|
67
node_modules/@egjs/hammerjs/tests/unit/gestures/test_pan.js
generated
vendored
Normal file
67
node_modules/@egjs/hammerjs/tests/unit/gestures/test_pan.js
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils,Simulator */
|
||||
|
||||
var el;
|
||||
var hammer;
|
||||
|
||||
QUnit.module('Pan Gesture', {
|
||||
beforeEach: function() {
|
||||
el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
|
||||
hammer = new Hammer(el, { recognizers: [] });
|
||||
},
|
||||
afterEach: function() {
|
||||
document.body.removeChild(el);
|
||||
hammer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('`panstart` and `panmove` should be recognized', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var panMoveCount = 0;
|
||||
var pan = new Hammer.Pan({ threshold: 1 });
|
||||
|
||||
hammer.add(pan);
|
||||
hammer.on('panstart', function() {
|
||||
assert.ok(true, 'Pan start triggered');
|
||||
});
|
||||
hammer.on('panmove', function() {
|
||||
panMoveCount++;
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'move', 70, 50);
|
||||
utils.dispatchTouchEvent(el, 'move', 90, 50);
|
||||
|
||||
assert.equal(panMoveCount, 1, 'exactly one panMove triggered');
|
||||
});
|
||||
|
||||
QUnit.test('Pan event flow should be start -> left -> end', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
var pan = new Hammer.Pan({ threshold: 1 });
|
||||
hammer.add(pan);
|
||||
|
||||
var eventflow = '';
|
||||
var isCalledPanleft = false;
|
||||
hammer.on('panstart', function() {
|
||||
eventflow += 'start';
|
||||
});
|
||||
hammer.on('panleft', function() {
|
||||
if (!isCalledPanleft) {
|
||||
isCalledPanleft = true;
|
||||
eventflow += 'left';
|
||||
}
|
||||
});
|
||||
hammer.on('panend', function() {
|
||||
eventflow += 'end';
|
||||
isCalledPanleft = true;
|
||||
});
|
||||
|
||||
Simulator.gestures.pan(el, { deltaX: -100, deltaY: 0 }, function() {
|
||||
assert.equal(eventflow, 'startleftend', 'correct event flow');
|
||||
done();
|
||||
});
|
||||
});
|
46
node_modules/@egjs/hammerjs/tests/unit/gestures/test_pinch.js
generated
vendored
Normal file
46
node_modules/@egjs/hammerjs/tests/unit/gestures/test_pinch.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,Simulator */
|
||||
|
||||
var el;
|
||||
var hammer;
|
||||
|
||||
QUnit.module('Pinch Gesture', {
|
||||
beforeEach: function() {
|
||||
el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
|
||||
hammer = new Hammer(el, { recognizers: [] });
|
||||
},
|
||||
afterEach: function() {
|
||||
document.body.removeChild(el);
|
||||
hammer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('Pinch event flow should be start -> in -> end', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
var pinch = new Hammer.Pinch({ enable: true, threshold: 0.1 });
|
||||
hammer.add(pinch);
|
||||
|
||||
var eventflow = '';
|
||||
var isFiredPinchin = false;
|
||||
hammer.on('pinchstart', function() {
|
||||
eventflow += 'start';
|
||||
});
|
||||
hammer.on('pinchin', function() {
|
||||
if (!isFiredPinchin) {
|
||||
isFiredPinchin = true;
|
||||
eventflow += 'in';
|
||||
}
|
||||
});
|
||||
hammer.on('pinchend', function() {
|
||||
eventflow += 'end';
|
||||
isFiredPinchin = false;
|
||||
});
|
||||
|
||||
Simulator.gestures.pinch(el, { duration: 500, scale: 0.5 }, function() {
|
||||
assert.equal(eventflow, 'startinend', 'correct event flow');
|
||||
done();
|
||||
});
|
||||
});
|
29
node_modules/@egjs/hammerjs/tests/unit/gestures/test_swipe.js
generated
vendored
Normal file
29
node_modules/@egjs/hammerjs/tests/unit/gestures/test_swipe.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils,Simulator */
|
||||
|
||||
var el;
|
||||
var hammer;
|
||||
var swipeCount = 0;
|
||||
|
||||
QUnit.module('Swipe Gesture', {
|
||||
beforeEach: function() {
|
||||
el = utils.createHitArea();
|
||||
hammer = new Hammer(el, { recognizers: [] });
|
||||
swipeCount = 0;
|
||||
},
|
||||
afterEach: function() {
|
||||
hammer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('swipe can be recognized', function(assert) {
|
||||
assert.expect(1);
|
||||
var done = assert.async();
|
||||
var swipe = new Hammer.Swipe({ threshold: 1 });
|
||||
hammer.add(swipe);
|
||||
hammer.on('swipe', function() {
|
||||
assert.ok(true);
|
||||
done();
|
||||
});
|
||||
Simulator.gestures.swipe(el);
|
||||
});
|
43
node_modules/@egjs/hammerjs/tests/unit/index.html
generated
vendored
Normal file
43
node_modules/@egjs/hammerjs/tests/unit/index.html
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title>Tests</title>
|
||||
<link rel="stylesheet" href="../../node_modules/qunitjs/qunit/qunit.css">
|
||||
|
||||
<script src="../../node_modules/jquery/dist/jquery.min.js"></script>
|
||||
<script src="../../node_modules/lodash-compat/index.js"></script>
|
||||
<script src="../../node_modules/qunitjs/qunit/qunit.js"></script>
|
||||
<!--[if !IE]> --><script src="../../node_modules/blanket/dist/qunit/blanket.js"></script><!-- <![endif]-->
|
||||
<script src="assets/utils.js"></script>
|
||||
|
||||
<script src="../../node_modules/hammer-simulator/index.js"></script>
|
||||
<script>
|
||||
Simulator.setType('touch');
|
||||
Simulator.events.touch.fakeSupport();
|
||||
</script>
|
||||
|
||||
<script src="../../dist/hammer.js" data-cover></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
|
||||
<script src="test_utils.js"></script>
|
||||
<script src="test_enable.js"></script>
|
||||
<script src="test_hammer.js"></script>
|
||||
<script src="test_events.js"></script>
|
||||
<script src="test_nested_gesture_recognizers.js"></script>
|
||||
<script src="test_simultaneous_recognition.js"></script>
|
||||
<script src="test_propagation_bubble.js"></script>
|
||||
<script src="test_gestures.js"></script>
|
||||
<script src="test_multiple_taps.js"></script>
|
||||
<script src="test_require_failure.js"></script>
|
||||
|
||||
<script src="test_jquery_plugin.js"></script>
|
||||
<script src="gestures/test_pan.js"></script>
|
||||
<script src="gestures/test_pinch.js"></script>
|
||||
<script src="gestures/test_swipe.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
179
node_modules/@egjs/hammerjs/tests/unit/test_enable.js
generated
vendored
Normal file
179
node_modules/@egjs/hammerjs/tests/unit/test_enable.js
generated
vendored
Normal file
@ -0,0 +1,179 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils */
|
||||
/* jshint unused:false */
|
||||
|
||||
var el,
|
||||
hammer,
|
||||
counter;
|
||||
|
||||
QUnit.module('Test recognizer enable', {
|
||||
beforeEach: function() {
|
||||
el = utils.createHitArea();
|
||||
hammer = new Hammer.Manager(el, { recognizers: [] });
|
||||
counter = 0;
|
||||
},
|
||||
afterEach: function() {
|
||||
hammer && hammer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('should disable a recognizer through the `enable` constructor parameter', function(assert) {
|
||||
assert.expect(1);
|
||||
hammer.add(new Hammer.Tap({ enable: false }));
|
||||
hammer.on('tap', function() {
|
||||
counter++;
|
||||
});
|
||||
|
||||
var done = assert.async();
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
setTimeout(function() {
|
||||
|
||||
assert.equal(counter, 0, 'counter is zero');
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
QUnit.test('should disable recognizing when the manager is disabled.', function(assert) {
|
||||
assert.expect(1);
|
||||
hammer.set({ enable: false });
|
||||
hammer.add(new Hammer.Tap());
|
||||
hammer.on('tap', function() {
|
||||
counter++;
|
||||
});
|
||||
|
||||
var done = assert.async();
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(counter, 0, 'counter is zero');
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
QUnit.test('should toggle a recognizer using the `set` call to the recognizer enable property', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
hammer.add(new Hammer.Tap());
|
||||
hammer.on('tap', function() {
|
||||
counter++;
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
assert.equal(counter, 1);
|
||||
|
||||
hammer.get('tap').set({ enable: false });
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
assert.equal(counter, 1, 'counter is 1');
|
||||
});
|
||||
|
||||
QUnit.test('should accept the `enable` constructor parameter as function', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var canRecognizeTap = false;
|
||||
|
||||
var tap = new Hammer.Tap({
|
||||
enable: function() {
|
||||
return canRecognizeTap;
|
||||
}
|
||||
});
|
||||
|
||||
hammer.add(tap);
|
||||
hammer.on('tap', function() {
|
||||
counter++;
|
||||
});
|
||||
|
||||
var done = assert.async();
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(counter, 0, 'counter is zero');
|
||||
|
||||
canRecognizeTap = true;
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
assert.equal(counter, 1, 'counter is 1');
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
QUnit.test('should accept a function parameter with `set`', function(assert) {
|
||||
assert.expect(3);
|
||||
|
||||
hammer.add(new Hammer.Tap());
|
||||
hammer.on('tap', function() {
|
||||
counter++;
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
assert.equal(counter, 1, 'counter is 1');
|
||||
|
||||
var canRecognizeTap = false;
|
||||
hammer.get('tap').set({ enable: function() {
|
||||
return canRecognizeTap;
|
||||
} });
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
assert.equal(counter, 1, 'counter is 1');
|
||||
|
||||
canRecognizeTap = true;
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
assert.equal(counter, 2, 'counter is 2');
|
||||
});
|
||||
|
||||
QUnit.test('should pass the recognizer and optional the input parameter to the `enable` callback', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var tap;
|
||||
|
||||
// The enable function is called initially to setup the touch-action property
|
||||
// at that moment there isn't any input
|
||||
var canEnable = function(recognizer, input) {
|
||||
assert.equal(recognizer, tap, 'recognizer is tap');
|
||||
return true;
|
||||
};
|
||||
tap = new Hammer.Tap({ enable: canEnable });
|
||||
hammer.add(tap);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
});
|
||||
|
||||
QUnit.test('should toggle based on other object method', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var view = {
|
||||
state: 0,
|
||||
canRecognizeTap: function(recognizer, input) {
|
||||
return this.state !== 0;
|
||||
}
|
||||
};
|
||||
|
||||
hammer.add(new Hammer.Tap({ enable: function(rec, input) {
|
||||
return view.canRecognizeTap(rec, input);
|
||||
} }));
|
||||
hammer.on('tap', function() {
|
||||
counter++;
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
assert.equal(counter, 0, 'counter is 0');
|
||||
|
||||
view.state = 1;
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
assert.equal(counter, 1, 'counter is 1');
|
||||
});
|
64
node_modules/@egjs/hammerjs/tests/unit/test_events.js
generated
vendored
Normal file
64
node_modules/@egjs/hammerjs/tests/unit/test_events.js
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils,el */
|
||||
|
||||
QUnit.module('eventEmitter');
|
||||
|
||||
QUnit.test('test the eventemitter', function(assert) {
|
||||
assert.expect(6);
|
||||
|
||||
var ee = new Hammer.Manager(utils.createHitArea());
|
||||
var inputData = {
|
||||
target: document.body,
|
||||
srcEvent: {
|
||||
preventDefault: function() {
|
||||
assert.ok(true, 'preventDefault ref');
|
||||
},
|
||||
target: document.body
|
||||
}
|
||||
};
|
||||
|
||||
function event3Handler() {
|
||||
assert.ok(true, 'emitted event3');
|
||||
}
|
||||
|
||||
ee.on('testEvent1', function() {
|
||||
assert.ok(true, 'emitted event');
|
||||
});
|
||||
ee.on('testEvent2', function(ev) {
|
||||
assert.ok(true, 'emitted event');
|
||||
ev.preventDefault();
|
||||
assert.ok(ev.target === document.body, 'target is the body');
|
||||
});
|
||||
ee.on('testEvent3', event3Handler);
|
||||
|
||||
ee.emit('testEvent1', inputData);
|
||||
ee.emit('testEvent2', inputData);
|
||||
ee.emit('testEvent3', inputData);
|
||||
|
||||
// Unbind testEvent2
|
||||
ee.off('testEvent2');
|
||||
ee.off('testEvent3', event3Handler);
|
||||
|
||||
ee.emit('testEvent1', inputData); // Should trigger testEvent1 again
|
||||
ee.emit('testEvent2', inputData); // Doenst trigger a thing
|
||||
ee.emit('testEvent3', inputData); // Doenst trigger a thing
|
||||
|
||||
// Destroy
|
||||
ee.destroy();
|
||||
|
||||
ee.emit('testEvent1', inputData); // Doenst trigger a thing
|
||||
ee.emit('testEvent2', inputData); // Doenst trigger a thing
|
||||
ee.emit('testEvent3', inputData); // Doenst trigger a thing
|
||||
});
|
||||
|
||||
/*
|
||||
* Hammer.Manager.off method : exception handling
|
||||
*/
|
||||
QUnit.test('When Hammer.Manager didnt attach an event, `off` method is ignored', function(assert) {
|
||||
var count = 0;
|
||||
var hammer = new Hammer(el, { inputTarget: document.body });
|
||||
hammer.off('swipeleft', function() {
|
||||
count++;
|
||||
});
|
||||
assert.ok(true, 'nothing');
|
||||
});
|
225
node_modules/@egjs/hammerjs/tests/unit/test_gestures.js
generated
vendored
Normal file
225
node_modules/@egjs/hammerjs/tests/unit/test_gestures.js
generated
vendored
Normal file
@ -0,0 +1,225 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils,Simulator */
|
||||
|
||||
// TODO: this tests fails because tapRecognizer changes
|
||||
// it could be that tapRecognizer setup its BEGAN state and
|
||||
// disable the other gesture recognition
|
||||
var el;
|
||||
var hammer;
|
||||
var events;
|
||||
var allGestureEvents = [
|
||||
'tap doubletap press',
|
||||
'pinch pinchin pinchout pinchstart pinchmove pinchend pinchcancel',
|
||||
'rotate rotatestart rotatemove rotateend rotatecancel',
|
||||
'pan panstart panmove panup pandown panleft panright panend pancancel',
|
||||
'swipe swipeleft swiperight swipeup swipedown'
|
||||
].join(' ');
|
||||
|
||||
QUnit.module('Gesture recognition', {
|
||||
beforeEach: function() {
|
||||
el = utils.createHitArea();
|
||||
hammer = new Hammer(el);
|
||||
hammer.get('pinch')
|
||||
.set({ // Some threshold, since the simulator doesnt stays at scale:1 when rotating
|
||||
enable: true,
|
||||
threshold: 0.1
|
||||
});
|
||||
|
||||
hammer.get('rotate')
|
||||
.set({ enable: true });
|
||||
|
||||
hammer.on(allGestureEvents, function(ev) {
|
||||
events[ ev.type ] = true;
|
||||
});
|
||||
events = {};
|
||||
},
|
||||
afterEach: function() {
|
||||
hammer && hammer.destroy();
|
||||
events = null;
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('recognize pan', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
Simulator.gestures.pan(el, { duration: 500, deltaX: 100, deltaY: 0 }, function() {
|
||||
assert.deepEqual(events, {
|
||||
pan: true,
|
||||
panstart: true,
|
||||
panmove: true,
|
||||
panright: true,
|
||||
panend: true
|
||||
}, 'Pan events recognized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('recognize press', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
Simulator.gestures.press(el, null, function() {
|
||||
assert.deepEqual(events, {
|
||||
press: true
|
||||
});
|
||||
done();
|
||||
}, 'only press was recognized');
|
||||
});
|
||||
|
||||
QUnit.test('recognize swipe', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
Simulator.gestures.swipe(el, { duration: 300, deltaX: 400, deltaY: 0 }, function() {
|
||||
assert.deepEqual(events, {
|
||||
pan: true,
|
||||
panstart: true,
|
||||
panmove: true,
|
||||
panright: true,
|
||||
panend: true,
|
||||
swipe: true,
|
||||
swiperight: true
|
||||
}, 'pan and swipe events were recognized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('recognize pinch', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
Simulator.gestures.pinch(el, { duration: 500, scale: 0.5 }, function() {
|
||||
assert.deepEqual(events, {
|
||||
pinch: true,
|
||||
pinchstart: true,
|
||||
pinchmove: true,
|
||||
pinchend: true,
|
||||
pinchin: true
|
||||
}, 'pinch events were recognized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('recognize children multitouch pinch', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
var el1 = utils.createHitArea(el);
|
||||
var el2 = utils.createHitArea(el);
|
||||
|
||||
Simulator.gestures.pinch([ el1, el2 ], { duration: 500, scale: 0.5 }, function() {
|
||||
assert.deepEqual(events, {
|
||||
pinch: true,
|
||||
pinchstart: true,
|
||||
pinchmove: true,
|
||||
pinchend: true,
|
||||
pinchin: true
|
||||
}, 'pinch events on child were recognized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('recognize parent-child multitouch pinch', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
var el1 = utils.createHitArea(el);
|
||||
|
||||
Simulator.gestures.pinch([ el, el1 ], { duration: 100, scale: 0.5 }, function() {
|
||||
assert.deepEqual(events, {
|
||||
pinch: true,
|
||||
pinchstart: true,
|
||||
pinchmove: true,
|
||||
pinchend: true,
|
||||
pinchin: true
|
||||
}, 'Pinch events on parent were recognized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('recognize rotate', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
Simulator.gestures.rotate(el, { duration: 500, scale: 1 }, function() {
|
||||
assert.deepEqual(events, {
|
||||
rotate: true,
|
||||
rotatestart: true,
|
||||
rotatemove: true,
|
||||
rotateend: true
|
||||
}, 'Rotate events recognized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('recognize multitouch rotate', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
var el1 = utils.createHitArea(el);
|
||||
|
||||
Simulator.gestures.rotate([ el, el1 ], { duration: 500, scale: 1 }, function() {
|
||||
assert.deepEqual(events, {
|
||||
rotate: true,
|
||||
rotatestart: true,
|
||||
rotatemove: true,
|
||||
rotateend: true
|
||||
}, 'Rotate events were recognized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('recognize rotate and pinch simultaneous', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
Simulator.gestures.pinchRotate(el, { duration: 500, scale: 2 }, function() {
|
||||
assert.deepEqual(events, {
|
||||
rotate: true,
|
||||
rotatestart: true,
|
||||
rotatemove: true,
|
||||
rotateend: true,
|
||||
pinch: true,
|
||||
pinchstart: true,
|
||||
pinchmove: true,
|
||||
pinchend: true,
|
||||
pinchout: true
|
||||
}, 'Rotate and pinch were recognized together');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test("don't recognize pan and swipe when moving down, when only horizontal is allowed", function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
Simulator.gestures.swipe(el, { duration: 250, deltaX: 0, deltaZ: 200 }, function() {
|
||||
assert.deepEqual(events, { }, 'No events were recognized');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test("don't recognize press if duration is too short.", function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
Simulator.gestures.press(el, { duration: 240 });
|
||||
|
||||
setTimeout(function() {
|
||||
assert.deepEqual(events, { tap: true }, 'Tap gesture has been recognized.');
|
||||
done();
|
||||
}, 275);
|
||||
});
|
||||
|
||||
QUnit.test("don't recognize tap if duration is too long.", function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
Simulator.gestures.tap(el, { duration: 255 });
|
||||
|
||||
setTimeout(function() {
|
||||
assert.deepEqual(events, { press: true }, 'Press gesture has been recognized.');
|
||||
done();
|
||||
}, 275);
|
||||
});
|
197
node_modules/@egjs/hammerjs/tests/unit/test_hammer.js
generated
vendored
Normal file
197
node_modules/@egjs/hammerjs/tests/unit/test_hammer.js
generated
vendored
Normal file
@ -0,0 +1,197 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals,requireTemplateStringsForConcatenation,requireArrayDestructuring
|
||||
/* globals QUnit,Hammer,utils,Simulator */
|
||||
|
||||
var el, el2,
|
||||
hammer, hammer2;
|
||||
|
||||
QUnit.module('Tests', {
|
||||
beforeEach: function() {
|
||||
el = utils.createHitArea();
|
||||
el2 = utils.createHitArea();
|
||||
},
|
||||
|
||||
afterEach: function() {
|
||||
if (hammer) {
|
||||
hammer.destroy();
|
||||
hammer = null;
|
||||
}
|
||||
if (hammer2) {
|
||||
hammer2.destroy();
|
||||
hammer2 = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// since Hammer is now a ES6 Class and we cannot call a class as a function,
|
||||
// it needs a `new` keyword prefixed that makes this Shortcut test kinda Redundant.
|
||||
|
||||
// QUnit.test( "hammer shortcut", function( assert ) {
|
||||
// assert.expect( 2 );
|
||||
//
|
||||
// Hammer.defaults.touchAction = "pan-y";
|
||||
// hammer = Hammer( el );
|
||||
//
|
||||
// assert.ok( hammer instanceof Hammer.Manager, "returns an instance of Manager" );
|
||||
// assert.ok( hammer.touchAction.actions == Hammer.defaults.touchAction, "set the default touchAction" );
|
||||
// } );
|
||||
//
|
||||
// QUnit.test( "hammer shortcut with options", function( assert ) {
|
||||
// assert.expect( 2 );
|
||||
//
|
||||
// hammer = Hammer( el, {
|
||||
// touchAction: "none"
|
||||
// } );
|
||||
// assert.ok( hammer instanceof Hammer.Manager, "returns an instance of Manager" );
|
||||
// assert.ok( hammer.touchAction.actions == "none", "set the default touchAction" );
|
||||
// } );
|
||||
|
||||
/* Creating a hammer instance does not work on the same way
|
||||
* when using Hammer or Hammer.Manager.
|
||||
*
|
||||
* This can confuse developers who read tests to use the library when doc is missing.
|
||||
*/
|
||||
QUnit.test('Hammer and Hammer.Manager constructors work exactly on the same way.', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
hammer = new Hammer(el, {});
|
||||
assert.equal(Hammer.defaults.preset.length, hammer.recognizers.length,
|
||||
'Correct number of recognizers by default');
|
||||
|
||||
hammer2 = new Hammer.Manager(el, {});
|
||||
assert.equal(0, hammer2.recognizers.length, 'No default recognizers with manager and empty object');
|
||||
});
|
||||
|
||||
/* DOC to disable default recognizers should be added.
|
||||
*
|
||||
* - Hammer(el). IMO: Currently, well done.
|
||||
* - Hammer(el, {}) . IMO: should disable default recognizers
|
||||
* - Hammer(el, {recognizers: null}). IMO: now, it fails.
|
||||
* - Hammer(el, {recognizers: []}). It works, but it is likely not intuitive.
|
||||
*/
|
||||
QUnit.test('A Hammer instance can be setup to not having default recognizers.', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
hammer = new Hammer(el, { recognizers: false });
|
||||
assert.equal(0, hammer.recognizers.length, 'No default recognizers with recognizers false');
|
||||
});
|
||||
|
||||
/* The case was when I added a custom tap event which was added to the default
|
||||
* recognizers, and my custom tap gesture wasn't working (I do not know exactly the reason),
|
||||
* but removing the default recognizers solved the issue.
|
||||
*/
|
||||
QUnit.test('Adding the same recognizer type should remove the old recognizer', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
hammer = new Hammer(el);
|
||||
|
||||
assert.ok(!!hammer.get('tap'));
|
||||
assert.equal(7, hammer.recognizers.length, '7 recognizers found');
|
||||
|
||||
var newTap = new Hammer.Tap({ time: 1337 });
|
||||
hammer.add(newTap);
|
||||
|
||||
assert.equal(7, hammer.recognizers.length, '7 recognizers found after adding tap');
|
||||
assert.equal(1337, hammer.get('tap').options.time, 'Time has been updated to reflect new tap');
|
||||
});
|
||||
|
||||
/*
|
||||
* Swipe gesture:
|
||||
* - in this tests, it does not update input.velocity ( always 0)
|
||||
* - does not fire swipeleft or swiperight events
|
||||
*/
|
||||
QUnit.test('Swiping to the left should fire swipeleft event', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(2);
|
||||
|
||||
hammer = new Hammer(el, { recognizers: [] });
|
||||
hammer.add(new Hammer.Swipe());
|
||||
hammer.on('swipe swipeleft', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
Simulator.gestures.swipe(el, { pos: [ 300, 300 ], deltaY: 0, deltaX: -200 }, function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* Input target change
|
||||
*/
|
||||
QUnit.test('Should detect input while on other element', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
hammer = new Hammer(el, { inputTarget: document.body });
|
||||
hammer.on('tap', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
Simulator.gestures.tap(document.body, null, function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
/* Hammer.Manager constructor accepts a "recognizers" option in which each
|
||||
* element is an array representation of a Recognizer.
|
||||
*/
|
||||
QUnit.test('Hammer.Manager accepts recognizers as arrays.', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
hammer = new Hammer.Manager(el, {
|
||||
recognizers: [
|
||||
[ Hammer.Swipe ],
|
||||
[ Hammer.Pinch ],
|
||||
[ Hammer.Rotate ],
|
||||
[ Hammer.Pan, { direction: Hammer.DIRECTION_UP }, [ 'swipe', 'pinch' ], [ 'rotate' ] ]
|
||||
]
|
||||
});
|
||||
assert.equal(4, hammer.recognizers.length, '4 recognizers found');
|
||||
|
||||
var recognizerActual = hammer.recognizers[ 3 ];
|
||||
assert.equal(recognizerActual.options.direction, Hammer.DIRECTION_UP,
|
||||
'Recognize direction from options');
|
||||
assert.equal(2, Object.keys(recognizerActual.simultaneous).length, '2 simultanious recognizers found');
|
||||
assert.equal(1, recognizerActual.requireFail.length, '1 require failing recognizer found');
|
||||
});
|
||||
|
||||
/*
|
||||
* Removing a recognizer which cannot be found would errantly remove the last recognizer in the
|
||||
* manager's list.
|
||||
*/
|
||||
QUnit.test('Remove non-existent recognizer.', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
hammer = new Hammer(el, { recognizers: [] });
|
||||
hammer.add(new Hammer.Swipe());
|
||||
hammer.remove('tap');
|
||||
|
||||
assert.equal(1, hammer.recognizers.length, '1 recognizer found');
|
||||
});
|
||||
|
||||
QUnit.test('check whether Hammer.defaults.cssProps is restored', function(assert) {
|
||||
var beforeCssProps = {
|
||||
userSelect: 'text',
|
||||
touchSelect: 'grippers',
|
||||
touchCallout: 'default',
|
||||
contentZooming: 'chained',
|
||||
userDrag: 'element',
|
||||
tapHighlightColor: 'rgba(0, 1, 0, 0)'
|
||||
};
|
||||
var prop;
|
||||
Hammer.each(Hammer.defaults.cssProps, function(value, name) {
|
||||
prop = Hammer.prefixed(el.style, name);
|
||||
if (prop) {
|
||||
el.style[ prop ] = beforeCssProps[ name ];
|
||||
}
|
||||
});
|
||||
|
||||
hammer = new Hammer(el);
|
||||
hammer.destroy();
|
||||
hammer = null;
|
||||
Hammer.each(Hammer.defaults.cssProps, function(value, name) {
|
||||
prop = Hammer.prefixed(el.style, name);
|
||||
if (prop) {
|
||||
assert.equal(el.style[ prop ], beforeCssProps[ name ], 'check if ' + name + ' is restored');
|
||||
}
|
||||
});
|
||||
});
|
63
node_modules/@egjs/hammerjs/tests/unit/test_jquery_plugin.js
generated
vendored
Normal file
63
node_modules/@egjs/hammerjs/tests/unit/test_jquery_plugin.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils,Simulator,$,jQuery */
|
||||
|
||||
var el, hammer, events;
|
||||
|
||||
var jQueryPluginPath = '../../node_modules/jquery-hammerjs/jquery.hammer.js';
|
||||
|
||||
QUnit.module('jQuery plugin', {
|
||||
beforeEach: function() {
|
||||
el = utils.createHitArea();
|
||||
events = {};
|
||||
},
|
||||
afterEach: function() {
|
||||
hammer && hammer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('trigger pan with jQuery', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(2);
|
||||
|
||||
$.getScript(jQueryPluginPath, function() {
|
||||
jQuery(el).hammer();
|
||||
jQuery(el).bind('panstart pan panmove panright panend', function(ev) {
|
||||
if (ev.gesture) {
|
||||
events[ ev.type ] = true;
|
||||
}
|
||||
});
|
||||
|
||||
Simulator.gestures.pan(el, { deltaX: 50, deltaY: 0 }, function() {
|
||||
|
||||
assert.deepEqual(events, {
|
||||
pan: true,
|
||||
panstart: true,
|
||||
panmove: true,
|
||||
panright: true,
|
||||
panend: true
|
||||
}, 'Pan events recognized');
|
||||
|
||||
assert.ok(jQuery(el).data('hammer') instanceof Hammer.Manager, 'data attribute refers to the instance');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('trigger pan without jQuery should still work', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
var hammer = new Hammer(el);
|
||||
hammer.on('panstart pan panmove panright panend', function(ev) {
|
||||
events[ev.type] = true;
|
||||
});
|
||||
Simulator.gestures.pan(el, { deltaX: 50, deltaY: 0 }, function() {
|
||||
assert.deepEqual(events, {
|
||||
pan: true,
|
||||
panstart: true,
|
||||
panmove: true,
|
||||
panright: true,
|
||||
panend: true
|
||||
}, 'Pan events recognized');
|
||||
done();
|
||||
});
|
||||
});
|
97
node_modules/@egjs/hammerjs/tests/unit/test_multiple_taps.js
generated
vendored
Normal file
97
node_modules/@egjs/hammerjs/tests/unit/test_multiple_taps.js
generated
vendored
Normal file
@ -0,0 +1,97 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils*/
|
||||
|
||||
var el;
|
||||
var hammer;
|
||||
|
||||
var tripleTapCount = 0;
|
||||
var doubleTapCount = 0;
|
||||
var tapCount = 0;
|
||||
|
||||
QUnit.module('Tap delay', {
|
||||
beforeEach: function() {
|
||||
el = utils.createHitArea();
|
||||
hammer = new Hammer(el, { recognizers: [] });
|
||||
|
||||
var tap = new Hammer.Tap();
|
||||
var doubleTap = new Hammer.Tap({ event: 'doubleTap', taps: 2 });
|
||||
var tripleTap = new Hammer.Tap({ event: 'tripleTap', taps: 3 });
|
||||
|
||||
hammer.add([ tripleTap, doubleTap, tap ]);
|
||||
|
||||
tripleTap.recognizeWith([ doubleTap, tap ]);
|
||||
doubleTap.recognizeWith(tap);
|
||||
|
||||
doubleTap.requireFailure(tripleTap);
|
||||
tap.requireFailure([ tripleTap, doubleTap ]);
|
||||
|
||||
tripleTapCount = 0;
|
||||
doubleTapCount = 0;
|
||||
tapCount = 0;
|
||||
|
||||
hammer.on('tap', function() {
|
||||
tapCount++;
|
||||
});
|
||||
hammer.on('doubleTap', function() {
|
||||
doubleTapCount++;
|
||||
});
|
||||
hammer.on('tripleTap', function() {
|
||||
tripleTapCount++;
|
||||
});
|
||||
},
|
||||
afterEach: function() {
|
||||
hammer.destroy();
|
||||
}
|
||||
});
|
||||
QUnit.test('When a tripleTap is fired, doubleTap and Tap should not be recognized', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(3);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(tripleTapCount, 1, 'one tripletap event');
|
||||
assert.equal(doubleTapCount, 0, 'no doubletap event');
|
||||
assert.equal(tapCount, 0, 'no singletap event');
|
||||
done();
|
||||
}, 350);
|
||||
});
|
||||
QUnit.test('When a doubleTap is fired, tripleTap and Tap should not be recognized', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(3);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(tripleTapCount, 0, 'No tripple taps recognized');
|
||||
assert.equal(doubleTapCount, 1, '1 double tap recognized');
|
||||
assert.equal(tapCount, 0, 'No single taps recognized');
|
||||
done();
|
||||
}, 350);
|
||||
});
|
||||
|
||||
QUnit.test('When a tap is fired, tripleTap and doubleTap should not be recognized', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(3);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'end', 50, 50);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(tripleTapCount, 0, 'No tripple taps recognized');
|
||||
assert.equal(doubleTapCount, 0, 'No double taps recognized');
|
||||
assert.equal(tapCount, 1, '1 single tap recognized');
|
||||
done();
|
||||
}, 350);
|
||||
});
|
170
node_modules/@egjs/hammerjs/tests/unit/test_nested_gesture_recognizers.js
generated
vendored
Normal file
170
node_modules/@egjs/hammerjs/tests/unit/test_nested_gesture_recognizers.js
generated
vendored
Normal file
@ -0,0 +1,170 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils*/
|
||||
/*jshint -W079 */
|
||||
|
||||
var parent,
|
||||
child,
|
||||
hammerChild,
|
||||
hammerParent;
|
||||
|
||||
QUnit.module('Nested gesture recognizers (Tap Child + Pan Parent)', {
|
||||
beforeEach: function() {
|
||||
parent = document.createElement('div');
|
||||
child = document.createElement('div');
|
||||
|
||||
document.getElementById('qunit-fixture').appendChild(parent);
|
||||
parent.appendChild(child);
|
||||
|
||||
hammerParent = new Hammer.Manager(parent, {
|
||||
touchAction: 'none'
|
||||
});
|
||||
hammerChild = new Hammer.Manager(child, {
|
||||
touchAction: 'none'
|
||||
});
|
||||
|
||||
hammerChild.add(new Hammer.Tap());
|
||||
hammerParent.add(new Hammer.Pan({ threshold: 5, pointers: 1 }));
|
||||
},
|
||||
afterEach: function() {
|
||||
hammerChild.destroy();
|
||||
hammerParent.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('Tap on the child', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
hammerChild.on('tap', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
hammerParent.on('tap', function() {
|
||||
throw new Error('tap should not fire on parent');
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(child, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(child, 'end', 0, 10);
|
||||
});
|
||||
|
||||
QUnit.test('Panning on the child should fire parent pan and should not fire child tap event', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
hammerChild.on('tap', function() {
|
||||
throw new Error('tap should not fire on parent');
|
||||
});
|
||||
hammerParent.on('panend', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(child, 'start', 10, 0);
|
||||
utils.dispatchTouchEvent(child, 'move', 20, 0);
|
||||
utils.dispatchTouchEvent(child, 'end', 30, 0);
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
// test (optional pointers validation)
|
||||
test('Panning with one finger down on child, other on parent', function () {
|
||||
expect(1);
|
||||
|
||||
var event,
|
||||
touches;
|
||||
|
||||
hammerParent.on('panend', function () {
|
||||
ok(true);
|
||||
});
|
||||
|
||||
// one finger one child
|
||||
utils.dispatchTouchEvent(child, 'start', 10, 0, 0);
|
||||
utils.dispatchTouchEvent(parent, 'start', 12, 0, 1);
|
||||
|
||||
touches = [
|
||||
{clientX: 20, clientY: 0, identifier: 0 },
|
||||
{clientX: 20, clientY: 0, identifier: 1 }
|
||||
];
|
||||
|
||||
event = document.createEvent('Event');
|
||||
event.initEvent('touchmove', true, true);
|
||||
event.touches = touches;
|
||||
event.changedTouches = touches;
|
||||
|
||||
parent.dispatchEvent(event);
|
||||
|
||||
touches = [
|
||||
{clientX: 30, clientY: 0, identifier: 0 },
|
||||
{clientX: 30, clientY: 0, identifier: 1 }
|
||||
];
|
||||
|
||||
event = document.createEvent('Event');
|
||||
event.initEvent('touchend', true, true);
|
||||
event.touches = touches;
|
||||
event.changedTouches = touches;
|
||||
|
||||
parent.dispatchEvent(event);
|
||||
});
|
||||
*/
|
||||
|
||||
var pressPeriod = 600;
|
||||
QUnit.module('Nested gesture recognizers (Press Child + Pan Parent)', {
|
||||
beforeEach: function() {
|
||||
parent = document.createElement('div');
|
||||
child = document.createElement('div');
|
||||
|
||||
document.getElementById('qunit-fixture').appendChild(parent);
|
||||
parent.appendChild(child);
|
||||
|
||||
hammerParent = new Hammer.Manager(parent, {
|
||||
touchAction: 'none'
|
||||
});
|
||||
hammerChild = new Hammer.Manager(child, {
|
||||
touchAction: 'none'
|
||||
});
|
||||
|
||||
hammerChild.add(new Hammer.Press({ time: pressPeriod }));
|
||||
hammerParent.add(new Hammer.Pan({ threshold: 5, pointers: 1 }));
|
||||
},
|
||||
afterEach: function() {
|
||||
hammerChild.destroy();
|
||||
hammerParent.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('Press on the child', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
hammerChild.on('press', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
hammerParent.on('press', function() {
|
||||
throw new Error('press should not fire on parent');
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(child, 'start', 0, 10);
|
||||
|
||||
var done = assert.async();
|
||||
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, pressPeriod);
|
||||
});
|
||||
|
||||
QUnit.test('When Press is followed by Pan on the same element, both gestures are recognized', function(assert) {
|
||||
assert.expect(2);
|
||||
hammerChild.on('press', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
hammerParent.on('panend', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(child, 'start', 0, 10);
|
||||
var done = assert.async();
|
||||
|
||||
setTimeout(function() {
|
||||
utils.dispatchTouchEvent(child, 'move', 10, 10);
|
||||
utils.dispatchTouchEvent(child, 'move', 20, 10);
|
||||
utils.dispatchTouchEvent(child, 'move', 30, 10);
|
||||
utils.dispatchTouchEvent(child, 'end', 30, 10);
|
||||
|
||||
done();
|
||||
}, pressPeriod);
|
||||
});
|
60
node_modules/@egjs/hammerjs/tests/unit/test_propagation_bubble.js
generated
vendored
Normal file
60
node_modules/@egjs/hammerjs/tests/unit/test_propagation_bubble.js
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils*/
|
||||
/*jshint -W079 */
|
||||
|
||||
var parent;
|
||||
var child;
|
||||
var hammerChild;
|
||||
var hammerParent;
|
||||
|
||||
QUnit.module('Propagation (Tap in Child and Parent)', {
|
||||
beforeEach: function() {
|
||||
parent = document.createElement('div');
|
||||
child = document.createElement('div');
|
||||
|
||||
document.getElementById('qunit-fixture').appendChild(parent);
|
||||
parent.appendChild(child);
|
||||
|
||||
hammerParent = new Hammer.Manager(parent);
|
||||
hammerChild = new Hammer.Manager(child);
|
||||
|
||||
hammerChild.add(new Hammer.Tap());
|
||||
hammerParent.add(new Hammer.Tap());
|
||||
},
|
||||
afterEach: function() {
|
||||
hammerChild.destroy();
|
||||
hammerParent.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('Tap on the child, fires also the tap event to the parent', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
hammerChild.on('tap', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
hammerParent.on('tap', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(child, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(child, 'end', 0, 10);
|
||||
});
|
||||
|
||||
QUnit.test('When tap on the child and the child stops the input event propagation, the tap event does not get fired in the parent', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
hammerChild.on('tap', function() {
|
||||
assert.ok(true);
|
||||
});
|
||||
hammerParent.on('tap', function() {
|
||||
throw new Error('parent tap gesture should not be recognized');
|
||||
});
|
||||
|
||||
child.addEventListener('touchend', function(ev) {
|
||||
ev.stopPropagation();
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(child, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(child, 'end', 0, 10);
|
||||
});
|
118
node_modules/@egjs/hammerjs/tests/unit/test_require_failure.js
generated
vendored
Normal file
118
node_modules/@egjs/hammerjs/tests/unit/test_require_failure.js
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils,Simulator */
|
||||
|
||||
var el;
|
||||
var hammer;
|
||||
var pressPeriod = 200;
|
||||
var pressThreshold = 20;
|
||||
var pressCount = 0;
|
||||
var panStartCount = 0;
|
||||
var swipeCount = 0;
|
||||
|
||||
QUnit.module('Require Failure ( Swipe & Press )', {
|
||||
beforeEach: function() {
|
||||
el = utils.createHitArea();
|
||||
hammer = new Hammer(el, { recognizers: [] });
|
||||
|
||||
var swipe = new Hammer.Swipe({ threshold: 1 });
|
||||
var press = new Hammer.Press({ time: pressPeriod, threshold: pressThreshold });
|
||||
|
||||
hammer.add(swipe);
|
||||
hammer.add(press);
|
||||
|
||||
swipe.recognizeWith(press);
|
||||
press.requireFailure(swipe);
|
||||
|
||||
pressCount = 0;
|
||||
swipeCount = 0;
|
||||
hammer.on('press', function() {
|
||||
pressCount++;
|
||||
});
|
||||
hammer.on('swipe', function() {
|
||||
swipeCount++;
|
||||
});
|
||||
},
|
||||
afterEach: function() {
|
||||
hammer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('When swipe does not recognize the gesture, a press gesture can be fired', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(pressCount, 1, '1 press recognized');
|
||||
done();
|
||||
}, pressPeriod + 100);
|
||||
});
|
||||
|
||||
QUnit.test('When swipe does recognize the gesture, a press gesture cannot be fired', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(2);
|
||||
|
||||
Simulator.gestures.swipe(el, null, function() {
|
||||
assert.ok(swipeCount > 0, 'swipe gesture should be recognizing');
|
||||
|
||||
assert.equal(pressCount, 0, 'press gesture should not be recognized because swipe gesture is recognizing');
|
||||
done();
|
||||
});
|
||||
});
|
||||
QUnit.module('Require Failure ( Pan & Press )', {
|
||||
beforeEach: function() {
|
||||
el = document.createElement('div');
|
||||
document.body.appendChild(el);
|
||||
|
||||
hammer = new Hammer(el, { recognizers: [] });
|
||||
|
||||
var pan = new Hammer.Pan({ threshold: 1 });
|
||||
var press = new Hammer.Press({ time: pressPeriod, threshold: pressThreshold });
|
||||
|
||||
hammer.add([ pan, press ]);
|
||||
|
||||
pan.recognizeWith(press);
|
||||
press.requireFailure(pan);
|
||||
|
||||
pressCount = 0;
|
||||
panStartCount = 0;
|
||||
hammer.on('press', function() {
|
||||
pressCount++;
|
||||
});
|
||||
hammer.on('panstart', function() {
|
||||
panStartCount++;
|
||||
});
|
||||
},
|
||||
afterEach: function() {
|
||||
document.body.removeChild(el);
|
||||
hammer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('When pan does not recognize the gesture, a press gesture can be fired', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(pressCount, 1, '1 press recognized');
|
||||
done();
|
||||
}, pressPeriod + 100);
|
||||
});
|
||||
|
||||
QUnit.test('When pan recognizes the gesture, a press gesture cannot be fired', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(2);
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 50, 50);
|
||||
utils.dispatchTouchEvent(el, 'move', 50 + pressThreshold / 4, 50);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.ok(panStartCount > 0, 'pan gesture should be recognizing');
|
||||
|
||||
assert.equal(pressCount, 0, 'press gesture should not be recognized because pan gesture is recognizing');
|
||||
done();
|
||||
}, pressPeriod + 100);
|
||||
});
|
238
node_modules/@egjs/hammerjs/tests/unit/test_simultaneous_recognition.js
generated
vendored
Normal file
238
node_modules/@egjs/hammerjs/tests/unit/test_simultaneous_recognition.js
generated
vendored
Normal file
@ -0,0 +1,238 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils*/
|
||||
|
||||
var el;
|
||||
var hammer;
|
||||
|
||||
QUnit.module('Simultaenous recognition', {
|
||||
beforeEach: function() {
|
||||
el = utils.createHitArea();
|
||||
},
|
||||
afterEach: function() {
|
||||
hammer && hammer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('should pinch and pan simultaneously be recognized when enabled', function(assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(4);
|
||||
|
||||
var panCount = 0;
|
||||
var pinchCount = 0;
|
||||
|
||||
hammer = new Hammer.Manager(el, {
|
||||
touchAction: 'none'
|
||||
});
|
||||
|
||||
hammer.add(new Hammer.Pan({ threshold: 5, pointers: 2 }));
|
||||
|
||||
var pinch = new Hammer.Pinch({ threshold: 0, pointers: 2 });
|
||||
hammer.add(pinch);
|
||||
pinch.recognizeWith(hammer.get('pan'));
|
||||
|
||||
hammer.on('panend', function() {
|
||||
panCount++;
|
||||
});
|
||||
hammer.on('pinchend', function() {
|
||||
pinchCount++;
|
||||
});
|
||||
|
||||
var executeGesture = function(cb) {
|
||||
var event, touches;
|
||||
|
||||
touches = [
|
||||
{ clientX: 0, clientY: 10, identifier: 0, target: el },
|
||||
{ clientX: 10, clientY: 10, identifier: 1, target: el }
|
||||
];
|
||||
|
||||
event = document.createEvent('Event');
|
||||
event.initEvent('touchstart', true, true);
|
||||
event.touches = touches;
|
||||
event.targetTouches = touches;
|
||||
event.changedTouches = touches;
|
||||
el.dispatchEvent(event);
|
||||
|
||||
setTimeout(function() {
|
||||
touches = [
|
||||
{ clientX: 10, clientY: 20, identifier: 0, target: el },
|
||||
{ clientX: 20, clientY: 20, identifier: 1, target: el }
|
||||
];
|
||||
|
||||
event = document.createEvent('Event');
|
||||
event.initEvent('touchmove', true, true);
|
||||
event.touches = touches;
|
||||
event.targetTouches = touches;
|
||||
event.changedTouches = touches;
|
||||
|
||||
el.dispatchEvent(event);
|
||||
}, 100);
|
||||
|
||||
setTimeout(function() {
|
||||
touches = [
|
||||
{ clientX: 20, clientY: 30, identifier: 0, target: el },
|
||||
{ clientX: 40, clientY: 30, identifier: 1, target: el }
|
||||
];
|
||||
|
||||
event = document.createEvent('Event');
|
||||
event.initEvent('touchmove', true, true);
|
||||
event.touches = touches;
|
||||
event.targetTouches = touches;
|
||||
event.changedTouches = touches;
|
||||
el.dispatchEvent(event);
|
||||
|
||||
event = document.createEvent('Event');
|
||||
event.initEvent('touchend', true, true);
|
||||
event.touches = touches;
|
||||
event.targetTouches = touches;
|
||||
event.changedTouches = touches;
|
||||
el.dispatchEvent(event);
|
||||
|
||||
cb();
|
||||
}, 200);
|
||||
};
|
||||
|
||||
// 2 gesture will be recognized
|
||||
executeGesture(function() {
|
||||
assert.equal(panCount, 1, '1 pan event recognized');
|
||||
assert.equal(pinchCount, 1, '1 pinch event recognized');
|
||||
|
||||
pinch.dropRecognizeWith(hammer.get('pan'));
|
||||
|
||||
// Only the pan gesture will be recognized
|
||||
executeGesture(function() {
|
||||
assert.equal(panCount, 2, '2 pan events recognized');
|
||||
assert.equal(pinchCount, 1, 'One pinch event recognized');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('the first gesture should block the following gestures (Tap & DoubleTap)', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var tapCount = 0;
|
||||
var doubleTapCount = 0;
|
||||
|
||||
hammer = new Hammer.Manager(el, {
|
||||
touchAction: 'none'
|
||||
});
|
||||
|
||||
var tap = new Hammer.Tap();
|
||||
var doubleTap = new Hammer.Tap({ event: 'doubletap', taps: 2 });
|
||||
|
||||
hammer.add(tap);
|
||||
hammer.add(doubleTap);
|
||||
|
||||
hammer.on('tap', function() {
|
||||
tapCount++;
|
||||
});
|
||||
hammer.on('doubletap', function() {
|
||||
doubleTapCount++;
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
|
||||
assert.equal(tapCount, 2, 'on a double tap gesture, the tap gesture is recognized twice');
|
||||
assert.equal(doubleTapCount, 0, 'double tap gesture is not recognized because the prior tap gesture does not recognize it simultaneously');
|
||||
|
||||
doubleTap.recognizeWith(hammer.get('tap'));
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
|
||||
assert.equal(tapCount, 4, '4 tap events recognized');
|
||||
assert.equal(doubleTapCount, 1, 'when the tap gesture is configured to work simultaneously, tap & doubleTap can be recognized simultaneously');
|
||||
});
|
||||
|
||||
QUnit.test('when disabled, the first gesture should not block gestures (Tap & DoubleTap )', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var tapCount = 0;
|
||||
var doubleTapCount = 0;
|
||||
|
||||
hammer = new Hammer.Manager(el, {
|
||||
touchAction: 'none'
|
||||
});
|
||||
|
||||
var tap = new Hammer.Tap();
|
||||
var doubleTap = new Hammer.Tap({ event: 'doubletap', taps: 2 });
|
||||
|
||||
hammer.add(tap);
|
||||
hammer.add(doubleTap);
|
||||
|
||||
hammer.on('tap', function() {
|
||||
tapCount++;
|
||||
});
|
||||
hammer.on('doubletap', function() {
|
||||
doubleTapCount++;
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
|
||||
assert.equal(tapCount, 2, 'on a double tap gesture, the tap gesture is recognized twice');
|
||||
assert.equal(doubleTapCount, 0, 'double tap gesture is not recognized because the prior tap gesture does not recognize it simultaneously');
|
||||
|
||||
hammer.get('tap').set({ enable: false });
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
|
||||
assert.equal(tapCount, 2, 'tap gesture should not be recognized when the recognizer is disabled');
|
||||
assert.equal(doubleTapCount, 1, 'when the tap gesture is disabled, doubleTap can be recognized');
|
||||
});
|
||||
|
||||
QUnit.test('the first gesture should block the following gestures (DoubleTap & Tap)', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var tapCount = 0;
|
||||
var doubleTapCount = 0;
|
||||
|
||||
hammer = new Hammer.Manager(el, {
|
||||
touchAction: 'none'
|
||||
});
|
||||
|
||||
var tap = new Hammer.Tap();
|
||||
var doubleTap = new Hammer.Tap({ event: 'doubletap', taps: 2 });
|
||||
|
||||
hammer.add(doubleTap);
|
||||
hammer.add(tap);
|
||||
|
||||
hammer.on('tap', function() {
|
||||
tapCount++;
|
||||
});
|
||||
hammer.on('doubletap', function() {
|
||||
doubleTapCount++;
|
||||
});
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
|
||||
assert.equal(doubleTapCount, 1, 'double tap is recognized');
|
||||
assert.equal(tapCount, 1, 'tap is detected, the doubletap is only catched by the doubletap recognizer');
|
||||
|
||||
// Doubletap and tap together
|
||||
doubleTap.recognizeWith(hammer.get('tap'));
|
||||
doubleTapCount = 0;
|
||||
tapCount = 0;
|
||||
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'start', 0, 10);
|
||||
utils.dispatchTouchEvent(el, 'end', 0, 10);
|
||||
|
||||
assert.equal(doubleTapCount, 1, '1 double tap recognized');
|
||||
assert.equal(tapCount, 2, 'when the tap gesture is configured to work simultaneously, tap & doubleTap can be recognized simultaneously');
|
||||
});
|
167
node_modules/@egjs/hammerjs/tests/unit/test_utils.js
generated
vendored
Normal file
167
node_modules/@egjs/hammerjs/tests/unit/test_utils.js
generated
vendored
Normal file
@ -0,0 +1,167 @@
|
||||
// jscs:disable requireArrowFunctions,disallowVar,requireEnhancedObjectLiterals
|
||||
/* globals QUnit,Hammer,utils,_*/
|
||||
|
||||
QUnit.module('utils');
|
||||
|
||||
// For the tests, all hammer properties and methods of Hammer are exposed to window.Hammer
|
||||
|
||||
QUnit.test('get/set prefixed util', function(assert) {
|
||||
assert.ok(_.isUndefined(Hammer.prefixed(window, 'FakeProperty')), 'non existent property returns undefined');
|
||||
|
||||
window.webkitFakeProperty = 1337;
|
||||
assert.ok(Hammer.prefixed(window, 'FakeProperty') == 'webkitFakeProperty', 'existent prefixed property returns the prefixed name');
|
||||
|
||||
delete window.webkitFakeProperty;
|
||||
});
|
||||
|
||||
QUnit.test('fnBind', function(assert) {
|
||||
var context = { a: true };
|
||||
|
||||
Hammer.bindFn(function(b) {
|
||||
assert.ok(this.a === true, 'bindFn scope');
|
||||
assert.ok(b === 123, 'bindFn argument');
|
||||
}, context)(123);
|
||||
});
|
||||
|
||||
QUnit.test('Inherit objects', function(assert) {
|
||||
function Base() {
|
||||
this.name = true;
|
||||
}
|
||||
|
||||
function Child() {
|
||||
Base.call(this);
|
||||
}
|
||||
|
||||
Hammer.inherit(Child, Base, {
|
||||
newMethod: function() {
|
||||
}
|
||||
});
|
||||
|
||||
var inst = new Child();
|
||||
|
||||
assert.ok(inst.name == true, 'child has extended from base');
|
||||
assert.ok(inst.newMethod, 'child has a new method');
|
||||
assert.ok(Child.prototype.newMethod, 'child has a new prototype method');
|
||||
assert.ok(inst instanceof Child, 'is instanceof Child');
|
||||
assert.ok(inst instanceof Base, 'is instanceof Base');
|
||||
assert.ok(inst._super === Base.prototype, '_super is ref to prototype of Base');
|
||||
});
|
||||
|
||||
QUnit.test('toArray', function(assert) {
|
||||
assert.ok(_.isArray(Hammer.toArray({ 0: true, 1: 'second', length: 2 })), 'converted an array-like object to an array');
|
||||
assert.ok(_.isArray(Hammer.toArray([ true, true ])), 'array stays an array');
|
||||
});
|
||||
|
||||
QUnit.test('inArray', function(assert) {
|
||||
assert.ok(Hammer.inArray([ 1, 2, 3, 4, 'hammer' ], 'hammer') === 4, 'found item and returned the index');
|
||||
assert.ok(Hammer.inArray([ 1, 2, 3, 4, 'hammer' ], 'notfound') === -1, 'not found an item and returned -1');
|
||||
assert.ok(Hammer.inArray([
|
||||
{ id: 2 },
|
||||
{ id: 24 }
|
||||
], '24', 'id') === 1, 'find by key and return the index');
|
||||
assert.ok(Hammer.inArray([
|
||||
{ id: 2 },
|
||||
{ id: 24 }
|
||||
], '22', 'id') === -1, 'not found by key and return -1');
|
||||
});
|
||||
|
||||
QUnit.test('splitStr', function(assert) {
|
||||
assert.deepEqual(Hammer.splitStr(' a b c d '), [ 'a', 'b', 'c', 'd' ], 'str split valid');
|
||||
});
|
||||
|
||||
QUnit.test('uniqueArray', function(assert) {
|
||||
assert.deepEqual(Hammer.uniqueArray([
|
||||
{ id: 1 },
|
||||
{ id: 2 },
|
||||
{ id: 2 }
|
||||
], 'id'), [
|
||||
{ id: 1 },
|
||||
{ id: 2 }
|
||||
], 'remove duplicate ids');
|
||||
});
|
||||
|
||||
QUnit.test('boolOrFn', function(assert) {
|
||||
assert.equal(Hammer.boolOrFn(true), true, 'Passing an boolean');
|
||||
assert.equal(Hammer.boolOrFn(false), false, 'Passing an boolean');
|
||||
assert.equal(Hammer.boolOrFn(function() {
|
||||
return true;
|
||||
}), true, 'Passing an boolean');
|
||||
assert.equal(Hammer.boolOrFn(1), true, 'Passing an integer');
|
||||
});
|
||||
|
||||
QUnit.test('hasParent', function(assert) {
|
||||
var parent = document.createElement('div');
|
||||
var child = document.createElement('div');
|
||||
|
||||
document.body.appendChild(parent);
|
||||
parent.appendChild(child);
|
||||
|
||||
assert.equal(Hammer.hasParent(child, parent), true, 'Found parent');
|
||||
assert.equal(Hammer.hasParent(parent, child), false, 'Not in parent');
|
||||
|
||||
document.body.removeChild(parent);
|
||||
});
|
||||
|
||||
QUnit.test('each', function(assert) {
|
||||
var object = { hi: true };
|
||||
var array = [ 'a', 'b', 'c' ];
|
||||
var loop;
|
||||
|
||||
loop = false;
|
||||
Hammer.each(object, function(value, key) {
|
||||
if (key == 'hi' && value === true) {
|
||||
loop = true;
|
||||
}
|
||||
});
|
||||
assert.ok(loop, 'object loop');
|
||||
|
||||
loop = 0;
|
||||
Hammer.each(array, function(value) {
|
||||
if (value) {
|
||||
loop++;
|
||||
}
|
||||
});
|
||||
assert.ok(loop == 3, 'array loop');
|
||||
|
||||
loop = 0;
|
||||
array.forEach = null;
|
||||
Hammer.each(array, function(value) {
|
||||
if (value) {
|
||||
loop++;
|
||||
}
|
||||
});
|
||||
assert.ok(loop == 3, 'array loop without Array.forEach');
|
||||
});
|
||||
|
||||
QUnit.test('assign', function(assert) {
|
||||
assert.expect(2);
|
||||
assert.deepEqual(
|
||||
Hammer.assign(
|
||||
{ a: 1, b: 3 },
|
||||
{ b: 2, c: 3 }
|
||||
),
|
||||
{ a: 1, b: 2, c: 3 },
|
||||
'Simple extend'
|
||||
);
|
||||
|
||||
var src = { foo: true };
|
||||
var dest = Hammer.assign({}, src);
|
||||
src.foo = false;
|
||||
assert.deepEqual(dest, { foo: true }, 'Clone reference');
|
||||
});
|
||||
|
||||
QUnit.test('test add/removeEventListener', function(assert) {
|
||||
function handleEvent() {
|
||||
assert.ok(true, 'triggered event');
|
||||
}
|
||||
|
||||
assert.expect(2);
|
||||
|
||||
Hammer.addEventListeners(window, 'testEvent1 testEvent2 ', handleEvent);
|
||||
utils.triggerDomEvent(window, 'testEvent1');
|
||||
utils.triggerDomEvent(window, 'testEvent2');
|
||||
|
||||
Hammer.removeEventListeners(window, ' testEvent1 testEvent2 ', handleEvent);
|
||||
utils.triggerDomEvent(window, 'testEvent1');
|
||||
utils.triggerDomEvent(window, 'testEvent2');
|
||||
});
|
Reference in New Issue
Block a user