From e658de47d1f0af0d4a729d97f5de72467ed7bb6d Mon Sep 17 00:00:00 2001 From: Nicolas ANGOT Date: Tue, 22 Aug 2017 15:35:18 +0200 Subject: [PATCH 1/3] add EventBus unit test --- test/unit/core.EventBus.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/unit/core.EventBus.js diff --git a/test/unit/core.EventBus.js b/test/unit/core.EventBus.js new file mode 100644 index 0000000000..bfa8b09170 --- /dev/null +++ b/test/unit/core.EventBus.js @@ -0,0 +1,30 @@ +import EventBus from '../../src/core/EventBus'; + +const chai = require('chai'); +const spies = require('chai-spies'); +const expect = chai.expect; + +chai.use(spies); + +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 = chai.spy(); + + eventBus.on('EVENT_TEST', spy); + + expect(eventBus.trigger.bind(eventBus, 'EVENT_TEST', { type:{}})).to.throw('\'type\' is a reserved word for event dispatching'); + }); + +}); From c1c38c7f5e19b97976389d9cc1f82dd4ac1b0339 Mon Sep 17 00:00:00 2001 From: Nicolas ANGOT Date: Tue, 22 Aug 2017 17:59:04 +0200 Subject: [PATCH 2/3] add a test on priority of events notification --- test/unit/core.EventBus.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/test/unit/core.EventBus.js b/test/unit/core.EventBus.js index bfa8b09170..1620f06c5a 100644 --- a/test/unit/core.EventBus.js +++ b/test/unit/core.EventBus.js @@ -1,10 +1,9 @@ import EventBus from '../../src/core/EventBus'; const chai = require('chai'); -const spies = require('chai-spies'); +const sinon = require('sinon'); const expect = chai.expect; - -chai.use(spies); +const assert = chai.assert; const context = {}; const eventBus = EventBus(context).getInstance(); @@ -20,11 +19,25 @@ describe('EventBus', function () { }); it("should throw an exception when attempting to trigger a 'type' payload parameter", function () { - const spy = chai.spy(); + 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); + }); }); From 4205e7ca20e59eaabc2c09ed77cf396fdfb83056 Mon Sep 17 00:00:00 2001 From: Nicolas ANGOT Date: Tue, 22 Aug 2017 17:59:53 +0200 Subject: [PATCH 3/3] small update on ScheduleController unit test : add some missing mocks --- test/unit/mocks/StreamProcessorMock.js | 2 +- ...streaming.controllers.ScheduleController.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/unit/mocks/StreamProcessorMock.js b/test/unit/mocks/StreamProcessorMock.js index 7eb1114a90..1877a0d42e 100644 --- a/test/unit/mocks/StreamProcessorMock.js +++ b/test/unit/mocks/StreamProcessorMock.js @@ -90,7 +90,7 @@ class StreamProcessorMock { } getCurrentRepresentationInfo() { - return {}; + return {mediaInfo: {type : this.type}}; } isBufferingCompleted() { diff --git a/test/unit/streaming.controllers.ScheduleController.js b/test/unit/streaming.controllers.ScheduleController.js index 3cab25b386..8694acd355 100644 --- a/test/unit/streaming.controllers.ScheduleController.js +++ b/test/unit/streaming.controllers.ScheduleController.js @@ -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 = {}; @@ -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();