playable
Version:
Video player based on HTML5Video
395 lines • 20.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
require("jsdom-global/register");
var chai_1 = require("chai");
var interaction_type_1 = (0, tslib_1.__importDefault)(require("./interaction-type"));
describe('engageInteractionTypeObserver', function () {
var keydownEvent = new Event('keydown');
var keyupEvent = new Event('keyup');
var touchstartEvent = new Event('touchstart');
var pointerdownEvent = new Event('pointerdown');
var MSPointerDowntEvent = new Event('MSPointerDown');
var mousedownEvent = new Event('mousedown');
var touchendEvent = new Event('touchend');
var touchcancelEvent = new Event('touchcancel');
var pointerupEvent = new Event('pointerup');
var MSPointerUpEvent = new Event('MSPointerUp');
var pointercancelEvent = new Event('pointercancel');
var MSPointerCancelEvent = new Event('MSPointerCancel');
var mouseupEvent = new Event('mouseup');
var blurEvent = new Event('blur');
var get;
describe('get function', function () {
describe('for key', function () {
it('should return false', function () {
get = interaction_type_1.default.engage().get;
(0, chai_1.expect)(get().key).to.be.equal(false);
interaction_type_1.default.disengage();
});
describe('after key down event', function () {
beforeEach(function () {
get = interaction_type_1.default.engage().get;
});
afterEach(function () {
delete keydownEvent.keyCode;
interaction_type_1.default.disengage();
});
it('should return true', function () {
document.documentElement.dispatchEvent(keydownEvent);
(0, chai_1.expect)(get().key).to.be.equal(true);
});
it('should return false if keyCode 16', function () {
keydownEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
(0, chai_1.expect)(get().key).to.be.equal(false);
});
it('should return false if keyCode 17', function () {
keydownEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
(0, chai_1.expect)(get().key).to.be.equal(false);
});
it('should return false if keyCode 18', function () {
keydownEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
(0, chai_1.expect)(get().key).to.be.equal(false);
});
it('should return false if keyCode 91', function () {
keydownEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
(0, chai_1.expect)(get().key).to.be.equal(false);
});
it('should return false if keyCode 93', function () {
keydownEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
(0, chai_1.expect)(get().key).to.be.equal(false);
});
});
describe('after key up event', function () {
beforeEach(function () {
get = interaction_type_1.default.engage().get;
});
afterEach(function () {
delete keyupEvent.keyCode;
interaction_type_1.default.disengage();
});
it('should return false', function (done) {
document.documentElement.dispatchEvent(keydownEvent);
document.documentElement.dispatchEvent(keyupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().key).to.be.equal(false);
done();
}, 2);
});
it('should return true if keyCode 16', function (done) {
keyupEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
document.documentElement.dispatchEvent(keyupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().key).to.be.equal(true);
done();
}, 2);
});
it('should return true if keyCode 17', function (done) {
keyupEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
document.documentElement.dispatchEvent(keyupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().key).to.be.equal(true);
done();
}, 2);
});
it('should return true if keyCode 18', function (done) {
keyupEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
document.documentElement.dispatchEvent(keyupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().key).to.be.equal(true);
done();
}, 2);
});
it('should return true if keyCode 91', function (done) {
keyupEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
document.documentElement.dispatchEvent(keyupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().key).to.be.equal(true);
done();
}, 2);
});
it('should return true if keyCode 93', function (done) {
keyupEvent.keyCode = 16;
document.documentElement.dispatchEvent(keydownEvent);
document.documentElement.dispatchEvent(keyupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().key).to.be.equal(true);
done();
}, 2);
});
});
});
describe('for pointer', function () {
beforeEach(function () {
get = interaction_type_1.default.engage().get;
});
afterEach(function () {
delete keydownEvent.keyCode;
interaction_type_1.default.disengage();
});
it('should return false', function () {
(0, chai_1.expect)(get().pointer).to.be.equal(false);
});
it('should return true after touchstartEvent', function () {
document.documentElement.dispatchEvent(touchstartEvent);
(0, chai_1.expect)(get().pointer).to.be.equal(true);
});
it('should return false after touchstartEvent if not isPrimary', function () {
touchstartEvent.isPrimary = false;
document.documentElement.dispatchEvent(touchstartEvent);
(0, chai_1.expect)(get().pointer).to.be.equal(false);
delete touchstartEvent.isPrimary;
});
it('should return true after pointerdownEvent', function () {
document.documentElement.dispatchEvent(pointerdownEvent);
(0, chai_1.expect)(get().pointer).to.be.equal(true);
});
it('should return false after pointerdownEvent if not isPrimary', function () {
pointerdownEvent.isPrimary = false;
document.documentElement.dispatchEvent(pointerdownEvent);
(0, chai_1.expect)(get().pointer).to.be.equal(false);
delete pointerdownEvent.isPrimary;
});
it('should return true after MSPointerDowntEvent', function () {
document.documentElement.dispatchEvent(MSPointerDowntEvent);
(0, chai_1.expect)(get().pointer).to.be.equal(true);
});
it('should return false after MSPointerDowntEvent if not isPrimary', function () {
MSPointerDowntEvent.isPrimary = false;
document.documentElement.dispatchEvent(MSPointerDowntEvent);
(0, chai_1.expect)(get().pointer).to.be.equal(false);
delete MSPointerDowntEvent.isPrimary;
});
it('should return true after mousedownEvent', function () {
document.documentElement.dispatchEvent(mousedownEvent);
(0, chai_1.expect)(get().pointer).to.be.equal(true);
});
it('should return false after mousedownEvent if not isPrimary', function () {
mousedownEvent.isPrimary = false;
document.documentElement.dispatchEvent(mousedownEvent);
(0, chai_1.expect)(get().pointer).to.be.equal(false);
delete mousedownEvent.isPrimary;
});
it('should return false after touchend', function (done) {
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(touchendEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(false);
done();
}, 2);
});
it('should return true after touchend if there is still touches', function (done) {
touchendEvent.touches = [1];
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(touchendEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete touchendEvent.touches;
});
it('should return true after touchend if it not isPrimary', function (done) {
touchendEvent.isPrimary = false;
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(touchendEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete touchendEvent.isPrimary;
});
it('should return false after touchcancel', function (done) {
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(touchcancelEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(false);
done();
}, 2);
});
it('should return true after touchcancel if there is still touches', function (done) {
touchcancelEvent.touches = [1];
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(touchcancelEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete touchcancelEvent.touches;
});
it('should return true after touchcancel if it not isPrimary', function (done) {
touchcancelEvent.isPrimary = false;
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(touchcancelEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete touchcancelEvent.isPrimary;
});
it('should return false after MSPointerUpEvent', function (done) {
document.documentElement.dispatchEvent(MSPointerDowntEvent);
document.documentElement.dispatchEvent(MSPointerUpEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(false);
done();
}, 2);
});
it('should return true after MSPointerUpEvent if there is still touches', function (done) {
MSPointerUpEvent.touches = [1];
document.documentElement.dispatchEvent(MSPointerDowntEvent);
document.documentElement.dispatchEvent(MSPointerUpEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete MSPointerUpEvent.touches;
});
it('should return true after MSPointerUpEvent if it not isPrimary', function (done) {
MSPointerUpEvent.isPrimary = false;
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(MSPointerUpEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete MSPointerUpEvent.isPrimary;
});
it('should return false after MSPointerCancelEvent', function (done) {
document.documentElement.dispatchEvent(MSPointerDowntEvent);
document.documentElement.dispatchEvent(MSPointerCancelEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(false);
done();
}, 2);
});
it('should return true after MSPointerCancelEvent if there is still touches', function (done) {
MSPointerCancelEvent.touches = [1];
document.documentElement.dispatchEvent(MSPointerDowntEvent);
document.documentElement.dispatchEvent(MSPointerCancelEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete MSPointerCancelEvent.touches;
});
it('should return true after MSPointerCancelEvent if it not isPrimary', function (done) {
MSPointerCancelEvent.isPrimary = false;
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(MSPointerCancelEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete MSPointerCancelEvent.isPrimary;
});
it('should return false after pointerupEvent', function (done) {
document.documentElement.dispatchEvent(pointerdownEvent);
document.documentElement.dispatchEvent(pointerupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(false);
done();
}, 2);
});
it('should return true after pointerupEvent if there is still touches', function (done) {
pointerupEvent.touches = [1];
document.documentElement.dispatchEvent(pointerdownEvent);
document.documentElement.dispatchEvent(pointerupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete pointerupEvent.touches;
});
it('should return true after pointerupEvent if it not isPrimary', function (done) {
pointerupEvent.isPrimary = false;
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(pointerupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete pointerupEvent.isPrimary;
});
it('should return false after pointercancelEvent', function (done) {
document.documentElement.dispatchEvent(pointerdownEvent);
document.documentElement.dispatchEvent(pointercancelEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(false);
done();
}, 2);
});
it('should return true after pointercancelEvent if there is still touches', function (done) {
pointercancelEvent.touches = [1];
document.documentElement.dispatchEvent(pointerdownEvent);
document.documentElement.dispatchEvent(pointercancelEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete pointercancelEvent.touches;
});
it('should return true after pointercancelEvent if it not isPrimary', function (done) {
pointercancelEvent.isPrimary = false;
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(pointercancelEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete pointercancelEvent.isPrimary;
});
it('should return false after mouseup', function (done) {
document.documentElement.dispatchEvent(mousedownEvent);
document.documentElement.dispatchEvent(mouseupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(false);
done();
}, 2);
});
it('should return true after mouseup if there is still touches', function (done) {
mouseupEvent.touches = [1];
document.documentElement.dispatchEvent(mousedownEvent);
document.documentElement.dispatchEvent(mouseupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete mouseupEvent.touches;
});
it('should return true after mouseupEvent if it not isPrimary', function (done) {
mouseupEvent.isPrimary = false;
document.documentElement.dispatchEvent(touchstartEvent);
document.documentElement.dispatchEvent(mouseupEvent);
setTimeout(function () {
(0, chai_1.expect)(get().pointer).to.be.equal(true);
done();
}, 2);
delete mouseupEvent.isPrimary;
});
});
it('should return both key and pointer as false after blur event on window', function (done) {
get = interaction_type_1.default.engage().get;
document.documentElement.dispatchEvent(keydownEvent);
document.documentElement.dispatchEvent(touchstartEvent);
window.dispatchEvent(blurEvent);
setTimeout(function () {
(0, chai_1.expect)(get()).to.be.deep.equal({
key: false,
pointer: false,
});
done();
}, 2);
interaction_type_1.default.disengage();
});
});
});
//# sourceMappingURL=interaction-type.spec.js.map