added tests for init.js. popcorn-port
authorhamidouk
Mon, 24 Oct 2011 16:51:22 +0200
branchpopcorn-port
changeset 127 3ce493c93d6c
parent 126 e007a7ad66b8
child 128 f3fec80dd31c
added tests for init.js.
src/js/init.js
unittests/index.html
unittests/tests/init.js
--- a/src/js/init.js	Mon Oct 24 12:43:13 2011 +0200
+++ b/src/js/init.js	Mon Oct 24 16:51:22 2011 +0200
@@ -8,19 +8,19 @@
 							container:'LdtPlayer',
 							css:'../../src/css/LdtPlayer.css',
               widgets: [
-                {type: IriSP.PlayerWidget, // please note that type refers directly to the constructor of the widget.
+                {type: "IriSP.PlayerWidget", // please note that type refers directly to the constructor of the widget.
                  metadata:{
                   format:'cinelab',
                   src:'test.json',
                   load:'json'}
                 },
-               {type: IriSP.SegmentsWidget, 
+               {type: "IriSP.SegmentsWidget", 
                  metadata:{
                   format:'cinelab',
                   src:'test.json',
                   load:'json'}
                 },
-               {type: IriSP.AnnotationsWidget, 
+               {type: "IriSP.AnnotationsWidget",                
                  metadata:{
                   format:'cinelab',
                   src:'test.json',
@@ -29,7 +29,7 @@
               ]
 						player:{
 							type:'jwplayer', // player type
-              
+              container: '#PopcornContainer'
               // the rest is player-dependent configuration options.
               file : "video/franceculture/franceculture_retourdudimanche20100620.flv", 
               streamer: "rtmp://media.iri.centrepompidou.fr/ddc_player/", 
@@ -46,59 +46,52 @@
 IriSP.configurePopcorn = function (options) {
     var pop;
     
-    switch(options.player.type) {
+    switch(options.type) {
       /*
         todo : dynamically create the div/video tag which
         will contain the video.
       */
       case "html5":
-           //pop = Popcorn(
+           pop = Popcorn(options.container);
         break;
+        
+      case "jwplayer":
+          var opts = IriSP.jQuery.extend({}, options);
+          delete opts.container;
+          pop = Popcorn.jwplayer(options.container, "", opts);
+        break;
+        
+      default:
+        pop = undefined;
     };
-};
-
-IriSP.configureWidgets = function (guiOptions) {
-
-  var dt = new IriSP.DataLoader();
-  
-  var params = {width: guiOptions.width, height: guiOptions.height, 
-  var lay = new LayoutManager(params);
-  
-  for (widget in widgets) {
-    var container = lay.createDiv();
     
-  };
+    return pop;
 };
 
-IriSP.initInstance = function ( config ) {		
-		if ( config === null ) {
-			config = IriSP.configDefault;
-		
-    } else {			
-		
+IriSP.configureWidgets = function (popcornInstance, guiOptions) {
 
-			if (.config.player.params == null ) {
-				config.player.params = IriSP.configDefault.player.params;
-			}
-			
-			if ( config.player.flashvars == null ) {
-				config.player.flashvars = IriSP.configDefault.player.flashvars;
-			}
-			
-			if ( config.player.attributes == null ) {
-				config.player.attributes = IriSP.configDefault.player.attributes;
-			}
-		}
-		
-		var metadataSrc 		 = config.metadata.src;
-		var guiContainer		 = config.gui.container;
-		var guiMode				 = config.gui.mode;
-			
-    IriSP.loadLibs(IriSP.lib, IriSP.config.gui.css, function() {
-    	IriSP.createPlayerChrome();			
-      /******* Load Metadata *******/
-      IriSP.getMetadata();	
-    });
-	
+  var dt = new IriSP.DataLoader();
+  var serialFactory = new IriSP.SerializerFactory(dt);
+  
+  var params = {width: guiOptions.width, height: guiOptions.height};
+  var lay = new IriSP.LayoutManager(params);
+  
+  var ret_widgets = [];
+  
+  for (index in guiOptions.widgets) {    
+    var widget = guiOptions.widgets[index];
+    var container = lay.createDiv();
+        
+    var arr = IriSP.jQuery.extend({}, widget);
+    arr.container = container;
     
+    var serializer = serialFactory.getSerializer(widget.metadata);
+
+    // instantiate the object passed as a string
+    var widget = new IriSP[widget.type](popcornInstance, widget, serializer);    
+    serializer.sync(function() { widget.draw() });
+    ret_widgets.push(widget);
+  };
+  
+  return ret_widgets;
 };
\ No newline at end of file
--- a/unittests/index.html	Mon Oct 24 12:43:13 2011 +0200
+++ b/unittests/index.html	Mon Oct 24 16:51:22 2011 +0200
@@ -25,6 +25,7 @@
 	<script src="tests/annotationsWidget.js" type="text/javascript"></script>
 	<script src="tests/segmentsWidget.js" type="text/javascript"></script>
 	<script src="tests/layout.js" type="text/javascript"></script>
+	<script src="tests/init.js" type="text/javascript"></script>
 </head>
 <script>
  $(document).ready(function(){ 
@@ -41,6 +42,7 @@
 		test_annotations_widget();
 		test_segments_widget();
 		test_layout();
+		test_init();
 });
 </script>	
 <body>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/unittests/tests/init.js	Mon Oct 24 16:51:22 2011 +0200
@@ -0,0 +1,64 @@
+function test_init() {
+	module("test initialization routines", 
+  {
+    setup: function() {
+      IriSP.jQuery("#widget-div").append("<div id='player_container'></div>");
+      this.popcornOptions = {
+          container: "#player_container",
+          type: "jwplayer", file : "video/franceculture/franceculture_retourdudimanche20100620.flv", 
+          streamer: "rtmp://media.iri.centrepompidou.fr/ddc_player/", 
+          flashplayer : '../libs/player.swf',
+          live: true, 
+          "controlbar.position" : "none", 
+          height: 300, 
+          width: 200, 
+          provider: "rtmp" 
+        };
+        
+        this.widgetOptions = {
+						width:650,
+						height:480,							
+						container:'LdtPlayer',
+						css:'../../src/css/LdtPlayer.css',
+            widgets: [
+              {type: "PlayerWidget",
+               metadata:{
+                format:'cinelab',
+                src:'test.json',
+                type:'dummy'}
+              },
+             {type: "SegmentsWidget", 
+               metadata:{
+                format:'cinelab',
+                src:'test.json',
+                type:'dummy'}
+              },
+             {type: "AnnotationsWidget", 
+               metadata:{
+                format:'cinelab',
+                src:'test.json',
+                type:'dummy'}
+              },
+            ]};
+    }
+  });
+  
+  test("test the creation of a correct popcorn object", function() {
+
+            
+    var pop = IriSP.configurePopcorn(this.popcornOptions);
+    notDeepEqual(pop, undefined, "returned object is not undefined");
+    
+    /* FIXME: add more test options ? */
+    equal(pop.options.type, "jwplayer", "the player is of the correct type.");
+  });
+  
+  test("test the instantiation of a bunch of widgets", function() {
+    var pop = IriSP.configurePopcorn(this.popcornOptions);
+    var widgets = IriSP.configureWidgets(pop, this.widgetOptions);
+    
+    ok(widgets[0] instanceof IriSP.PlayerWidget, "first widget is a player widget");
+    ok(widgets[1] instanceof IriSP.SegmentsWidget, "second widget is a segments widget");
+    ok(widgets[2] instanceof IriSP.AnnotationsWidget, "third widget is an annotation widget");
+  });
+}
\ No newline at end of file