Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Berry <bryan@olenepal.org>2009-11-16 18:07:23 (GMT)
committer Bryan Berry <bryan@olenepal.org>2009-11-16 18:07:23 (GMT)
commit4de12e760b0f8b76d72ea28c72d8dcd67ed60d28 (patch)
tree46514e4e0e47518ac8beb1e67e0a6bb83159197b
parentf44e4c08c4629c26c2e079b132a0534d54509f3c (diff)
committing before I try taking replacing KarmaRoot w/ karma.initialized to ensure karma object is a singleton
-rwxr-xr-xjs/karma.js668
l---------tests/.#tests.js1
-rwxr-xr-xtests/tests.js171
3 files changed, 463 insertions, 377 deletions
diff --git a/js/karma.js b/js/karma.js
index 0e8fa6d..bd60c29 100755
--- a/js/karma.js
+++ b/js/karma.js
@@ -1,346 +1,388 @@
+//common.js modules use exports object
if(!this.exports) {
exports = {};
}
- var Karma = exports.Karma = function (options) {
- if ( Karma.KarmaRoot) {
- return Karma.KarmaRoot;
- } else {
- return Karma.create(Karma.karma).init(options);
- }
- };
-
- Karma.KarmaRoot = null;
-
- //helper functions, all in the Karma namespace
-
- //This emulates the Object.create method in ecmascript 5 spec
- //This isn't a full implementation as it doesn't support
- //Object.defineProperty
- //This has the same functionality as Crockford's beget method
- //and this primary building block for prototypal inheritance in
- //this library
- Karma.create = function (object){
- function F () {};
- F.prototype = object;
- return new F();
- };
-
- //this is a shallow copy
- Karma.clone = function (object){
- var copy = {};
- for ( var i in object ) {
- copy[i] = object[i];
- }
- return copy;
- };
-
- //this copies all the enumerable properties in source to target
- Karma.objectPlus = function (target, source){
- for ( var i in source){
- if (source.hasOwnProperty(i)){
- target[i] = source[i];
- }
- }
- return target;
- };
-
- //Creates a new object that is a prototype of the first argument
- // then extends it with the properties of the second argument
- Karma.copyObjectPlus = function (parent1, parent2){
- function F () {};
- F.prototype = parent1;
- var G = new F();
- return Karma.objectPlus(G, parent2);
- };
-
-
+var Karma = exports.Karma = function (options) {
+ if ( Karma.KarmaRoot) {
+ return Karma.KarmaRoot;
+ } else {
+ return Karma.create(Karma.karma).init(options);
+ }
+};
+
+Karma.KarmaRoot = null;
+
+//helper functions, all in the Karma namespace
+
+//This emulates the Object.create method in ecmascript 5 spec
+//This isn't a full implementation as it doesn't support
+//Object.defineProperty
+//This has the same functionality as Crockford's beget method
+//and this primary building block for prototypal inheritance in
+//this library
+Karma.create = function (object){
+ function F () {};
+ F.prototype = object;
+ return new F();
+};
+
+//this is a shallow copy
+Karma.clone = function (object){
+ var copy = {};
+ for ( var i in object ) {
+ copy[i] = object[i];
+ }
+ return copy;
+};
+
+//this copies all the enumerable properties in source to target
+Karma.objectPlus = function (target, source){
+ for ( var i in source){
+ if (source.hasOwnProperty(i)){
+ target[i] = source[i];
+ }
+ }
+ return target;
+};
+
+//Creates a new object that is a prototype of the first argument
+// then extends it with the properties of the second argument
+Karma.copyObjectPlus = function (parent1, parent2){
+ function F () {};
+ F.prototype = parent1;
+ var G = new F();
+ return Karma.objectPlus(G, parent2);
+};
+
+
+
+//These make* commands update the countTotalAssets and
+//countNotLoaded when they first create each asset, then
+//decrement countNotloaded as they are loaded
+Karma.makeImages = function (images){
+ /* for ( var image in images ) {
+ image._type = "image";
+
+
+ }
+ */
+};
- //These make* commands update the countTotalAssets and
- //countNotLoaded when they first create each asset, then
- //decrement countNotloaded as they are loaded
- Karma.makeImages = function (images){
+Karma.makeSounds = function (sounds){
- };
+};
- Karma.makeSounds = function (sounds){
+Karma.makeVideos = function (videos){
- };
+};
- Karma.makeVideos = function (videos){
+Karma.makeSvgs = function (svgs){
- };
+};
- Karma.makeSvgs = function (svgs){
+Karma.makeSurfaces = function (surfaces){
- };
+};
- Karma.makeSurfaces = function (surfaces){
- };
+Karma.karma = {
+ locale : undefined,
+ _localized : false,
+ _localePath : "",
+ images : [],
+ videos : [],
+ sounds : [],
+ svgs : [],
+ statusDiv: undefined,
+ _counters : { total : 0, errors : 0, loaded : 0},
+ //init initializes all the assets passed to Karma, that's it
+ //it returns 'this' so it can be used for function chaining
+ init: function(options) {
+ this.name = "karma";
+ Karma.KarmaRoot = this;
- Karma.karma = {
- locale : undefined,
- _localized : false,
- _localePath : "",
- images : [],
- videos : [],
- sounds : [],
- svgs : [],
- _counters : { total : 0, errors : 0, loaded : 0},
-
- //init initializes all the assets passed to Karma, that's it
- //it returns 'this' so it can be used for function chaining
- init: function(options) {
- this.name = "karma";
- Karma.KarmaRoot = this;
-
- //set up message that show count of assets loaded
- var loaderDiv = document.createElement('div')
- loaderDiv.innerHTML = '<div id=\"karma-loader\">Karma is \
+ //set up message that show count of assets loaded
+ var loaderDiv = document.createElement('div');
+ loaderDiv.innerHTML = '<div id=\"karma-loader\">Karma is \
loading ...<div id=\"karma-loader\" class=\"status\"></div></div>';
- document.body.appendChild(loaderDiv);
- this.statusDiv = document.getElementById("karma-loader");
+ document.body.appendChild(loaderDiv);
+ this.statusDiv = document.getElementById("karma-loader");
- //create an ordered list to hold any error messages that pop-up
- var ol = document.createElement('ol');
- this.statusDiv.appendChild(ol);
+ //create an ordered list to hold any error messages that pop-up
+ var ol = document.createElement('ol');
+ ol.setAttribute('id', 'errorList');
+ this.statusDiv.appendChild(ol);
+
+ //regular expression that matches the name of aprivate property
+ // the karma object
+ var regexPrivate = new RegExp('^_.*');
+
+ for ( var option in options ) {
+ if (option === "images" || option === "sounds" || option ===
+ "svgs" || option === "videos" || option === "surfaces"){
- //regular expression that matches the name of aprivate property
- // the karma object
- var regexPrivate = new RegExp('^_.*');
-
- for ( var option in options ) {
- if (option === "images" || option === "sounds" || option ===
- "svgs" || option === "videos" || option === "surfaces"){
-
- if(!(options[option] instanceof Array)){
- throw new Error("" + option + " must be an array");
- } else if (options[option].length === 0){
- continue;
- }
- } else if (regexPrivate.test(option)){
- //don't overwrite a private property of karma object
- continue;
- }
-
- switch (option){
- case "locale":
- if (this.isValidLocale(options[option])){
- this.locale = this.normalizeLocale(options[option]);
- this._localized = true;
- options._localePath = computeLocalePath(this.locale);
- } else {
- throw new Error("locale provided to karma.init() is invalid");
- }
-
- break;
- case "images":
- options[option]._type = 'image';
- Karma.makeImages(options[option]);
- break;
- case "sounds":
- options[option]._type = 'sound';
- Karma.makeSounds(options[option]);
- break;
- case "videos":
- options[option]._type = 'video';
- Karma.makeVideos(options[option]);
- break;
- case "svgs":
- options[option]._type = 'svg';
- Karma.makeSvgs(options[option]);
- break;
- case "surfaces":
- options[option]._type = 'surface';
- Karma.makeSurfaces(options[option]);
- break;
- }
+ if(!(options[option] instanceof Array)){
+ throw new Error("" + option + " must be an array");
+ } else if (options[option].length === 0){
+ continue;
}
- return this;
- },
+ } else if (regexPrivate.test(option)){
+ //don't overwrite a private property of karma object
+ continue;
+ }
- //ready checks to see if all assets loaded, then runs lesson code
- ready : function( cb ) {
- that = this;
- if (!Karma.KarmaRoot){
- throw new Error("Karma.karma not initialized");
- }
-
- if (this._counters.loaded !== this._counters.total){
- setTimeout(function(){ that.ready(cb);}, 100);
- } else if (cb) {
- //hide that loader status
- this.statusDiv.setAttribute('style', 'display:none;');
- cb();
- } else if (!cb) {
- //if no options passed, show it works message
- this.showStarterMessage();
- }
-
- return this;
- },
-
- //Display Apache-like "It works" message if no options
- showStarterMessage : function (){
- var starterMsg = document.createElement('div');
- starterMsg.setAttribute('id', 'starterMsg');
- starterMsg.innerHTML = "<h1>It Works</h1>";
- document.body.appendChild(starterMsg);
- },
-
- statusUpdate : function (errorMsg) {
- var loaded = this._counters.loaded;
- var total = this._counters.total;
- var errors = this._counters.total;
- this.statusDiv.innerText = "" + loaded + "/" total +
- (errors > 0 ? " [ "+errors+" ]":'');
- if (errorMsg) {
- var liError = document.createElement('li');
- liError.innerText = errorMsg;
- this.statusDiv.ol.appendChild(liError);
+ switch (option){
+ case "locale":
+ if (this.isValidLocale(options[option])){
+ this.locale = this.normalizeLocale(options[option]);
+ this._localized = true;
+ options._localePath = Karma.computeLocalePath(this.locale);
+ } else {
+ throw new Error("locale provided to karma.init() is invalid");
}
- },
-
- isValidLocale : function (locale) {
- //matches 2 letter country code then optionally
- //a dash or underscore followed by a country or language identifier
- //i currently only allow a language identifier 2-3 chars long
-
- localeRegex = new RegExp('^[a-zA-Z][a-zA-Z]([-_][a-zA-z]{2,3})?$');
- return localeRegex.test(locale);
- },
-
- normalizeLocale : function(locale) {
- var lang = "";
- var country = "";
- var divider = "";
-
- lang = locale.slice(0, 2).toLowerCase();
- divider = "_";
- country = locale.slice(3, 6).toUpperCase();
- return locale.length > 2 ? "" + lang + divider + country : lang;
- },
-
-
- };
+ break;
+ case "images":
+ options[option]._type = 'image';
+ Karma.makeImages(options[option]);
+ break;
+ case "sounds":
+ options[option]._type = 'sound';
+ Karma.makeSounds(options[option]);
+ break;
+ case "videos":
+ options[option]._type = 'video';
+ Karma.makeVideos(options[option]);
+ break;
+ case "svgs":
+ options[option]._type = 'svg';
+ Karma.makeSvgs(options[option]);
+ break;
+ case "surfaces":
+ options[option]._type = 'surface';
+ Karma.makeSurfaces(options[option]);
+ break;
+ }
+ }
+ return this;
+ },
+
+ //ready checks to see if all assets loaded, then runs lesson code
+ ready : function( cb ) {
+ that = this;
+ if (!Karma.KarmaRoot){
+ throw new Error("Karma.karma not initialized");
+ }
+ if (this._counters.loaded !== this._counters.total){
+ setTimeout(function(){ that.ready(cb);}, 100);
+ } else if (cb) {
+ //hide that loader status
+ this.statusDiv.setAttribute('style', 'display:none;');
+ cb();
+ } else if (!cb) {
+ //if no options passed, show it works message
+ this.showStarterMessage();
+ }
- Karma.kMedia = {
- name : "",
- file : "",
- path : "",
- localized : false,
- _type : "",
- media : undefined,
-
- init : function (asset) {
- Karma.KarmaRoot._counters.total++;
-
- if (asset.name === undefined || asset.file === undefined){
- throw new Error("properties name and file have to be defined");
- } else {
- this.name = asset.name;
- this.file = asset.file;
+ return this;
+ },
+
+ //Display Apache-like "It works" message if no options
+ showStarterMessage : function (){
+ var starterMsg = document.createElement('div');
+ starterMsg.setAttribute('id', 'starterMsg');
+ starterMsg.innerHTML = "<h1>It Works</h1>";
+ document.body.appendChild(starterMsg);
+ },
+
+ updateStatus : function (errorMsg) {
+ var loaded = this._counters.loaded;
+ var total = this._counters.total;
+ var errors = this._counters.total;
+ this.statusDiv.innerText = "" + loaded + " / " + total +
+ "" + (errors > 0 ? " [ "+errors+" ]" : '');
+ if (errorMsg) {
+ var liError = document.createElement('li');
+ liError.innerText = errorMsg;
+ var errorList = document.getElementById('errorList');
+ errorList.appendChild(liError);
+ }
+ },
+
+ isValidLocale : function (locale) {
+ //matches 2 letter country code then optionally
+ //a dash or underscore followed by a country or language identifier
+ //i currently only allow a language identifier 2-3 chars long
+
+ localeRegex = new RegExp('^[a-zA-Z][a-zA-Z]([-_][a-zA-z]{2,3})?$');
+ return localeRegex.test(locale);
+ },
+ normalizeLocale : function(locale) {
+ var lang = "";
+ var country = "";
+ var divider = "";
+
+ lang = locale.slice(0, 2).toLowerCase();
+ divider = "_";
+ country = locale.slice(3, 6).toUpperCase();
+
+ return locale.length > 2 ? "" + lang + divider + country : lang;
+ },
+
+};
+
+
+Karma.kMedia = {
+ name : "",
+ file : "",
+ path : "",
+ localized : false,
+ _type : "",
+ media : undefined,
+
+ init : function (asset) {
+
+ Karma.KarmaRoot._counters.total++;
+
+ asset.localized = asset.localized || false;
+
+ if (asset.name === undefined || asset.file === undefined){
+ throw new Error("properties name and file have to be defined");
+ } else {
+ this.name = asset.name;
+ this.file = asset.file;
+ }
+
+ //_type is a private variable used internally
+ if (asset._type === undefined){
+ throw new Error("the _type property must be set. " +
+ "Blame the karma library authors as this is an internal value");
+ } else {
+ if (Karma.isValidType(asset._type)){
+ this._type = asset._type;
+ switch ( this._type ) {
+ case "image": this.media = new Image();
+ break;
+ case "sound": this.media = new Audio();
+ break;
+ case "svg":
+ //this.media = new Audio();
+ break;
+ default: throw new Error ("Media type not supported");
}
- //_type is a private variable used internally
- if (asset._type === undefined){
- throw new Error("the _type property must be set. " +
- "Blame the karma library authors as this is an internal value");
- } else {
- if (Karma.isValidType(asset._type)){
- this._type = asset._type;
- switch ( this._type ) {
- case "image": this.media = new Image();
- break;
- case "sound": this.media = new Audio();
- break;
- case "svg":
- //this.media = new Audio();
- break;
- default: throw new Error ("Media type not supported");
- }
-
- } else {
- throw new Error("the _type property supplied is invalid. " +
- "Blame the karma library authors as this is an internal value");
- }
- }
-
- if(Karma.isLocalized(asset.localized)){
- this.localized = asset.localized;
- this.path = Karma.computeLocalePath(Karma.KarmaRoot.locale) +
- this.type + "s/";
- }
-
- //IMPORTANT: This one magic line loads the file
- this.media.src = this.src = this.path + this.file;
-
- //add event handlers
- addEventHandlers(this);
-
- return this;
- },
- addEventHandlers : function (kmedia) {
- var elemKarma = document.getElementById('karma-loader');
- kmedia.media.addEventListener(
- "load",
- function (e) {
- Karma.KarmaRoot._counters.loaded++;
- Karma.KarmaRoot.updateMessage();
- kmedia.status = "loaded";}, false);
- kmedia.media.addEventListener(
- "error",
- function (e) {
- Karma.KarmaRoot._counters.errors++;
- kmedia.status = "error";
- var errorMsg = "Error: " + kmedia._type.toUpperCase() +
- " " + kmedia.name + " cannot be loaded.";
- Karma.KarmaRoot.updateMessage(errorMsg);
- },
- false);
- kmedia.media.addEventListener(
- "abort",
- function (e) {
- kmedia.status = "aborted";
- var errorMsg = "ABORT: " + kmedia._type.toUpperCase() +
- " " + kmedia.name + " loading was aborted.";
- Karma.KarmaRoot.updateMessage(errorMsg);
-
- }, false);
-
- },
- };
-
- Karma.isValidType = function (type){
- var regex = new RegExp('^(image||svg||sound||video||surface)$');
- return regex.test(type);
- };
-
- Karma.isLocalized = function (boolLocalized) {
- if (typeof boolLocalized === "boolean" ) {
- if(boolLocalized === true &&
- Karma.KarmaRoot.locale === undefined){
- throw new Error("You cannot localize a media asset" +
- " if the global locale for Karma isn't set");
- } else {
- return true;
- }
- } else if (typeof boolLocalized === undefined){
- return false;
- } else{
- throw new Error("This is not a valid value for the localized option");
+ } else {
+ throw new Error("the _type property supplied is invalid. " +
+ "Blame the karma library authors as this is an internal value");
}
- };
-
- Karma.computeLocalePath = function(locale) {
- return "../assets/" + locale + "/";
- };
+ }
+
+ if(Karma.isLocalized(asset.localized)){
+ this.localized = asset.localized;
+ this.path = Karma.computeLocalePath(Karma.KarmaRoot.locale) +
+ this.type + "s/";
+ }
+
+ //IMPORTANT: This one magic line loads the file
+ this.media.src = this.src = this.path + this.file;
+
+ //add event handlers
+ this.addEventHandlers(this);
+
+ return this;
+ },
+ addEventHandlers : function (kmedia) {
+ var elemKarma = document.getElementById('karma-loader');
+ kmedia.media.addEventListener(
+ "load",
+ function (e) {
+ Karma.KarmaRoot._counters.loaded++;
+ Karma.KarmaRoot.updateStatus();
+ kmedia.status = "loaded";}, false);
+ kmedia.media.addEventListener(
+ "error",
+ function (e) {
+ Karma.karma._counters.errors++;
+ kmedia.status = "error";
+ var errorMsg = "Error: " + kmedia._type.toUpperCase() +
+ " " + kmedia.name + " cannot be loaded.";
+ Karma.KarmaRoot.updateStatus(errorMsg);
+ },
+ false);
+ kmedia.media.addEventListener(
+ "abort",
+ function (e) {
+ kmedia.status = "aborted";
+ var errorMsg = "ABORT: " + kmedia._type.toUpperCase() +
+ " " + kmedia.name + " loading was aborted.";
+ Karma.KarmaRoot.updateStatus(errorMsg);
+
+ }, false);
+
+ },
+ //cleans up the stuff that init creates
+ //used in unit testing
+ cleanup : function () {
+ var karmaLoader = document.getElementById('karma-loader');
+ //karmaLoader.parent.remove
+
+ },
+};
+
+Karma.surface = {
+ width: 0,
+ height: 0,
+ visible: true,
+ elemId: undefined,
+ node: undefined,
+ fps: 24,
+ init: function () {
+
+ },
+
+};
+
+
+Karma.svg = {
+ width: 0,
+ height: 0,
+ visible: true,
+ elemId: undefined,
+ node: undefined,
+ init: function () {
+
+ },
+};
+
+Karma.isValidType = function (type){
+ var regex = new RegExp('^(image||svg||sound||video||surface)$');
+ return regex.test(type);
+};
+
+Karma.isLocalized = function (boolLocalized) {
+ if (typeof boolLocalized === "boolean" ) {
+ if(boolLocalized === true &&
+ Karma.KarmaRoot.locale === undefined){
+ throw new Error("You cannot localize a media asset" +
+ " if the global locale for Karma isn't set");
+ } else {
+ return true;
+ }
+ } else if (typeof boolLocalized === undefined){
+ return false;
+ } else{
+ throw new Error("This is not a valid value for the localized option");
+ }
+};
+
+Karma.computeLocalePath = function(locale) {
+ return "../assets/" + locale + "/";
+};
diff --git a/tests/.#tests.js b/tests/.#tests.js
new file mode 120000
index 0000000..4ddf3c8
--- /dev/null
+++ b/tests/.#tests.js
@@ -0,0 +1 @@
+hitman@hitman.15668:1258379610 \ No newline at end of file
diff --git a/tests/tests.js b/tests/tests.js
index 252b49c..7ce64d0 100755
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -133,6 +133,7 @@
ok(shouldNotError(function () { karma5.init(goodOptions);}),
"accepts good options");
+
var badOptions = {locale : "en", images : [{ name: "chimp",
file : 'chimp.png' }],
sounds : [{ name: "correct", file : 'notthere.ogg'}],
@@ -234,10 +235,10 @@
*
*/
- ok(Karma.karma.computeLocalePath("en_US") ===
+ ok(Karma.computeLocalePath("en_US") ===
"../assets/en_US/", "computes correct path");
- ok(Karma.karma.computeLocalePath("es") ===
+ ok(Karma.computeLocalePath("es") ===
"../assets/es/", "computes correct path");
});
@@ -248,96 +249,138 @@
});
- test("Karma.kMedia.init()",
+ /* list of tests for kMedia.init
+ *
+ * throw error if type, name, and file not specified
+ *
+ * for file that doesn't exist
+ * status set to error
+ * increment _conters.total
+ * increment _counters.errors
+ * error msg appended to karma-loader
+ *
+ * for file that does exist
+ * status set to loaded
+ * increment _counters.total and _counters.loaded
+ * updates karma-loader correctly
+ *
+ * repeat above tests for localized media
+ *
+ * emit error if locale not set but asset has localized set to true
+ *
+ */
+
+ test("Karma.kMedia.init({})",
function () {
- /* list of tests
- *
- * throw error if type, name, and file not specified
- *
- * for file that doesn't exist
- * status set to error
- * increment _conters.total
- * increment _counters.errors
- * error msg appended to karma-loader
- *
- * for file that does exist
- * status set to loaded
- * increment _counters.total and _counters.loaded
- * updates karma-loader correctly
- *
- * repeat above tests for localized media
- *
- * emit error if locale not set but asset has localized set to true
- *
- */
-
-
var kMock = Karma.create(Karma.kMedia);
ok(shouldError(
function(){
kMock.init({});
}), "Throw error if _type, name, or file not specified");
+ });
+
+ var kMedia1 = Karma.create(Karma.kMedia);
+
+ if(Karma.KarmaRoot){
+ delete Karma.KarmaRoot;
+ }
- var kMedia1 = Karma.create(Karma.karma.kMedia);
- var oldErrors = Karma.karma._counters.errors;
- var oldTotal = Karma.karma._counters.total;
- kMedia1.init({name: "notthere", _type : "image",
+ Karma.KarmaRoot = Karma.create(Karma.karma).init({});
+ var oldErrors = Karma.KarmaRoot._counters.errors;
+ var oldTotal = Karma.KarmaRoot._counters.total;
+ kMedia1.init({name: "notthere", _type : "image",
file: "notthere.png"});
+
+ //have to do this asynchronously let the error event propagate
+ setTimeout(
+ function(){
+
+
+ test("Karma.kMedia.init(/* bad options */)",
+ function (){
ok(kMedia1.status === "error", "bad file name produces error");
- ok(Karma.karma._counters.errors === oldErrors + 1 ,
+ ok(Karma.KarmaRoot._counters.errors === oldErrors + 1 ,
"Error counter was incremented on load error");
- ok(Karma.karma._counters.total === oldTotal + 1 ,
+ ok(Karma.KarmaRoot._counters.total === oldTotal + 1 ,
"Total Assets counter was incremented");
var errorMsg = $('#karma-loader>ol>li').text();
ok(errorMsg === "ERROR: File notthere.png could not be loaded",
"correct error message appended");
-
- oldErrors = Karma.karma._counters.errors;
- oldTotal = Karma.karma._counters.total;
- kMock = { name: "chimp", _type: "image", file: "happyMonkey"};
- kMedia1 = Karma.create(Karma.karma.kMedia).init(kMock);
- ok(kMedia1.status === "loaded", "Good file is loaded");
- ok(Karma.karma.counterrors === oldErrors,
- "Error counter not incremented");
- ok(Karma.karma._counters.total === oldTotal + 1 ,
- "Total Assets counter was incremented");
-
- kMock = Karma.create(Karma.kMedia);
- Karma.karma.locale = undefined;
+
+ });
+ }, 100);
+
+
+ oldErrors = Karma.KarmaRoot._counters.errors;
+ oldTotal = Karma.KarmaRoot._counters.total;
+ kMock = { name: "chimp", _type: "image", file: "happyMonkey"};
+ kMedia1 = Karma.create(Karma.kMedia).init(kMock);
+
+ setTimeout(
+ function(){
+ test("Karma.kMedia.init(/* good options */)",
+ function () {
+ ok(kMedia1.status === "loaded", "Good file is loaded");
+ ok(Karma.KarmaRoot.counterrors === oldErrors,
+ "Error counter not incremented");
+ ok(Karma.KarmaRoot._counters.total === oldTotal + 1 ,
+ "Total Assets counter was incremented");});
+ }, 100);
+
+ kMock = Karma.create(Karma.kMedia);
+ Karma.karma.locale = undefined;
+
+ test("Karma.kMedia.init( /* localize an asset when locale not set */)",
+ function(){
ok(shouldError(
function () {
kMock.init({ name: 'esMonkey', file: 'HappyMonkey.jpg',
- _type: 'image', localized: true });
+ _type: 'image', localized: true });
}),
- "You can't localize an asset if the locale isn't defined for your lesson");
+ "You can't localize an asset if the locale isn't defined for your lesson");
+ });
- kMock = Karma.create(Karma.kMedia);
- oldErrors = Karma.karma._counters.errors;
- oldTotal = Karma.karma._counters.total;
- kMock.init({ name : 'trigger', file : 'trigger.ogg',
- _type : "sound", localized : true});
- ok(kMock.status === "error", "Asset has status properly set to error");
- ok(Karma.karma._counters.errors === oldErrors + 1,
+ /* kMock = Karma.create(Karma.kMedia);
+ oldErrors = Karma.karma._counters.errors;
+ oldTotal = Karma.karma._counters.total;
+ kMock.init({ name : 'trigger', file : 'trigger.ogg',
+ _type : "sound", localized : true});
+
+ setTimeout(
+ function(){
+ test("Karma.kMedia.init( localized asset)",
+ function () {
+ ok(kMock.status === "error", "Asset has status properly set to error");
+ ok(Karma.karma._counters.errors === oldErrors + 1,
"Loading a localized file emits an error event if a localized version doesn't exist");
- ok(Karma.karma._counters.total === oldTotal + 1 ,
+ ok(Karma.karma._counters.total === oldTotal + 1 ,
"Total Assets counter was incremented");
-
- kMock = Karma.create(Karma.kMedia);
- oldErrors = Karma.karma._counters.errors;
- oldTotal = Karma.karma._counters.total;
- kMock.init({ name : 'monkey', file : 'happyMonkey.jpg',
- _type : "image", localized : true});
- ok(Karma.karma._counters.errors === oldErrors,
+ });
+ },100);
+ */
+
+ kMock = Karma.create(Karma.kMedia);
+ oldErrors = Karma.karma._counters.errors;
+ oldTotal = Karma.karma._counters.total;
+ kMock.init({ name : 'monkey', file : 'happyMonkey.jpg',
+ _type : "image", localized : true});
+
+ setTimeout(
+ function(){
+ test( function(){
+ ok(Karma.KarmaRoot._counters.errors === oldErrors,
"Properly loads localized file");
- ok(Karma.karma._counters.total === oldTotal + 1 ,
+ ok(Karma.KarmaRoot._counters.total === oldTotal + 1 ,
"Total Assets counter was incremented");
- });
+ });
+ }, 100);
+
test("Karma.isLocalized(boolLocalized)",
- function(){
+ function(){
/*
* reject non-boolean values
*