Skip to content

Commit

Permalink
Merge pull request #2141 from Orange-OpenSource/AddEventBusUnitTest
Browse files Browse the repository at this point in the history
add EventBus unit test
  • Loading branch information
Dan Sparacio committed Aug 22, 2017
2 parents 66d6492 + 4205e7c commit 7214d62
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
43 changes: 43 additions & 0 deletions test/unit/core.EventBus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import EventBus from '../../src/core/EventBus';

const chai = require('chai');
const sinon = require('sinon');
const expect = chai.expect;
const assert = chai.assert;

const context = {};
const eventBus = EventBus(context).getInstance();

describe('EventBus', function () {

it("should throw an exception when attempting to register the on callback with an undefined type", function () {
expect(eventBus.on.bind(eventBus)).to.throw('event type cannot be null or undefined');
});

it("should throw an exception when attempting to register the on callback with an undefined listener", function () {
expect(eventBus.on.bind(eventBus, 'EVENT_TEST')).to.throw('listener must be a function: undefined');
});

it("should throw an exception when attempting to trigger a 'type' payload parameter", function () {
const spy = sinon.spy();

eventBus.on('EVENT_TEST', spy);

expect(eventBus.trigger.bind(eventBus, 'EVENT_TEST', { type:{}})).to.throw('\'type\' is a reserved word for event dispatching');
});

it("should respect priority parameter in order to notify the different listeners", function () {
const spy = sinon.spy();
const spy2 = sinon.spy();

eventBus.on('EVENT_TEST', spy);
eventBus.on('EVENT_TEST', spy2, this, EventBus.EVENT_PRIORITY_HIGH);

eventBus.trigger('EVENT_TEST', {});

assert.equal(spy.calledOnce, true);
assert.equal(spy2.calledOnce, true);
assert.equal(spy2.calledBefore(spy), true);
});

});
2 changes: 1 addition & 1 deletion test/unit/mocks/StreamProcessorMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class StreamProcessorMock {
}

getCurrentRepresentationInfo() {
return {};
return {mediaInfo: {type : this.type}};
}

isBufferingCompleted() {
Expand Down
18 changes: 17 additions & 1 deletion test/unit/streaming.controllers.ScheduleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import PlaybackControllerMock from './mocks/PlaybackControllerMock';
import StreamProcessorMock from './mocks/StreamProcessorMock';
import MediaPlayerModelMock from './mocks/MediaPlayerModelMock';
import DashManifestModelMock from './mocks/DashManifestModelMock';
import AbrControllerMock from './mocks/AbrControllerMock';
import StreamControllerMock from './mocks/StreamControllerMock';
import DashMetricsMock from './mocks/DashMetricsMock';
import MetricsModelMock from './mocks/MetricsModelMock';

const expect = require('chai').expect;
const context = {};
Expand All @@ -24,19 +28,31 @@ describe('ScheduleController', function () {
let streamProcessorMock;
let dashManifestModelMock;
let playbackControllerMock;
let abrControllerMock;
let streamControllerMock;
let dashMetricsMock;
let metricsModelMock;

beforeEach(function () {
mediaPlayerModelMock = new MediaPlayerModelMock();
streamProcessorMock = new StreamProcessorMock(testType, streamInfo);
dashManifestModelMock = new DashManifestModelMock();
playbackControllerMock = new PlaybackControllerMock();
abrControllerMock = new AbrControllerMock();
streamControllerMock = new StreamControllerMock();
dashMetricsMock = new DashMetricsMock();
metricsModelMock = new MetricsModelMock();

scheduleController = ScheduleController(context).create({
type: testType,
mediaPlayerModel: mediaPlayerModelMock,
streamProcessor: streamProcessorMock,
dashManifestModel: dashManifestModelMock,
playbackController: playbackControllerMock
playbackController: playbackControllerMock,
abrController: abrControllerMock,
streamController: streamControllerMock,
dashMetrics: dashMetricsMock,
metricsModel: metricsModelMock
});

scheduleController.initialize();
Expand Down

0 comments on commit 7214d62

Please sign in to comment.