Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
walsh9 committed Oct 8, 2014
1 parent 7377a6a commit 3d9d5a7
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,5 @@ var eventEmitter = {
h[2].apply();
}
});
},
delegate: function (obj) {
obj.on = function (event, callback) {
eventEmitter.on(obj, event, callback);
};
obj.trigger = function (obj) {
eventEmitter.trigget(obj, event);
};
return obj;
}
};
25 changes: 25 additions & 0 deletions test/modules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Video.js Transcript Sub Modules</title>
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
<script>
test('the environment is sane', function() {
ok(true, 'everything is swell');
});
</script>
<script src="../node_modules/video.js/dist/video-js/video.js"></script>
<script src="../src/options.js"></script>
<script src="../src/events.js"></script>
<script src="../src/tracklist.js"></script>
<script src="../src/scroller.js"></script>
<script src="../src/widget.js"></script>
<script src="modules.test.js"></script>
</body>
</html>
120 changes: 120 additions & 0 deletions test/modules.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*! videojs-transcript - v0.0.0 - 2014-9-8
* Copyright (c) 2014 Matthew Walsh
* Licensed under the MIT license. */
(function (window, videojs, qunit) {
'use strict';

var realIsHtmlSupported,
player,

// local QUnit aliases
// http://api.qunitjs.com/

// module(name, {[setup][ ,teardown]})
module = qunit.module,
// test(name, callback)
test = qunit.test,
// ok(value, [message])
ok = qunit.ok,
// equal(actual, expected, [message])
equal = qunit.equal,
// strictEqual(actual, expected, [message])
strictEqual = qunit.strictEqual,
// deepEqual(actual, expected, [message])
deepEqual = qunit.deepEqual,
// notEqual(actual, expected, [message])
notEqual = qunit.notEqual,
// throws(block, [expected], [message])
throws = qunit.throws;

/********************
* test events.js
********************/
module('events', {
setup: function() {
// force HTML support so the tests run in a reasonable
// environment under phantomjs
realIsHtmlSupported = videojs.Html5.isSupported;
videojs.Html5.isSupported = function () {
return true;
};

// create a video element
var video = document.createElement('video');
document.querySelector('#qunit-fixture').appendChild(video);

// create a video.js player
player = videojs(video);

my.player = player;
},
teardown: function() {
videojs.Html5.isSupported = realIsHtmlSupported;
}
});

test('Register and trigger event', function(assert) {
expect(1);
eventEmitter.on(this, 'test', function() {
assert.ok(true, 'Event was triggered.');
});
eventEmitter.trigger(this, 'test');
});

/********************
* test tracklist.js
********************/
module('tracklist', {
setup: function() {
// force HTML support so the tests run in a reasonable
// environment under phantomjs
realIsHtmlSupported = videojs.Html5.isSupported;
videojs.Html5.isSupported = function () {
return true;
};

// create a video element
var video = document.createElement('video');
video.setAttribute('id', 'test-video');
document.querySelector('#qunit-fixture').appendChild(video);

var track = document.createElement('track');
track.setAttribute('kind', 'captions');
track.setAttribute('src', '../captions/captions.en.srt');
track.setAttribute('srclang', 'en');
track.setAttribute('label', 'English');
video.appendChild(track);

var track2 = document.createElement('track');
track2.setAttribute('kind', 'subtitles');
track2.setAttribute('src', '../captions/captions.sv.srt');
track2.setAttribute('srclang', 'sv');
track2.setAttribute('label', 'Swedish');
video.appendChild(track2);

// create a video.js player
player = videojs(video);

my.player = player;
},
teardown: function() {
videojs.Html5.isSupported = realIsHtmlSupported;
}
});

test('getTracks() returns list of tracks.', function(assert) {
assert.equal(trackList.get().length, videojs.players['test-video'].textTracks().length, 'Tracklist length is correct');
});

test('active() returns the default track.', function(assert) {
var tracks = trackList.get();
assert.equal(trackList.active(tracks).label(), 'English', 'Active track is defined');
});

test('active() returns active track after track change.', function(assert) {
var tracks = trackList.get();
videojs.players['test-video'].textTracks()[1].show();
assert.equal(trackList.active(tracks).label(), 'Swedish', 'Active track returns current track after track change.');
});

}(window, window.videojs, window.QUnit));

0 comments on commit 3d9d5a7

Please sign in to comment.