Permalink
Browse files

falling test fixed

  • Loading branch information...
Jozef Chraplewski
Jozef Chraplewski committed Jun 1, 2012
1 parent 1199402 commit 20b2a5942368ce7128b8fdb1f8f012ece916ff9f
Showing with 154 additions and 141 deletions.
  1. +1 −1 src/playlist.js
  2. +1 −16 test.html
  3. +30 −3 test/mocks.js
  4. +119 −118 test/playlist_engine_test.js
  5. +3 −3 test/playlist_thumb_test.js
View
@@ -180,7 +180,7 @@ _V_.PlaylistThumb = _V_.Component.extend({
},
poster: function() {
- return this.params.poster;
+ return this.params.poster_url;
}
});
View
@@ -35,22 +35,7 @@ <h1 id="qunit-header">Tests</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
-
-
-
- <div id="qunit-fixture">
- <div id="vid1_playlist">
- <img src="thumb1"
- data-poster="poster1"
- data-sources='[{"src":"src1.mp4",
- "type":"video/mp4", "media":"", "title":""},
- {"src":"src2.ogv",
- "type":"video/ogg", "media":"", "title":""}]'/>
- <img src="thumb2"
- data-poster="poster2"
- data-sources='[{"src":"src1.mp4",
- "type":"video/mp4", "media":"", "title":""}]'/>
- </div>
+ <div id="qunit-fixture"></div>
</body>
</html>
View
@@ -7,11 +7,39 @@ function mkPlayer() {
width: function(){},
src: function(sources){},
triggerReady: function(){},
+ options: {
+ "playlist": mkPlaylist()
+ },
tag: { poster: "poster" },
el: { id: "vid1", style: {} }
};
};
+function mkPlaylist(){
+ return [
+ {"thumb_url":"thumb.url",
+ "poster_url":"poster.url",
+ "sources":[
+ {"src":"video.src",
+ "type":"video/mp4",
+ "media":"",
+ "title":""
+ }
+ ]
+ },
+ {"thumb_url":"thumb.url2",
+ "poster_url":"poster.url2",
+ "sources":[
+ {"src":"video.src2",
+ "type":"video/mp4",
+ "media":"",
+ "title":""
+ }
+ ]
+ }
+ ]
+};
+
function mkVideo(src) {
return {
sources: function(){},
@@ -25,8 +53,7 @@ function videos() {
function mkThumb() {
var player = mkPlayer();
- var el = document.getElementById(player.el.id + "_playlist").children[0];
- var options = { index: 0, el: el };
- var obj = new _V_.PlaylistThumb(player, options);
+ var playlist = player.options.playlist;
+ var obj = new _V_.PlaylistThumb(player, playlist[0], 0);
return obj;
};
@@ -1,165 +1,166 @@
-// helper methods
-var itInvokes = function(expectedMethod, callback) {
- test("it invokes " + expectedMethod + " method", function() {
- var subject = new _V_.PlaylistEngine(mkPlayer(), videos());;
- var mock = sinon.mock(subject);
- mock.expects(expectedMethod).once();
- callback(subject);
- mock.verify();
+(function(){
+ var itInvokes = function(expectedMethod, callback) {
+ test("it invokes " + expectedMethod + " method", function() {
+ var subject = new _V_.PlaylistEngine(mkPlayer(), mkPlaylist());
+ var mock = sinon.mock(subject);
+ mock.expects(expectedMethod).once();
+ callback(subject);
+ mock.verify();
+ });
+ };
+
+ module("_V_.PlaylistEngine#incrementCurrentIndex");
+
+ test("increments currentIndex", function(){
+ var subject = new _V_.PlaylistEngine(mkPlayer(), mkPlaylist());
+ equal(subject.currentIndex, 0);
+ subject.incrementCurrentIndex();
+ equal(subject.currentIndex, 1);
});
-};
-
-
-module("_V_.PlaylistEngine#incrementCurrentIndex");
-test("increments currentIndex", function(){
- var subject = new _V_.PlaylistEngine(mkPlayer(), videos());
- equal(subject.currentIndex, 0);
- subject.incrementCurrentIndex();
- equal(subject.currentIndex, 1);
-});
+ test("sets current index to 0 when it was at the end of the videos array",
+ function() {
+ var subject = new _V_.PlaylistEngine(mkPlayer(), mkPlaylist());
+ subject.currentIndex = 1;
+ equal(subject.currentIndex, 1);
+ subject.incrementCurrentIndex();
+ equal(subject.currentIndex, 0);
+ });
-test("sets current index to 0 when it was at the end of the videos array",
-function() {
- var subject = new _V_.PlaylistEngine(mkPlayer(), videos());
- subject.currentIndex = 1;
- equal(subject.currentIndex, 1);
- subject.incrementCurrentIndex();
- equal(subject.currentIndex, 0);
-});
+ module("_V_.PlaylistEngine#decrementCurrentIndex");
-module("_V_.PlaylistEngine#decrementCurrentIndex");
+ test("decrements currentIndex", function(){
+ var subject = new _V_.PlaylistEngine(mkPlayer(), mkPlaylist());
+ subject.currentIndex = 1;
+ equal(subject.currentIndex, 1);
+ subject.decrementCurrentIndex();
+ equal(subject.currentIndex, 0);
+ });
-test("decrements currentIndex", function(){
- var subject = new _V_.PlaylistEngine(mkPlayer(), videos());
- subject.currentIndex = 1;
- equal(subject.currentIndex, 1);
- subject.decrementCurrentIndex();
- equal(subject.currentIndex, 0);
-});
+ test("sets current index to last element of the videos array when it was at 0",
+ function() {
+ var subject = new _V_.PlaylistEngine(mkPlayer(), mkPlaylist());
+ subject.videos = [0, 1];
+ subject.currentIndex = 0;
+ equal(subject.currentIndex, 0);
+ subject.decrementCurrentIndex();
+ equal(subject.currentIndex, 1);
+ });
-test("sets current index to last element of the videos array when it was at 0",
-function() {
- var subject = new _V_.PlaylistEngine(mkPlayer(), videos());
- subject.videos = [0, 1];
- subject.currentIndex = 0;
- equal(subject.currentIndex, 0);
- subject.decrementCurrentIndex();
- equal(subject.currentIndex, 1);
-});
+ module("_V_.PlaylistEngine#play");
-module("_V_.PlaylistEngine#play");
+ test("sets new currentIndex", function() {
+ var subject = new _V_.PlaylistEngine(mkPlayer(), mkPlaylist());
+ equal(subject.currentIndex, 0);
+ sinon.stub(subject, "updateVideo")
+ subject.play(1);
+ equal(subject.currentIndex, 1);
+ });
-test("sets new currentIndex", function() {
- var subject = new _V_.PlaylistEngine(mkPlayer(), videos());
- equal(subject.currentIndex, 0);
- sinon.stub(subject, "updateVideo")
- subject.play(1);
- equal(subject.currentIndex, 1);
-});
+ itInvokes("updateVideo", function(subject) {
+ subject.play();
+ });
-itInvokes("updateVideo", function(subject) {
- subject.play();
-});
+ module("_V_.PlaylistEngine#pause");
-module("_V_.PlaylistEngine#pause");
+ test("invokes player's pause() method", function() {
+ var player = mkPlayer();
+ var subject = new _V_.PlaylistEngine(player, mkPlaylist());
+ var mock = sinon.mock(player);
+ mock.expects("pause").once();
+ subject.pause();
+ mock.verify();
+ });
-test("invokes player's pause() method", function() {
- var player = mkPlayer();
- var subject = new _V_.PlaylistEngine(player, videos());
- var mock = sinon.mock(player);
- mock.expects("pause").once();
- subject.pause();
- mock.verify();
-});
+ module("_V_.PlaylistEngine#next");
-module("_V_.PlaylistEngine#next");
+ itInvokes("updateVideo", function(subject) {
+ subject.next();
+ });
-itInvokes("updateVideo", function(subject) {
- subject.next();
-});
+ itInvokes('incrementCurrentIndex', function(subject) {
+ sinon.stub(subject, "updateVideo")
+ subject.next();
+ });
-itInvokes('incrementCurrentIndex', function(subject) {
- sinon.stub(subject, "updateVideo")
- subject.next();
-});
+ module("_V_.PlaylistEngine#prev");
-module("_V_.PlaylistEngine#prev");
+ itInvokes("updateVideo", function(subject) {
+ subject.prev();
+ });
-itInvokes("updateVideo", function(subject) {
- subject.prev();
-});
+ itInvokes('decrementCurrentIndex', function(subject) {
+ sinon.stub(subject, "updateVideo")
+ subject.prev();
+ });
-itInvokes('decrementCurrentIndex', function(subject) {
- sinon.stub(subject, "updateVideo")
- subject.prev();
-});
+ module("_V_.PlaylistEngine#reload");
-module("_V_.PlaylistEngine#reload");
+ itInvokes("pause", function(subject) {
+ subject.reload();
+ });
-itInvokes("pause", function(subject) {
- subject.reload();
-});
+ module("_V_.PlaylistEngine#updateVideo");
-module("_V_.PlaylistEngine#updateVideo");
+ itInvokes("updateVideoSrc", function(subject) {
+ subject.updateVideoPoster = function(){};
+ subject.updateVideo();
+ });
-itInvokes("updateVideoSrc", function(subject) {
- subject.updateVideoPoster = function(){};
- subject.updateVideo();
-});
+ itInvokes("updateVideoPoster", function(subject) {
+ subject.updateVideo();
+ });
-itInvokes("updateVideoPoster", function(subject) {
- subject.updateVideo();
-});
+ itInvokes("reload", function(subject) {
+ sinon.stub(subject, "updateVideoPoster")
+ subject.updateVideo();
+ });
-itInvokes("reload", function(subject) {
- sinon.stub(subject, "updateVideoPoster")
- subject.updateVideo();
-});
+ module("_V_.PlaylistEngine#updateVideoPoster");
-module("_V_.PlaylistEngine#updateVideoPoster");
+ (function() {
+ var player = mkPlayer();
+ var subject = new _V_.PlaylistEngine(player, mkPlaylist());
+ var mock = sinon.mock(player);
-(function() {
- var player = mkPlayer();
- var subject = new _V_.PlaylistEngine(player, videos());
- var mock = sinon.mock(player);
+ test("invokes player's src() method", function() {
+ mock.expects("src").once();
+ subject.updateVideoSrc();
+ mock.verify();
+ });
- test("invokes player's src() method", function() {
- mock.expects("src").once();
- subject.updateVideoSrc();
- mock.verify();
- });
+ test("invokes player's triggerReady() method", function() {
+ mock.expects("triggerReady").once();
+ subject.updateVideoSrc();
+ mock.verify();
+ });
+ })();
- test("invokes player's triggerReady() method", function() {
- mock.expects("triggerReady").once();
- subject.updateVideoSrc();
- mock.verify();
- });
-})();
+ module("_V_.PlaylistEngine#updateVideoPoster");
-module("_V_.PlaylistEngine#updateVideoPoster");
+ test("sets new poster", function() {
+ var subject = new _V_.PlaylistEngine(mkPlayer(), mkPlaylist());
+ equal(subject.player.tag.poster, "poster");
+ subject.updateVideoPoster();
+ equal(subject.player.tag.poster, "poster.url");
+ });
-test("sets new poster", function() {
- var subject = new _V_.PlaylistEngine(mkPlayer(), videos());
- equal(subject.player.tag.poster, "poster");
- subject.updateVideoPoster();
- equal(subject.player.tag.poster, "src1/poster");
-});
+})();
@@ -2,19 +2,19 @@ module("_V_.PlaylistThumb#sources()");
test('returns all video sources', function() {
var subject = mkThumb();
- equal(subject.sources().length, 2)
+ equal(subject.sources().length, 1)
});
test("source is a valid js object", function() {
var subject = mkThumb();
var vidSource = subject.sources()[0];
- equal(vidSource.src,"src1.mp4");
+ equal(vidSource.src,"video.src");
equal(vidSource.type,"video/mp4");
equal(vidSource.media,"");
equal(vidSource.title,"");
});
test('returns poster for video', function() {
var subject = mkThumb();
- equal(subject.poster(), "poster1")
+ equal(subject.poster(), "poster.url")
});

0 comments on commit 20b2a59

Please sign in to comment.