playable
Version:
Video player based on HTML5Video
129 lines • 5.96 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 constants_1 = require("../../../../constants");
var time_1 = require("./time");
describe('TimeControl', function () {
var testkit;
var control;
var eventEmitter;
beforeEach(function () {
testkit = (0, testkit_1.default)();
eventEmitter = testkit.getModule('eventEmitter');
control = testkit.getModule('timeControl');
});
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 time', function () {
var spy = sinon.spy(control.view, 'setCurrentTime');
control._setCurrentTime();
(0, chai_1.expect)(spy.called).to.be.true;
});
it('should have method for setting duration time', function () {
var spy = sinon.spy(control.view, 'setDurationTime');
control._setDurationTime();
(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, '_toggleIntervalUpdates');
control._bindEvents();
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {})];
case 1:
_a.sent();
(0, chai_1.expect)(spy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
it('should call callback on seek', 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, '_startIntervalUpdates');
control._bindEvents();
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {
nextState: constants_1.EngineState.SEEK_IN_PROGRESS,
})];
case 1:
_a.sent();
(0, chai_1.expect)(spy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
it('should call callback on duration update', 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, '_updateDurationTime');
control._bindEvents();
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.DURATION_UPDATED)];
case 1:
_a.sent();
(0, chai_1.expect)(spy.called).to.be.true;
return [2 /*return*/];
}
});
});
});
});
describe('internal methods', function () {
it('should toggle interval updates', function () {
var startSpy = sinon.spy(control, '_startIntervalUpdates');
control._toggleIntervalUpdates({ nextState: constants_1.EngineState.PLAYING });
(0, chai_1.expect)(startSpy.called).to.be.true;
var stopSpy = sinon.spy(control, '_stopIntervalUpdates');
control._toggleIntervalUpdates({ nextState: constants_1.EngineState.PAUSED });
(0, chai_1.expect)(stopSpy.called).to.be.true;
});
it('should start interval updates', function () {
var spy = sinon.spy(window, 'setInterval');
var stopSpy = sinon.spy(control, '_stopIntervalUpdates');
control._startIntervalUpdates();
(0, chai_1.expect)(spy.calledWith(control._updateCurrentTime, time_1.UPDATE_TIME_INTERVAL_DELAY)).to.be.true;
(0, chai_1.expect)(stopSpy.called).to.be.false;
control._startIntervalUpdates();
(0, chai_1.expect)(stopSpy.called).to.be.true;
spy.restore();
});
});
});
//# sourceMappingURL=time.spec.js.map