playable
Version:
Video player based on HTML5Video
98 lines • 5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var chai_1 = require("chai");
var sinon = (0, tslib_1.__importStar)(require("sinon"));
var event_emitter_1 = (0, tslib_1.__importDefault)(require("../../../../modules/event-emitter/event-emitter"));
var constants_1 = require("../../../../constants");
var native_events_broadcaster_1 = (0, tslib_1.__importStar)(require("./native-events-broadcaster"));
var NATIVE_EVENTS = {
ERROR: { type: 'error' },
STALLED: { type: 'stalled' },
PROGRESS: { type: 'progress' },
SEEKING: { type: 'seeking' },
SUSPEND: { type: 'suspend' },
DURATION_CHANGE: { type: 'durationchange' },
TIME_UPDATE: { type: 'timeupdate' },
VOLUME_CHANGE: { type: 'volumechange' },
};
describe('NativeEventsBroadcaster', function () {
var video;
var broadcaster;
var eventEmitter;
beforeEach(function () {
video = {
addEventListener: sinon.spy(),
removeEventListener: sinon.spy(),
tagName: 'VIDEO',
};
eventEmitter = new event_emitter_1.default();
sinon.spy(eventEmitter, 'emitAsync');
broadcaster = new native_events_broadcaster_1.default(eventEmitter, video);
});
afterEach(function () {
eventEmitter.emitAsync.restore();
});
it('should attach events to video tag on initialization', function () {
(0, chai_1.expect)(video.addEventListener.args.length).to.be.equal(native_events_broadcaster_1.NATIVE_VIDEO_TO_BROADCAST.length);
video.addEventListener.args.forEach(function (arg) {
(0, chai_1.expect)(native_events_broadcaster_1.NATIVE_VIDEO_TO_BROADCAST.indexOf(arg[0]) !== -1).to.be.true;
(0, chai_1.expect)(arg[1] === broadcaster._processEventFromVideo).to.be.true;
});
});
it('should detach events from video tag on destroy', function () {
broadcaster.destroy();
(0, chai_1.expect)(video.removeEventListener.args.length).to.be.equal(native_events_broadcaster_1.NATIVE_VIDEO_TO_BROADCAST.length);
video.removeEventListener.args.forEach(function (arg) {
(0, chai_1.expect)(native_events_broadcaster_1.NATIVE_VIDEO_TO_BROADCAST.indexOf(arg[0]) !== -1).to.be.true;
(0, chai_1.expect)(arg[1] === broadcaster._processEventFromVideo).to.be.true;
});
});
it('should broadcast progress event', function () {
broadcaster._processEventFromVideo(NATIVE_EVENTS.PROGRESS);
(0, chai_1.expect)(eventEmitter.emitAsync.calledWith(constants_1.VideoEvent.CHUNK_LOADED)).to.be
.true;
});
it('should broadcast stalled event', function () {
broadcaster._processEventFromVideo(NATIVE_EVENTS.STALLED);
(0, chai_1.expect)(eventEmitter.emitAsync.calledWith(constants_1.VideoEvent.UPLOAD_STALLED)).to.be
.true;
});
it('should broadcast suspend event', function () {
broadcaster._processEventFromVideo(NATIVE_EVENTS.SUSPEND);
(0, chai_1.expect)(eventEmitter.emitAsync.calledWith(constants_1.VideoEvent.UPLOAD_SUSPEND)).to.be
.true;
});
it('should broadcast seeking event', function () {
video.currentTime = 100;
broadcaster._processEventFromVideo(NATIVE_EVENTS.SEEKING);
(0, chai_1.expect)(eventEmitter.emitAsync.calledWith(constants_1.VideoEvent.SEEK_IN_PROGRESS, 100))
.to.be.true;
});
it('should broadcast durationchange event', function () {
video.duration = 'Test duration';
broadcaster._processEventFromVideo(NATIVE_EVENTS.DURATION_CHANGE);
(0, chai_1.expect)(eventEmitter.emitAsync.calledWith(constants_1.VideoEvent.DURATION_UPDATED, video.duration)).to.be.true;
});
it('should broadcast timeupdate event', function () {
video.currentTime = 'Test currentTime';
broadcaster._processEventFromVideo(NATIVE_EVENTS.TIME_UPDATE);
(0, chai_1.expect)(eventEmitter.emitAsync.calledWith(constants_1.VideoEvent.CURRENT_TIME_UPDATED, video.currentTime)).to.be.true;
});
it('should broadcast volume change event', function () {
video.volume = 0.2;
video.muted = true;
broadcaster._processEventFromVideo(NATIVE_EVENTS.VOLUME_CHANGE);
(0, chai_1.expect)(eventEmitter.emitAsync.calledWith(constants_1.VideoEvent.SOUND_STATE_CHANGED, {
volume: video.volume,
muted: video.muted,
})).to.be.true;
(0, chai_1.expect)(eventEmitter.emitAsync.calledWith(constants_1.VideoEvent.VOLUME_CHANGED, video.volume * 100)).to.be.true;
(0, chai_1.expect)(eventEmitter.emitAsync.calledWith(constants_1.VideoEvent.MUTE_CHANGED, video.muted)).to.be.true;
});
it('should do nothing if event is not in list', function () {
broadcaster._processEventFromVideo();
(0, chai_1.expect)(eventEmitter.emitAsync.called).to.be.false;
});
});
//# sourceMappingURL=native-events-broadcaster.spec.js.map