unittests/tests/init.js
branchnew-model
changeset 924 64c2eaafe5e2
parent 923 b3ee7d1b472a
child 925 28efc97b5d78
equal deleted inserted replaced
923:b3ee7d1b472a 924:64c2eaafe5e2
     1 function test_init() {
       
     2 	module("test initialization routines",
       
     3   {
       
     4     setup: function() {
       
     5       IriSP.jQuery("#widget-div").append("<div id='LdtPlayer'></div>");
       
     6       this.popcornOptions = {
       
     7           container: "LdtPlayer",
       
     8           type: "html5", 
       
     9           file : "trailer.mp4",
       
    10         };
       
    11 
       
    12         this.widgetOptions = {
       
    13 						width:650,
       
    14 						height:480,
       
    15 						container:'LdtPlayer',
       
    16 						css:'../../src/css/LdtPlayer.css',
       
    17             widgets: [
       
    18               {type: "PlayerWidget",
       
    19                mode: "radio",
       
    20                metadata:{
       
    21                 format:'cinelab',
       
    22                 src:'test.json',
       
    23                 type:'dummy'}
       
    24               },
       
    25              {type: "SegmentsWidget",
       
    26                metadata:{
       
    27                 format:'cinelab',
       
    28                 src:'test.json',
       
    29                 type:'dummy'}
       
    30               },
       
    31              {type: "AnnotationsWidget",
       
    32                metadata:{
       
    33                 format:'cinelab',
       
    34                 src:'test.json',
       
    35                 type:'dummy'}
       
    36               },
       
    37             ]};
       
    38 
       
    39         this.modulesOptions = [ 
       
    40             {type: "Module", a : 36},
       
    41             {type: "Module", b : 54}
       
    42         ];
       
    43     }
       
    44   });
       
    45 
       
    46   test("test the creation of a correct popcorn object", function() {
       
    47 
       
    48     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
       
    49     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
       
    50     notDeepEqual(pop, undefined, "returned object is not undefined");
       
    51   });
       
    52 
       
    53   test("test the creation of a video tag", function() {
       
    54 
       
    55     var popcornOptions = {
       
    56             type: "html5",
       
    57             file: "demo.mp4"
       
    58           };
       
    59 
       
    60     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
       
    61     var pop = IriSP.configurePopcorn(layoutManager, popcornOptions);
       
    62 
       
    63     var elem = IriSP.jQuery("#LdtPlayer").find("video");
       
    64     notDeepEqual(elem, [], "the element is not null");
       
    65     equal(elem.attr("src"), popcornOptions.file, "the src attribute is set correctly");
       
    66   });
       
    67 
       
    68   test("test the instantiation of a single widget without dependencies", function() {
       
    69 
       
    70     var dt = new IriSP.DataLoader();
       
    71     var serialFactory = new IriSP.SerializerFactory(dt);
       
    72 
       
    73     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
       
    74     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
       
    75     var conf = {type: "PlayerWidget",
       
    76                mode: "radio",
       
    77                metadata:{
       
    78                 format:'cinelab',
       
    79                 src:'test.json',
       
    80                 type:'dummy'}
       
    81               };
       
    82 
       
    83     var res = IriSP.instantiateWidget(pop, serialFactory, layoutManager, conf);
       
    84     ok(res instanceof IriSP.PlayerWidget, "the returned widget is of the correct instance");
       
    85     equal(res._config.mode, "radio", "the parameters not interpreted by the config are copied into the object");
       
    86   });
       
    87 
       
    88   test("test the instantiation of a single widget with one dependency", function() {
       
    89     var dt = new IriSP.DataLoader();
       
    90     var serialFactory = new IriSP.SerializerFactory(dt);
       
    91 
       
    92     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
       
    93 
       
    94     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
       
    95     var conf = {type: "PlayerWidget",
       
    96                mode: "radio",
       
    97                metadata:{
       
    98                 format:'cinelab',
       
    99                 src:'../test/test.json',
       
   100                 type:'dummy'},
       
   101                 requires: [
       
   102                 {type: "PlayerWidget",
       
   103                   mode: "radio",
       
   104                   metadata:{
       
   105                     format:'cinelab',
       
   106                     src:'../test/test.json',
       
   107                     type:'dummy'
       
   108                 } }]
       
   109               };
       
   110 
       
   111 
       
   112     var res = IriSP.instantiateWidget(pop, serialFactory, layoutManager, conf);
       
   113 
       
   114     ok(res instanceof IriSP.PlayerWidget, "the returned widget is of the correct instance");
       
   115     ok(res.PlayerWidget instanceof IriSP.PlayerWidget, "the dependency widget is accessible from the parent");
       
   116   });
       
   117 
       
   118   test("test the instantiation of a bunch of widgets", function() {
       
   119 
       
   120     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
       
   121     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
       
   122     var widgets = IriSP.configureWidgets(pop, layoutManager, this.widgetOptions);
       
   123 
       
   124     ok(widgets[0] instanceof IriSP.PlayerWidget, "first widget is a player widget");
       
   125     ok(widgets[1] instanceof IriSP.SegmentsWidget, "second widget is a segments widget");
       
   126     ok(widgets[2] instanceof IriSP.AnnotationsWidget, "third widget is an annotation widget");
       
   127     equal(IriSP.jQuery("#" + this.widgetOptions.container).length, 1, "a new dom element has been created");
       
   128   });
       
   129 
       
   130   test("test the instantiation of a couple modules", function() {
       
   131       
       
   132     var layoutManager = new IriSP.LayoutManager({container: "LdtPlayer", width: 327, height: 542});
       
   133     var pop = IriSP.configurePopcorn(layoutManager, this.popcornOptions);
       
   134 
       
   135     var modules = IriSP.configureModules(pop, this.modulesOptions);
       
   136 
       
   137     ok(modules[0] instanceof IriSP.Module && modules[0]._config.a === 36);
       
   138     ok(modules[1] instanceof IriSP.Module && modules[1]._config.b === 54);
       
   139   });
       
   140 
       
   141 
       
   142 }