]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Updated unit test, null artist handling
authorstevenaw <sweerdenburg@gmail.com>
Fri, 21 Jan 2011 17:06:56 +0000 (12:06 -0500)
committerstevenaw <sweerdenburg@gmail.com>
Fri, 21 Jan 2011 17:06:56 +0000 (12:06 -0500)
plugins/lastfm/popcorn.lastfm.html
plugins/lastfm/popcorn.lastfm.js
plugins/lastfm/popcorn.lastfm.unit.js

index 72f79b372e0f32701bb0acae1d7877dbf403cc68..5d0011d35347fb43149de457c16a797ec5f5bb62 100644 (file)
@@ -4,7 +4,6 @@
   <title>Popcorn LastFM Plug-in Demo</title>
   
   <script src="../../popcorn.js"></script>
-  <script src="../../test/jquery.js"></script>
   <script src="popcorn.lastfm.js"></script>
   <script>
     document.addEventListener('DOMContentLoaded', function () {
         end: 20, // seconds
         artist: 'the beatles',
         target: 'lastfmdiv'
+      } )
+      .lastfm({
+        start: 15, // seconds
+        end: 30, // seconds
+        artist: 'sdfsdfsdfdsddfsdfsdfsddfsf',
+        target: 'lastfmdiv'
       } )
            .lastfm({
         start: 20, // seconds
@@ -41,6 +46,7 @@
   <h1 id="qunit-header">Popcorn LastFM Plug-in Demo</h1>
   <p> Artist information for 'yacht' will appear at 5 seconds and disappear at 15 seconds.</p>
   <p> Artist information for 'The Beatles' will appear at 10 seconds and disappear at 20 seconds.</p>
+  <p> 'Unknown Artist' will appear at 15 seconds and disappear at 30 seconds.</p>
   <p> Artist information for 'Coldplay' will appear at 20 seconds and disappear at 45 seconds.</p>
   <p> Artist information for 'yacht' will appear at 25 seconds and disappear at 40 seconds.</p>
   <div>
index 2b03be42fcbb093ea1efcb0e05e8f77f0889e0d2..fc8a0fccc3b6b124fc68ce220f8bc3604b175126 100644 (file)
@@ -65,29 +65,31 @@ var lastFMcallback;
           script.type = "text/javascript";
           head.insertBefore( script, head.firstChild );
           
-          _artists[options.artist] = "Information unavailable";
+          _artists[options.artist] = "Unknown Artist";
         }
         
         lastFMcallback = function(data){
-          var htmlString = '<h3>'+data.artist.name+'</h3>';
-          htmlString += '<a href="'+data.artist.url+'" target="_blank" style="float:left;margin:0 10px 0 0;"><img src="'+ data.artist.image[2]['#text'] +'" alt=""></a>';
-          htmlString += '<p>'+ data.artist.bio.summary +'</p>';
-          htmlString += '<hr /><p><h4>Tags</h4><ul>';
-          
-          Popcorn.forEach( data.artist.tags.tag, function( val, i) {
-            htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
-          });
-          
-          htmlString += '</ul></p>';
-          htmlString += '<hr /><p><h4>Similar</h4><ul>';
-          
-          Popcorn.forEach( data.artist.similar.artist, function( val, i) {
-            htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
-          });
-          
-          htmlString += '</ul></p>';
-          
-          _artists[data.artist.name.toLowerCase()] = htmlString;
+          if (data.artist) {
+            var htmlString = '<h3>'+data.artist.name+'</h3>';
+            htmlString += '<a href="'+data.artist.url+'" target="_blank" style="float:left;margin:0 10px 0 0;"><img src="'+ data.artist.image[2]['#text'] +'" alt=""></a>';
+            htmlString += '<p>'+ data.artist.bio.summary +'</p>';
+            htmlString += '<hr /><p><h4>Tags</h4><ul>';
+            
+            Popcorn.forEach( data.artist.tags.tag, function( val, i) {
+              htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
+            });
+            
+            htmlString += '</ul></p>';
+            htmlString += '<hr /><p><h4>Similar</h4><ul>';
+            
+            Popcorn.forEach( data.artist.similar.artist, function( val, i) {
+              htmlString += '<li><a href="'+ val.url +'">'+ val.name +'</a></li>';
+            });
+            
+            htmlString += '</ul></p>';
+            
+            _artists[data.artist.name.toLowerCase()] = htmlString;
+          }
         };
       },
       /**
index 80c70b18d6ee7d57b01c89c116a9b16453901b39..092984d1b8d88b0bd1436c067fd7f9071d48efbd 100644 (file)
@@ -1,10 +1,11 @@
 test("Popcorn LastFM Plugin", function () {
   
   var popped = Popcorn("#video"),
-      expects = 5, 
+      expects = 8, 
       count = 0,
       interval,
       interval2,
+      interval3,
       lastfmdiv = document.getElementById('lastfmdiv');
   
   expect( expects );
@@ -24,30 +25,55 @@ test("Popcorn LastFM Plugin", function () {
   plus();
   
   popped.lastfm({
-    start: 1, // seconds
-    end: 3, // seconds
-    artist: 'yacht',
-    target: 'lastfmdiv'
-  } );
+      start: 1, // seconds
+      end: 4, // seconds
+      artist: 'yacht',
+      target: 'lastfmdiv'
+    } )
+    .lastfm({
+      start: 2.5, // seconds
+      end: 7, // seconds
+      artist: 'the beatles',
+      target: 'lastfmdiv'
+    } )
+    .lastfm({
+      start: 4.5, // seconds
+      end: 7, // seconds
+      artist: '',
+      target: 'lastfmdiv'
+    } );
 
   interval = setInterval( function() {
-    if( popped.currentTime() > 1 && popped.currentTime() < 3 ) {
-      ok( /display: inline;/.test( lastfmdiv.innerHTML ), "Div contents are displayed" );
+    if( popped.currentTime() > 1 && popped.currentTime() < 4 ) {
+    
+      equals ( lastfmdiv.childElementCount, 3, "lastfmdiv now has three inner elements" );
       plus();
-      ok( /img/.test( lastfmdiv.innerHTML ), "An image exists" );
+      equals (lastfmdiv.children[0].style.display , "inline", "yachtdiv is visible on the page" );
       plus();
       clearInterval( interval );
     }
-  }, 500);
+  }, 1000);
   
   interval2 = setInterval( function() {
-    if( popped.currentTime() > 3 ) {
-      ok( /display: none;/.test( lastfmdiv.innerHTML ), "Div contents are hidden again" );
+    if( popped.currentTime() > 2.5 && popped.currentTime() < 3 ) {
+      equals (lastfmdiv.children[0].style.display , "inline", "yachtdiv is visible on the page" );
+      plus();
+      equals (lastfmdiv.children[1].style.display , "inline", "beatlesdiv is visible on the page" );
+      plus();
+      equals (lastfmdiv.children[2].style.display , "none", "nulldiv is not visible on the page" );
       plus();
       clearInterval( interval2 );
     }
-  }, 500);
+  }, 1000);
+  
+  interval3 = setInterval( function() {
+    if( popped.currentTime() > 4.5 && popped.currentTime() < 7 ) {
+      equals (lastfmdiv.children[2].innerHTML , "Unknown Artist", "Artist information could not be found" );
+      plus();
+      clearInterval( interval3 );
+    }
+  }, 1000);
+  
   popped.volume(0);
   popped.play();
-  
 });