Skip to content

Commit

Permalink
@brandonocasey updated text track unit tests to use full es6 syntax. c…
Browse files Browse the repository at this point in the history
…loses #3148
  • Loading branch information
brandonocasey authored and gkatsev committed Mar 7, 2016
1 parent f77bcc9 commit c1112b7
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 323 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
* @gkatsev updated videojs badges in the README ([view](https://github.com/videojs/video.js/pull/3134))
* @BrandonOCasey converted remaining text-track modules to ES6 ([view](https://github.com/videojs/video.js/pull/3130))
* @gkatsev cleared waiting/spinner on timeupdate. Fixes #3124 ([view](https://github.com/videojs/video.js/pull/3138))
* @BrandonOCasey updated text track unit tests to use full es6 syntax ([view](https://github.com/videojs/video.js/pull/3148))

--------------------

Expand Down
25 changes: 12 additions & 13 deletions test/unit/tracks/html-track-element-list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@ import HTMLTrackElement from '../../../src/js/tracks/html-track-element.js';
import HTMLTrackElementList from '../../../src/js/tracks/html-track-element-list.js';
import TextTrack from '../../../src/js/tracks/text-track.js';

let noop = Function.prototype;
let defaultTech = {
textTracks: noop,
on: noop,
off: noop,
currentTime: noop
const defaultTech = {
textTracks() {},
on() {},
off() {},
currentTime() {}
};

let track1 = new TextTrack({
const track1 = new TextTrack({
id: 1,
tech: defaultTech
});
let track2 = new TextTrack({
const track2 = new TextTrack({
id: 2,
tech: defaultTech
});

var genericHtmlTrackElements = [{
const genericHtmlTrackElements = [{
tech() {},
kind: 'captions',
tech: noop,
track: track1
}, {
tech() {},
kind: 'chapters',
tech: noop,
track: track2
}];

Expand All @@ -47,9 +46,9 @@ test('can get html track element by track', function() {
test('length is updated when new tracks are added or removed', function() {
let htmlTrackElementList = new HTMLTrackElementList(genericHtmlTrackElements);

htmlTrackElementList.addTrackElement_({tech: noop});
htmlTrackElementList.addTrackElement_({tech() {}});
equal(htmlTrackElementList.length, genericHtmlTrackElements.length + 1, `the length is ${genericHtmlTrackElements.length + 1}`);
htmlTrackElementList.addTrackElement_({tech: noop});
htmlTrackElementList.addTrackElement_({tech() {}});
equal(htmlTrackElementList.length, genericHtmlTrackElements.length + 2, `the length is ${genericHtmlTrackElements.length + 2}`);

htmlTrackElementList.removeTrackElement_(htmlTrackElementList.getTrackElementByTrack_(track1));
Expand Down
35 changes: 17 additions & 18 deletions test/unit/tracks/html-track-element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import HTMLTrackElement from '../../../src/js/tracks/html-track-element.js';
import TextTrack from '../../../src/js/tracks/text-track.js';
import window from 'global/window';

let noop = Function.prototype;
let defaultTech = {
textTracks: noop,
on: noop,
off: noop,
currentTime: noop
const defaultTech = {
textTracks() {},
on() {},
off() {},
currentTime() {}
};

q.module('HTML Track Element');
Expand All @@ -23,20 +22,20 @@ test('html track element requires a tech', function() {
});

test('can create a html track element with various properties', function() {
let kind = 'chapters',
label = 'English',
language = 'en',
src = 'http://www.example.com';
let kind = 'chapters';
let label = 'English';
let language = 'en';
let src = 'http://www.example.com';

let htmlTrackElement = new HTMLTrackElement({
let htmlTrackElement = new HTMLTrackElement({
kind,
label,
language,
src,
tech: defaultTech
});

equal(htmlTrackElement.default, undefined, 'we have a default');
equal(typeof htmlTrackElement.default, 'undefined', 'we have a default');
equal(htmlTrackElement.kind, kind, 'we have a kind');
equal(htmlTrackElement.label, label, 'we have a label');
equal(htmlTrackElement.readyState, 0, 'we have a readyState');
Expand All @@ -46,29 +45,29 @@ test('can create a html track element with various properties', function() {
});

test('defaults when items not provided', function() {
let htmlTrackElement = new HTMLTrackElement({
let htmlTrackElement = new HTMLTrackElement({
tech: defaultTech
});

equal(htmlTrackElement.default, undefined, 'we have a default');
equal(typeof htmlTrackElement.default, 'undefined', 'we have a default');
equal(htmlTrackElement.kind, 'subtitles', 'we have a kind');
equal(htmlTrackElement.label, '', 'we have a label');
equal(htmlTrackElement.readyState, 0, 'we have a readyState');
equal(htmlTrackElement.src, undefined, 'we have a src');
equal(typeof htmlTrackElement.src, 'undefined', 'we have a src');
equal(htmlTrackElement.srclang, '', 'we have a srclang');
equal(htmlTrackElement.track.cues.length, 0, 'we have a track');
});

test('fires loadeddata when track cues become populated', function() {
let changes = 0,
loadHandler;
let changes = 0;
let loadHandler;

loadHandler = function() {
changes++;
};

let htmlTrackElement = new HTMLTrackElement({
tech: noop
tech() {}
});

htmlTrackElement.addEventListener('load', loadHandler);
Expand Down
32 changes: 16 additions & 16 deletions test/unit/tracks/text-track-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import TestHelpers from '../test-helpers.js';
import * as browser from '../../../src/js/utils/browser.js';

q.module('Text Track Controls', {
'setup': function() {
setup() {
this.clock = sinon.useFakeTimers();
},
'teardown': function() {
teardown() {
this.clock.restore();
}
});

var track = {
const track = {
kind: 'captions',
label: 'test'
};
Expand All @@ -30,7 +30,7 @@ test('should be displayed when text tracks list is not empty', function() {
});

test('should be displayed when a text track is added to an empty track list', function() {
var player = TestHelpers.makePlayer();
let player = TestHelpers.makePlayer();

player.addRemoteTextTrack(track);

Expand All @@ -41,7 +41,7 @@ test('should be displayed when a text track is added to an empty track list', fu
});

test('should not be displayed when text tracks list is empty', function() {
var player = TestHelpers.makePlayer();
let player = TestHelpers.makePlayer();

ok(player.controlBar.captionsButton.hasClass('vjs-hidden'), 'control is not displayed');
equal(player.textTracks().length, 0, 'textTracks is empty');
Expand All @@ -50,7 +50,7 @@ test('should not be displayed when text tracks list is empty', function() {
});

test('should not be displayed when last text track is removed', function() {
var player = TestHelpers.makePlayer({
let player = TestHelpers.makePlayer({
tracks: [track]
});

Expand All @@ -63,10 +63,10 @@ test('should not be displayed when last text track is removed', function() {
});

test('menu should contain "Settings", "Off" and one track', function() {
var player = TestHelpers.makePlayer({
tracks: [track]
}),
menuItems;
let player = TestHelpers.makePlayer({
tracks: [track]
});
let menuItems;

this.clock.tick(1000);

Expand All @@ -81,7 +81,7 @@ test('menu should contain "Settings", "Off" and one track', function() {
});

test('menu should update with addRemoteTextTrack', function() {
var player = TestHelpers.makePlayer({
let player = TestHelpers.makePlayer({
tracks: [track]
});

Expand All @@ -96,7 +96,7 @@ test('menu should update with addRemoteTextTrack', function() {
});

test('menu should update with removeRemoteTextTrack', function() {
var player = TestHelpers.makePlayer({
let player = TestHelpers.makePlayer({
tracks: [track, track]
});

Expand All @@ -115,15 +115,15 @@ if (!browser.IS_IE8) {
// However, this test tests a specific with iOS7 where the TextTrackList doesn't report track mode changes.
// TODO: figure out why this test doens't work on IE8. https://github.com/videojs/video.js/issues/1861
test('menu items should polyfill mode change events', function() {
var player = TestHelpers.makePlayer({}),
changes,
trackMenuItem;
let player = TestHelpers.makePlayer({});
let changes;
let trackMenuItem;

// emulate a TextTrackList that doesn't report track mode changes,
// like iOS7
player.textTracks().onchange = undefined;
trackMenuItem = new TextTrackMenuItem(player, {
track: track
track
});

player.textTracks().on('change', function() {
Expand Down
20 changes: 10 additions & 10 deletions test/unit/tracks/text-track-cue-list.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TextTrackCueList from '../../../src/js/tracks/text-track-cue-list.js';

let genericTracks = [
const genericTracks = [
{
id: '1'
}, {
Expand All @@ -13,13 +13,13 @@ let genericTracks = [
q.module('Text Track Cue List');

test('TextTrackCueList\'s length is set correctly', function() {
var ttcl = new TextTrackCueList(genericTracks);
let ttcl = new TextTrackCueList(genericTracks);

equal(ttcl.length, genericTracks.length, 'the length is ' + genericTracks.length);
});

test('can get cues by id', function() {
var ttcl = new TextTrackCueList(genericTracks);
let ttcl = new TextTrackCueList(genericTracks);

equal(ttcl.getCueById('1').id, 1, 'id "1" has id of "1"');
equal(ttcl.getCueById('2').id, 2, 'id "2" has id of "2"');
Expand All @@ -28,7 +28,7 @@ test('can get cues by id', function() {
});

test('length is updated when new tracks are added or removed', function() {
var ttcl = new TextTrackCueList(genericTracks);
let ttcl = new TextTrackCueList(genericTracks);

ttcl.setCues_(genericTracks.concat([{id: '100'}]));
equal(ttcl.length, genericTracks.length + 1, 'the length is ' + (genericTracks.length + 1));
Expand All @@ -42,9 +42,9 @@ test('length is updated when new tracks are added or removed', function() {
});

test('can access items by index', function() {
var ttcl = new TextTrackCueList(genericTracks),
i = 0,
length = ttcl.length;
let ttcl = new TextTrackCueList(genericTracks);
let i = 0;
let length = ttcl.length;

expect(length);

Expand All @@ -54,7 +54,7 @@ test('can access items by index', function() {
});

test('can access new items by index', function() {
var ttcl = new TextTrackCueList(genericTracks);
let ttcl = new TextTrackCueList(genericTracks);

ttcl.setCues_(genericTracks.concat([{id: '100'}]));

Expand All @@ -64,7 +64,7 @@ test('can access new items by index', function() {
});

test('cannot access removed items by index', function() {
var ttcl = new TextTrackCueList(genericTracks);
let ttcl = new TextTrackCueList(genericTracks);

ttcl.setCues_(genericTracks.concat([{id: '100'}, {id: '101'}]));
equal(ttcl[3].id, '100', 'id of item at index 3 is 100');
Expand All @@ -77,7 +77,7 @@ test('cannot access removed items by index', function() {
});

test('new item available at old index', function() {
var ttcl = new TextTrackCueList(genericTracks);
let ttcl = new TextTrackCueList(genericTracks);

ttcl.setCues_(genericTracks.concat([{id: '100'}]));
equal(ttcl[3].id, '100', 'id of item at index 3 is 100');
Expand Down
8 changes: 7 additions & 1 deletion test/unit/tracks/text-track-list-converter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import TextTrack from '../../../src/js/tracks/text-track.js';
import TextTrackList from '../../../src/js/tracks/text-track-list.js';
import Html5 from '../../../src/js/tech/html5.js';
import document from 'global/document';
import window from 'global/window';

q.module('Text Track List Converter', {});

Expand All @@ -26,6 +25,7 @@ let cleanup = (item) => {
if (Html5.supportsNativeTextTracks()) {
q.test('trackToJson_ produces correct representation for native track object', function(a) {
let track = document.createElement('track');

track.src = 'example.com/english.vtt';
track.kind = 'captions';
track.srclang = 'en';
Expand All @@ -48,11 +48,13 @@ if (Html5.supportsNativeTextTracks()) {
});

let nativeTrack = document.createElement('track');

nativeTrack.kind = 'captions';
nativeTrack.srclang = 'es';
nativeTrack.label = 'Spanish';

let tt = new TextTrackList();

tt.addTrack_(nativeTrack.track);
tt.addTrack_(emulatedTrack);

Expand Down Expand Up @@ -96,12 +98,14 @@ if (Html5.supportsNativeTextTracks()) {
});

let nativeTrack = document.createElement('track');

nativeTrack.src = 'example.com/spanish.vtt';
nativeTrack.kind = 'captions';
nativeTrack.srclang = 'es';
nativeTrack.label = 'Spanish';

let tt = new TextTrackList();

tt.addTrack_(nativeTrack.track);
tt.addTrack_(emulatedTrack);

Expand Down Expand Up @@ -171,6 +175,7 @@ q.test('textTracksToJson produces good json output for emulated only', function(
});

let tt = new TextTrackList();

tt.addTrack_(anotherTrack);
tt.addTrack_(emulatedTrack);

Expand Down Expand Up @@ -224,6 +229,7 @@ q.test('jsonToTextTracks calls addRemoteTextTrack on the tech with emulated trac
});

let tt = new TextTrackList();

tt.addTrack_(anotherTrack);
tt.addTrack_(emulatedTrack);

Expand Down
Loading

0 comments on commit c1112b7

Please sign in to comment.