]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#674] Implementation tests
authorRick Waldron <waldron.rick@gmail.com>
Tue, 2 Aug 2011 21:09:26 +0000 (17:09 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Tue, 2 Aug 2011 21:09:26 +0000 (17:09 -0400)
test/popcorn.unit.js

index 7d19d05a0e742c451e117c6a31b99e6f5520878c..e4a4f9323714c9681b0e5bf4fbd8602879851dc6 100644 (file)
@@ -500,7 +500,7 @@ test("roundTime", function () {
 
 });
 
-  
+
 test("exec", function () {
 
   QUnit.reset();
@@ -724,6 +724,81 @@ test("Popcorn.events.hooks: canplayall fires immediately if ready", function() {
 </video>
 
 */
+module("Popcorn Locale");
+
+test( "Popcorn.locale object", function() {
+
+       var api = {
+               get: "function",
+               set: "function",
+               broadcast: "function"
+       },
+       locale = navigator.language,
+       parts = locale.split("-"),
+
+       stub = {
+               i18n: locale,
+               language: parts[ 0 ],
+               region: parts[ 1 ]
+       },
+       $pop = Popcorn("#video"),
+       expects = 12,
+       count = 0;
+
+  expect( expects );
+
+  function plus() {
+    if ( ++count == expects ) {
+      start();
+    }
+  }
+
+  stop( 10000 );
+
+       ok( Popcorn.locale, "Popcorn.locale exists");
+       plus();
+
+       equal( typeof Popcorn.locale, "object", "Popcorn.locale is an object");
+       plus();
+
+       Popcorn.forEach( api, function( type, method ) {
+               ok( Popcorn.locale[ method ], Popcorn.locale[ method ] + " exists" );
+               plus();
+               equal( typeof Popcorn.locale[ method ], type, Popcorn.locale[ method ] + " is a " + type );
+               plus();
+       });
+
+       deepEqual( Popcorn.locale.get(), stub, "Popcorn.locale.get() === navigator.language (" +  JSON.stringify(stub) +  ") whenever possible" );
+       plus();
+
+       Popcorn.forEach( Popcorn.locale.get(), function( val, prop ) {
+               equal( val, stub[ prop ], "locale matches stub" );
+               plus();
+       });
+
+
+       Popcorn.locale.set("fr-CA");
+
+
+       $pop.listen("locale:changed", function() {
+
+               var locale = "fr-CA",
+               parts = locale.split("-"),
+    stub = {
+                       i18n: locale,
+                       language: parts[ 0 ],
+                       region: parts[ 1 ]
+               };
+
+               Popcorn.forEach( Popcorn.locale.get(), function( val, prop ) {
+                       equal( val, stub[ prop ], "locale matches updated stub" );
+                       plus();
+               });
+       });
+
+
+});
+
 
 module("Popcorn Position");
 test("position", function () {
@@ -1330,9 +1405,9 @@ test("Start Zero Immediately", function () {
     end: function() {}
   });
 
-  $pop.zero({ 
-    start:0, 
-    end: 2 
+  $pop.zero({
+    start:0,
+    end: 2
   });
 });
 test("Update Timer", function () {