Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Neil committed Feb 26, 2018
1 parent d3c62b0 commit 61b4d77
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/sync-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,58 @@ QUnit.test('returns correct sync point for ProgramDateTime strategy', function(a
}, 'syncpoint found for ProgramDateTime set');
});

QUnit.test('ProgramDateTime strategy finds nearest segment for sync', function(assert) {
let strategy = getStrategy('ProgramDateTime');
let playlist = playlistWithDuration(40);
let timeline = 0;
let duration = Infinity;
let syncPoint;

syncPoint = strategy.run(this.syncController, playlist, duration, timeline, 23);

assert.equal(syncPoint, null, 'no syncpoint when datetimeToDisplayTime not set');

playlist.segments.forEach((segment, index) => {
segment.dateTimeObject = new Date(2012, 11, 12, 12, 12, 12 + (index * 10));
});

this.syncController.setDateTimeMapping(playlist);

let newPlaylist = playlistWithDuration(40);

syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline);

assert.equal(syncPoint, null, 'no syncpoint when datetimeObject not set on playlist');

newPlaylist.segments.forEach((segment, index) => {
segment.dateTimeObject = new Date(2012, 11, 12, 12, 12, 22 + (index * 10));
});

syncPoint = strategy.run(this.syncController, newPlaylist, duration, timeline, 23);

assert.deepEqual(syncPoint, {
time: 20,
segmentIndex: 1
}, 'syncpoint found for ProgramDateTime set');
});

QUnit.test('Does not set date time mapping if date time info not on first segment',
function(assert) {
let playlist = playlistWithDuration(40);

playlist.segments[1].dateTimeObject = new Date(2012, 11, 12, 12, 12, 12);

this.syncController.setDateTimeMapping(playlist);

assert.notOk(this.syncController.datetimeToDisplayTime, 'did not set datetime mapping');

playlist.segments[0].dateTimeObject = new Date(2012, 11, 12, 12, 12, 2);

this.syncController.setDateTimeMapping(playlist);

assert.ok(this.syncController.datetimeToDisplayTime, 'did set date time mapping');
});

QUnit.test('returns correct sync point for Segment strategy', function(assert) {
let strategy = getStrategy('Segment');
let playlist = {
Expand Down

0 comments on commit 61b4d77

Please sign in to comment.