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