Permalink
Browse files

adding unit tests

  • Loading branch information...
1 parent 09b24b6 commit e9bb421d84070087dc7052d66b7304cdd036b3eb @drigato drigato committed with cadecairos Dec 12, 2011
View
4 plugins/rdio/popcorn.rdio.html
@@ -23,14 +23,14 @@
end: 20,
target: "rdiodiv",
artist: "Radiohead",
- album: "The Bends"
+ album: "The Bends"
})
.rdio({
start: 20,
end: 40,
target: "rdiodiv",
person: "scottyhons",
- id: 236475,
+ id: "236475",
playlist: "Toronto Music"
})
}, false);
View
2 plugins/rdio/popcorn.rdio.js
@@ -72,7 +72,7 @@
if ( !_albums[ options.playlist ] ) {
_albums[ options.playlist ] = {
count: 0,
- htmlString: "Unknown Artist"
+ htmlString: "Unknown Playlist"
};
Popcorn.getJSONP( "http://www.rdio.com/api/oembed/?format=json&url=http://www.rdio.com/%23/people/" + options.person + "/playlists/" + options.id + "/" + options.playlist + "/&callback=loadResult", loadResult, false );
View
49 plugins/rdio/popcorn.rdio.unit.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn API</title>
+ <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+ <script src="../../test/qunit/qunit.js"></script>
+ <!--
+ do not move - this must be called immediately prior to
+ popcorn-api-draft.js
+ -->
+
+ <script src="../../popcorn.js"></script>
+ <script src="../../test/jquery.js"></script>
+ <script src="popcorn.rdio.js"></script>
+
+ <script src="popcorn.rdio.unit.js"></script>
+</head>
+<body>
+
+ <h1 id="qunit-header">Popcorn Rdio Plugin</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture"> </div>
+
+ <video id="video"
+ controls
+ width="250px"
+ poster="../../test/poster.png">
+
+ <source id="mp4"
+ src="../../test/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id="ogv"
+ src="../../test/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <source id="webm"
+ src="../../test/trailer.webm"
+ type='video/webm; codecs="vp8, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ <div id="rdiodiv"></div>
+</body>
+</html>
View
101 plugins/rdio/popcorn.rdio.unit.js
@@ -0,0 +1,101 @@
+test( "Popcorn Rdio Plugin", function() {
+
+ var popped = Popcorn( "#video" ),
+ expects = 12,
+ count = 0,
+ setupId,
+ rdiodiv = document.getElementById( "rdiodiv" );
+
+ expect( expects );
+
+ function plus() {
+ if ( ++count === expects ) {
+ start();
+ }
+ }
+
+ stop();
+
+ ok( "rdio" in popped, "rdio is a method of the popped instance" );
+ plus();
+
+ equals( rdiodiv.innerHTML, "", "initially, there is nothing inside the rdiodiv" );
+ plus();
+
+ popped.rdio({
+ start: 1,
+ end: 4,
+ target: "rdiodiv",
+ artist: "Erykah Badu",
+ album: "Baduizm"
+ })
+ .rdio({
+ start: 2,
+ end: 7,
+ target: "rdiodiv",
+ person: "scottyhons",
+ id: 236475,
+ playlist: "Toronto Music"
+ })
+ .rdio({
+ start: 4,
+ end: 7,
+ target: "rdiodiv",
+ artist: "Radiohead",
+ album: "some album"
+ })
+ .rdio({
+ start: 5,
+ end: 8,
+ target: "rdiodiv",
+ person: "some person",
+ id: "236475",
+ playlist: "some playlist"
+ });
+
+
+ setupId = popped.getLastTrackEventId();
+
+ popped.exec( 2, function() {
+ equals( rdiodiv.childElementCount, 4, "rdiodiv now has three inner elements" );
+ plus();
+ equals( rdiodiv.children[ 0 ].style.display , "inline", "Erykah Badu div is visible on the page" );
+ plus();
+ });
+
+ popped.exec( 3, function() {
+ equals( rdiodiv.children[ 0 ].style.display , "inline", "Erykah Badu div is still visible on the page" );
+ plus();
+ equals( rdiodiv.children[ 1 ].style.display , "inline", "Scottyhons div is visible on the page" );
+ plus();
+ equals( rdiodiv.children[ 2 ].style.display , "none", "null div is not visible on the page" );
+ plus();
+ equals( rdiodiv.children[ 3 ].style.display , "none", "null div is not visible on the page" );
+ plus();
+ });
+
+ popped.exec( 5, function() {
+ equals( rdiodiv.children[ 2 ].innerHTML , "Unknown Artist", "Artist information could not be found" );
+ plus();
+ equals( rdiodiv.children[ 3 ].innerHTML , "Unknown Playlist", "Playlist information could not be found" );
+ plus();
+
+ popped.pause().removeTrackEvent( setupId );
+ ok( !rdiodiv.children[ 3 ], "removed playlist was properly destroyed" );
+ plus();
+ });
+
+ // empty track events should be safe
+ popped.rdio({});
+
+ // debug should log errors on empty track events
+ Popcorn.plugin.debug = true;
+ try {
+ popped.rdio({});
+ } catch( e ) {
+ ok( true, "empty event was caught by debug" );
+ plus();
+ }
+
+ popped.volume( 0 ).play();
+});

0 comments on commit e9bb421

Please sign in to comment.