playable
Version:
Video player based on HTML5Video
96 lines • 4.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
require("jsdom-global/register");
var chai_1 = require("chai");
var sinon = (0, tslib_1.__importStar)(require("sinon"));
var testkit_1 = (0, tslib_1.__importDefault)(require("../../../../testkit"));
var volume_1 = (0, tslib_1.__importDefault)(require("./volume"));
var constants_1 = require("../../../../constants");
describe('VolumeControl', function () {
var testkit;
var control;
var eventEmitter;
beforeEach(function () {
testkit = (0, testkit_1.default)();
testkit.registerModule('volumeControl', volume_1.default);
control = testkit.getModule('volumeControl');
eventEmitter = testkit.getModule('eventEmitter');
});
describe('constructor', function () {
it('should create instance ', function () {
(0, chai_1.expect)(control).to.exist;
(0, chai_1.expect)(control.view).to.exist;
});
});
describe('API', function () {
it('should have method for setting current volume', function () {
var spy = sinon.spy(control.view, 'setVolume');
control._setVolumeLevel(0);
(0, chai_1.expect)(spy.called).to.be.true;
});
it('should have method for setting mute state', function () {
var spy = sinon.spy(control.view, 'setMute');
control._setMuteState();
(0, chai_1.expect)(spy.called).to.be.true;
});
it('should have method for showing whole view', function () {
(0, chai_1.expect)(control.show).to.exist;
control.show();
(0, chai_1.expect)(control.isHidden).to.be.false;
});
it('should have method for hiding whole view', function () {
(0, chai_1.expect)(control.hide).to.exist;
control.hide();
(0, chai_1.expect)(control.isHidden).to.be.true;
});
it('should have method for destroying', function () {
var spy = sinon.spy(control, '_unbindEvents');
(0, chai_1.expect)(control.destroy).to.exist;
control.destroy();
(0, chai_1.expect)(spy.called).to.be.true;
});
});
describe('video events listeners', function () {
it('should call callback on playback state change', function () {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var spy;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
spy = sinon.spy(control, '_updateSoundState');
control._bindEvents();
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.SOUND_STATE_CHANGED)];
case 1:
_a.sent();
(0, chai_1.expect)(spy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
});
describe('internal methods', function () {
it('should change volume level based on wheel delta', function () {
var startSpy = sinon.spy(control, '_changeVolumeLevel');
control._getVolumeLevelFromWheel(-100);
(0, chai_1.expect)(startSpy.calledWith(90)).to.be.true;
});
it('should change volume level based on input', function () {
var startSpy = sinon.spy(control, '_changeVolumeLevel');
control._getVolumeLevelFromInput(40);
(0, chai_1.expect)(startSpy.calledWith(40)).to.be.true;
});
it('should change volume level and mute state of video', function () {
var volumeSpy = sinon.spy(control, '_changeVolumeLevel');
var muteSpy = sinon.spy(control, '_toggleMuteState');
control._changeVolumeLevel(90);
(0, chai_1.expect)(volumeSpy.calledWith(90)).to.be.true;
(0, chai_1.expect)(muteSpy.called).to.be.false;
control._engine.mute();
control._changeVolumeLevel(90);
(0, chai_1.expect)(muteSpy.called).to.be.true;
});
});
});
//# sourceMappingURL=volume.spec.js.map