playable
Version:
Video player based on HTML5Video
146 lines • 8.09 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 anomaly_bloodhound_1 = (0, tslib_1.__importStar)(require("./anomaly-bloodhound"));
var constants_1 = require("../../constants");
describe('AnomalyBloodhound', function () {
var testkit;
var anomalyBloodhound;
var eventEmitter;
var engine;
var callback = sinon.spy();
beforeEach(function () {
testkit = (0, testkit_1.default)();
eventEmitter = testkit.getModule('eventEmitter');
engine = testkit.getModule('engine');
testkit.registerModule(anomaly_bloodhound_1.default.moduleName, anomaly_bloodhound_1.default);
anomalyBloodhound = testkit.getModule('anomalyBloodhound');
anomalyBloodhound.setAnomalyCallback(callback);
});
afterEach(function () {
callback.resetHistory();
});
describe('reaction on changed state', function () {
it('should be based on event', 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(anomalyBloodhound, '_processStateChange');
anomalyBloodhound._bindEvents();
return [4 /*yield*/, eventEmitter.emitAsync(constants_1.VideoEvent.STATE_CHANGED, {})];
case 1:
_a.sent();
(0, chai_1.expect)(spy.called).to.be.true;
anomalyBloodhound._processStateChange.restore();
return [2 /*return*/];
}
});
});
});
describe('for LOAD_STARTED', function () {
it('should not schedule report if preload is not available and autoPlay is false', function () {
engine.setPreload('none');
engine.setAutoplay(false);
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.LOAD_STARTED,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.METADATA_LOADING)).to.be.false;
});
it('should not schedule report if preload is autoPlay is true', function () {
engine.setAutoplay(true);
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.LOAD_STARTED,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.METADATA_LOADING)).to.be.true;
});
it('should schedule report if preload available as metadata', function () {
engine.setPreload('metadata');
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.LOAD_STARTED,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.METADATA_LOADING)).to.be.true;
});
it('should schedule report if preload available as auto', function () {
engine.setPreload('metadata');
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.LOAD_STARTED,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.METADATA_LOADING)).to.be.true;
});
});
it('should start delayed report on METADATA_LOADED', function () {
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.LOAD_STARTED,
});
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.METADATA_LOADED,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.METADATA_LOADING)).to.be.false;
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.INITIAL_VIDEO_PARTS_LOADING)).to.be.true;
anomalyBloodhound.stopAllDelayedReports();
engine.setPreload('metadata');
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.METADATA_LOADED,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.INITIAL_VIDEO_PARTS_LOADING)).to.be.false;
});
it('should start delayed report on SEEK_IN_PROGRESS', function () {
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.SEEK_IN_PROGRESS,
prevState: constants_1.EngineState.PAUSED,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.RUNTIME_LOADING)).to.be.true;
});
it('should clear delayed report on READY_TO_PLAY', function () {
anomalyBloodhound.startDelayedReport(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.INITIAL_VIDEO_PARTS_LOADING);
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.READY_TO_PLAY,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.INITIAL_VIDEO_PARTS_LOADING)).to.be.false;
anomalyBloodhound.startDelayedReport(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.RUNTIME_LOADING);
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.READY_TO_PLAY,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.RUNTIME_LOADING)).to.be.false;
});
it('should clear delayed report on PLAYING', function () {
anomalyBloodhound.startDelayedReport(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.RUNTIME_LOADING);
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.PLAYING,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.RUNTIME_LOADING)).to.be.false;
});
it('should start delayed report on WAITING', function () {
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.WAITING,
prevState: constants_1.EngineState.PLAY_REQUESTED,
});
(0, chai_1.expect)(anomalyBloodhound.isDelayedReportExist(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.RUNTIME_LOADING)).to.be.true;
anomalyBloodhound.stopAllDelayedReports();
anomalyBloodhound._processStateChange({
nextState: constants_1.EngineState.WAITING,
prevState: constants_1.EngineState.PLAYING,
});
(0, chai_1.expect)(callback.called).to.be.true;
});
it('delayed report should be resolved', function (done) {
anomaly_bloodhound_1.DELAYED_REPORT_TYPES.___test = {
id: '___test',
timeout: 5,
};
window.setTimeout(function () {
(0, chai_1.expect)(callback.calledOnce).to.be.true;
done();
}, 10);
anomalyBloodhound.startDelayedReport(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.___test);
anomalyBloodhound.startDelayedReport(anomaly_bloodhound_1.DELAYED_REPORT_TYPES.___test);
}, 100);
});
});
//# sourceMappingURL=anomaly-bloodhound.spec.js.map