From ae7313eb6505c4e3ef0be3df73d7f2f87bffd07c Mon Sep 17 00:00:00 2001 From: Bryan Berry Date: Fri, 13 Nov 2009 18:55:19 +0000 Subject: added more tests --- diff --git a/js/jquery.karma.js b/js/jquery.karma.js index bce3cd5..8e69151 100755 --- a/js/jquery.karma.js +++ b/js/jquery.karma.js @@ -951,9 +951,9 @@ var KMedia = Class( this.path = undefined; this.media = undefined; switch ( this.type ) { - case "image": this.media = new Image(); break; - case "sound": this.media = new Audio(); break; - default: throw new Error ("Media type not supported"); + case "image": this.media = new Image(); break; + case "sound": this.media = new Audio(); break; + default: throw new Error ("Media type not supported"); } this.path = gk.paths[ this.type + "s" ][ this.localized ? "localized": "generic" diff --git a/js/karma.js b/js/karma.js index ae4550e..12f9472 100755 --- a/js/karma.js +++ b/js/karma.js @@ -1,45 +1,21 @@ -/* -* Karma Framework -* http://karmaeducation.org -* -* This code is licensed under the MIT open-source license -* Copyright (c) 2009 -* Felipe López Toledo zer.subzero@gmail.com -* Bryan W Berry bryan@olenepal.org -* -*/ - -/** -* @fileOverview Contains karma library -* @version 0.2 -* @authors Felipe Lopez Toledo , Bryan Berry -*/ - - -/** - * See jQuery. - * @name jQuery - * @exports $ as jQuery -*/ - - //this.exports is used by narwhal but undefined in other contexts - if(!this.exports) { - exports = {}; - } - - var KarmaRoot; - - var Karma = exports.Karma = function (options) { - KarmaRoot; - if ( this.KarmaRoot) { - return KarmaRoot; - } else { - KarmaRoot = Karma.create(Karma.karma) - return KarmaRoot.init(options); - } - }; - //helper functions, all in the Karma namespace + +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 @@ -82,10 +58,6 @@ }; - //counter that records if some assets are still waiting to be loaded - Karma.countAssetsLoaded = 0; - Karma.countAssetsTotal = 0; - //These make* commands update the countTotalAssets and //countNotLoaded when they first create each asset, then @@ -112,28 +84,21 @@ Karma.karma = { - locale : "", + locale : undefined, + _localized : false, + _localePath : "", images : [], videos : [], sounds : [], svgs : [], - _countAssetsLoaded: 0, - _countAssetsTotal: 0, - _countAssetsErrors: 0, + _counters : { total : 0, errors : 0, loaded }, //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; - //if no options passed, we are done! - if(!options) { - this.showStarterMessage(); - return this; - } - - options.localized = this.checkLocalized(options); - //set up message that show count of assets loaded var loaderDiv = document.createElement('div') loaderDiv.innerHTML = '
Karma is \ @@ -146,12 +111,11 @@ 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"); + throw new Error("" + option + " must be an array"); } else if (options[option].length === 0){ continue; } @@ -160,46 +124,62 @@ 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": + Karma.makeImages(options[option]); + break; + case "sounds": + Karma.makeSounds(options[option]); + break; + case "videos": + Karma.makeVideos(options[option]); + break; + case "svgs": + Karma.makeSvgs(options[option]); + break; + case "surfaces": + Karma.makeSurfaces(options[option]); + break; + } } - - switch (option){ - case "locale": - options.locale = sanitizeLocale(options[option]); - break; - case "images": - Karma.makeImages(options[option]); - break; - case "sounds": - Karma.makeSounds(options[option]); - break; - case "videos": - Karma.makeVideos(options[option]); - break; - case "svgs": - Karma.makeSvgs(options[option]); - break; - case "surfaces": - Karma.makeSurfaces(options[option]); - break; - } - - return this; + return this; }, //ready checks to see if all assets loaded, then runs lesson code ready : function( cb ) { - if (this.countAssetsLoaded !== this.countAssetsTotal){ - setTimeout(function(){this.ready(cb);}, 100); + 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) { - //remove that loader status - document.body.removeChild(this.statusDiv); + //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 = "

It Works

"; document.body.appendChild(starterMsg); }, @@ -208,17 +188,58 @@ this.statusDiv.innerHTML = "" + current + "/" + total + (error > 0 ? " [ "+error+" ]":''); }, - checkLocalized : function (options) { - if (options.localized && typeof options.localized === "boolean" ) { - return localized; - } - return false; + + + 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); }, - - sanitizeLocale : function() { + + 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; + }, + + computeLocalePath : function(locale) { + return "../assets/" + locale + "/"; }, }; - - + + +Karma.kMedia = { + name : "", + fileName : "", + path : "", + localized : false, + type : "", + media : undefined, + + init : function () { + + + + } +}; + +Karma.checkLocalized = function (options) { + if (options.localized && typeof options.localized === "boolean" ) { + return localized; + } else { + throw new Error("This is not a valid value for the localized option"); + } +}; + + diff --git a/tests/assets/es/images/happyMonkey.jpg b/tests/assets/es/images/happyMonkey.jpg new file mode 100755 index 0000000..bfe0d38 --- /dev/null +++ b/tests/assets/es/images/happyMonkey.jpg Binary files differ diff --git a/tests/assets/images/happyMonkey.jpg b/tests/assets/images/happyMonkey.jpg new file mode 100755 index 0000000..bfe0d38 --- /dev/null +++ b/tests/assets/images/happyMonkey.jpg Binary files differ diff --git a/tests/assets/sounds/trigger.ogg b/tests/assets/sounds/trigger.ogg new file mode 100755 index 0000000..f22512a --- /dev/null +++ b/tests/assets/sounds/trigger.ogg Binary files differ diff --git a/tests/assets/svgs/uruguay.svg b/tests/assets/svgs/uruguay.svg new file mode 100755 index 0000000..5f9d64a --- /dev/null +++ b/tests/assets/svgs/uruguay.svg @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/tests.js b/tests/tests.js index 969cd98..6e03d5d 100755 --- a/tests/tests.js +++ b/tests/tests.js @@ -1,265 +1,363 @@ - $(document).ready(function(){ - var hasProperties = function (properties) { - for ( prop in properties) { - if (!this[prop]){ - return false; + $(document).ready( + function(){ + var hasProperties = function (properties) { + for ( prop in properties) { + if (!this[prop]){ + return false; + } + else { + return true; + } } - else { - return true; - } - } - }; - - var shouldError = function (errorFactory){ - - errorFactory.args = errorFactory.args || []; - errorFactory.ctx = errorFactory.ctx || this; + }; - try { - errorFactory.func.apply(errorFactory.ctx, - errorFactory.args); - } catch (err){ - if (errorFactory.err) { - return errorFactory.err === err; - } else { + var shouldError = function ( cb, expectedError ){ + try { + cb(); + } catch (e){ + if (expectedError){ + if (e.name === expectedError.name) { + return true; + } else { + return false; + } + } return true; } - - return false; + return false; }; - }; - var shouldNotError = function () { - return !shouldError(arguments); - }; - - var getFile = function (fileName){ - var xhr = new XMLHttpRequest(); - xhr.open('GET', options.images[0].file, false); - xhr.send(''); - return xhr; - }; - - - module("Module Helpers"); - - test("Basic Requirements", function() { - ok( Karma, "Karma library loaded"); - ok( Array.prototype.push, "Array.push()" ); - ok( Function.prototype.apply, "Function.apply()" ); - ok( document.getElementById, "getElementById" ); - ok( document.getElementsByTagName, "getElementsByTagName" ); - }); - - test("Karma.create", function(){ - var mock = {}; - //test against empty object - same(Karma.create({}), mock, "doesn't match empty object"); - mock.age = 30; - mock1 = Karma.create(mock); - equals(mock.age, mock1.age, "child object inherits property"); - - }); - - test("Karma.clone", function(){ - var mock = { name: "foo", age: 30, children : ["adrian", "sheila", - "stephanie"], spouse: { wife: "Marie"}}; - same(Karma.clone(mock), mock, - "cloned object matches original"); - mock.spouse.wife = "Marjorie"; - same(Karma.clone(mock), mock, - "cloned object matches original after original changed after cloning"); - - }); - - test("Karma.objectPlus", function(){ - var warrior = { name : "conan", age : 30, dance : true}; - var oldProto = warrior.__proto__; - var ninja = { dance : false, tattoo : true}; - var newProto = warrior.__proto__; - - Karma.objectPlus(warrior, ninja); - ok ( warrior.dance === ninja.dance && warrior.tattoo - === ninja.tattoo, "target object wasn't updated with source"); - ok ( oldProto === newProto, "the object prototype changed."); - }); - - test("Karma.copyObjectPlus", function(){ - var warrior = { name : "conan", age : 30, dance : true}; - var copyWarrior = Karma.clone(warrior); - var ninja = { dance : false, name : "Yoshi"}; - - ninja1 = Karma.copyObjectPlus(warrior, ninja); - - ok ( ninja1.dance === ninja.dance && ninja1.age === warrior.age && - ninja1.name === ninja.name, - "target object wasn't updated with source"); - ok ( warrior.__proto__.isPrototypeOf(ninja1), - "the protoypeObject changed"); - - }); - - - module("Module Karma core library"); - - test("Karma()", function () { + var shouldNotError = function ( cb ) { + return !shouldError( cb ); + }; - same(Karma.create(Karma.karma).init(), Karma(), - "Karma() w/ no arguments returns the karma object");} - ); - - - var options = {locale: "en-US", - images: [ {name: "monkey", file: "happyMonkey.jpg"}], - sounds: [ {name: "trigger", file: "trigger.ogg"}], - svgs: [ {name: "uruguay", file: "uruguay.svg"}], - surfaces: [ {name:"testCanvas", canvas:"testCanvas"}]}; + var getFile = function (fileName){ + var xhr = new XMLHttpRequest(); + xhr.open('GET', options.images[0].file, false); + xhr.send(''); + return xhr; + }; + + module("Module Helpers"); + + test("Basic Requirements", function() { + ok( Karma, "Karma library loaded"); + ok( Array.prototype.push, "Array.push()" ); + ok( Function.prototype.apply, "Function.apply()" ); + ok( document.getElementById, "getElementById" ); + ok( document.getElementsByTagName, "getElementsByTagName" ); + }); + + test("Karma.create", function(){ + var mock = {}; + //test against empty object + same(Karma.create({}), mock, "doesn't match empty object"); + mock.age = 30; + var mock1 = Karma.create(mock); + equals(mock.age, mock1.age, "child object inherits property"); + + }); + + test("Karma.clone", function(){ + var mock = { name: "foo", age: 30, children : ["adrian", "sheila", + "stephanie"], spouse: { wife: "Marie"}}; + same(Karma.clone(mock), mock, + "cloned object matches original"); + mock.spouse.wife = "Marjorie"; + same(Karma.clone(mock), mock, + "cloned object matches original after original changed after cloning"); + + }); + + test("Karma.objectPlus", function(){ + var warrior = { name : "conan", age : 30, dance : true}; + var oldProto = warrior.__proto__; + var ninja = { dance : false, tattoo : true}; + var newProto = warrior.__proto__; + + Karma.objectPlus(warrior, ninja); + ok ( warrior.dance === ninja.dance && warrior.tattoo + === ninja.tattoo, "target object wasn't updated with source"); + ok ( oldProto === newProto, "the object prototype changed."); + }); - //test that entered options reflected in returned karma object - test("Karma(options)", function () { - var karma1 = Karma(options); - ok(karma1.images[0].name === "ball", "image name set properly"); - var karma2 = Karma.create(Karma.karma).init(options); - same(karma1, karma2, "Karma() returns same object as running init on Karma.karma"); - ok(karma1.locale === options.locale, "locale set"); - var canvasElem = document.getElementById(options.surfaces.canvas); - ok(karma1.surfaces[0].canvas === canvasElem, "Canvas element matches original"); - - //check that asset files match originals - //have to do this asynchronously to wait until the files are all loaded - setTimeout(function () { - var imageFile = getFile(options.images[0].file).responseText; - same(imageFile, karma1.images[0].toString(), "Returned image matches original"); - var soundFile = getFile(options.sounds[0].file).responseText; - same(soundFile, karma1.sounds[0].toString(), "Returned image matches original"); - var svgFile = getFile(options.svgs[0].file).responseText; - same(svgFile, karma1.svg[0].toString(), "Returned image matches original"); - }, 2000); - }); - - test("Karma.karma", function () { - var options; - karma1 = Karma.create(Karma.karma); - - }); - - test("Karma.karma.init()", function() { - var goodOptions = {locale : "en", images : [{ name: "chimp", - file : 'chimp.png' }], - sounds : [{ name: "correct", file : 'correct.ogg'}], - surfaces : [{ name: "test", canvas : 'testCanvas'}]}; + test("Karma.copyObjectPlus", function(){ + var warrior = { name : "conan", age : 30, dance : true}; + var copyWarrior = Karma.clone(warrior); + var ninja = { dance : false, name : "Yoshi"}; + + var ninja1 = Karma.copyObjectPlus(warrior, ninja); + + ok ( ninja1.dance === ninja.dance && ninja1.age === warrior.age && + ninja1.name === ninja.name, + "target object wasn't updated with source"); + ok ( warrior.__proto__.isPrototypeOf(ninja1), + "the protoypeObject changed"); + + }); + + + module("Module Karma core library"); - var karma5 = Karma.create(Karma.karma); - ok(shouldNotError(karma5.init(goodOptions)), "accepts good options"); + test("Karma()", function () { + + same(Karma.create(Karma.karma).init(), Karma(), + "Karma() w/ no arguments returns the karma object"); + }); - var badOptions = {locale : "en", images : [{ name: "chimp", - file : 'chimp.png' }], - sounds : [{ name: "correct", file : 'notthere.ogg'}], - surfaces : [{ name: "", canvas : 'noCanvas'}]}; - ok(shouldError(karma5.init(badOptions), "Rejects bad options")); - }); + test("Karma.karma", function () { + var options; + var karma1 = Karma.create(Karma.karma); + + }); + + test("Karma.karma.init()", function() { + + Karma.KarmaRoot = undefined; + var karma1 = Karma.create(Karma.karma).init(); + ok(Karma.KarmaRoot , "Karma.karma.init() creates KarmaRoot object"); + + ok(shouldError(function () { + karma1.init({locale : "foo"});}), + "emits error on invalid locale"); + + var goodOptions = {locale : "en", images : [{ name: "chimp", + file : 'chimp.png' }], + sounds : [{ name: "correct", file : 'correct.ogg'}], + surfaces : [{ name: "test", canvas : 'testCanvas'}]}; + + var karma5 = Karma.create(Karma.karma); + 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'}], + surfaces : [{ name: "", canvas : 'noCanvas'}]}; + + ok(shouldError(function () { karma5.init(badOptions); }), + "Rejects bad options"); + + //test that init won't overwrite private properties + var karma6 = Karma.create(Karma.karma).init({_counters : { errors : 500}}); + ok(karma6._counters.errors !== 500, "Private property not overwritten"); + }); - test("Karma.karma.sanitizeLocale(locale)", function () { - // check valid locale - ok(Karma.karma.sanitizeLocale("en"), "Valid locale option accepted"); - //test invalid locale - ok(Karma.karma.sanitizeLocale("foo"), "Invalid locale rejected"); - }); - - - test("Karma.karma.ready()", function () { - var karma3 = Karma.create(Karma.karma); - test(shouldError(karma3.ready()), "Uninitialized karma instance" + - "generates error on .ready()"); - - karma3.init(); - var testElem = $('#karma-test'); - ok(testElem, "karma.run() w/ no args puts out default message"); - if(testElem){ - testElem.remove(); - } - - var ninjaName = "Bruce Lee"; - var testCb = function () { ninjaName = "Chuck Norris";} - var karma4 = Karma.create(Karma.karma).init().run(testCb); - ok (ninjaName === "Chuck Norris", "run() calls callback"); - - //test that callback isn't called while asset isn't ready yet - var ninjaName = "Bruce Lee"; - try{ - var karma4 = Karma({ images : { name: "notthere", file : "notthere.png"}}); - } catch (e) {} - ok( ninjaName === "Bruce Lee", "callback not called before all assets loaded"); - }); - - - test("Karma.kMedia", - function () { - var kMock = { name: "chimp", type: "image", file: "chimp.png", - src: "./chimp.png"}; - - ok(kMock.src === "./chimp.png", "src matches file"); - kMock.file = "nothere.png"; - - mockErr = new Error("This file cannot be found"); - mockErr.name = "fileNotFound"; - - ok(shouldError({ func: Karma.kMedia.init, error: mockErr, ctx: kMock}), - "bad file name produces error"); - ok(kMedia.path, "kMedia.path"); - ok(kMedia.media, "kMedia.media"); - ok(kMedia.src === "" + kMock.path + kMock.file, "file path is correct"); - - //I don't know how to test that eventHandlers have been added - // nor how to test that they will be properly dispatched - /* kMedia1 = Karma.create( Karma.kMedia ); - - //check event listeners loaded - var handlers = ['ready', 'load', 'abort', 'error']; - ok(function () { - kMedia1.init({ name: "chimp", type: "image", file: "chimp.png", - src: "./chimp.png"}); + test("Karma.karma.ready()", function () { + Karma.KarmaRoot = undefined; + var karma3 = Karma.create(Karma.karma); + ok(shouldError(function () {karma3.ready();}), "Uninitialized karma instance " + + "generates error on .ready()"); + karma3 = Karma.create(Karma.karma).init().ready(); + var starterMsg = document.getElementById('starterMsg'); + ok(starterMsg, + "Karma.karma.ready() with no callback displays starter msg"); + //clean up + document.body.removeChild(starterMsg); + var ninjaName = "Bruce Lee"; + var testCb = function () { ninjaName = "Chuck Norris";}; - }, "All event handlers loaded"); + var karma4 = Karma.create(Karma.karma).init().ready(testCb); + ok (ninjaName === "Chuck Norris", "ready() calls callback"); - kMock = copyObjectPlus(Karma.kMedia, kMock); - - //trigger event handlers - var ev = document.createEvent('HTMLEvents'); - ev.initEvent('load'); - ok(kMock.elem.dispatchEvent(ev), "load event attached"); - */ + + //test that callback isn't called while asset isn't ready yet + ninjaName = "Bruce Lee"; + karma4 = Karma.create(Karma.karma).init(); + karma4._counters.total = 5000; + karma4.ready(testCb); + ok( ninjaName === "Bruce Lee", "callback not called before all assets loaded"); + karma4._counters.total = 0; + + //wait for callback to be called by ready + setTimeout(function() { + ok (ninjaName === "Chuck Norris", + "ready() calls callback after assets loaded");}, + 200); + + }); - }); + test("karma.isValidLocale(locale)", + function () { + /* reject locale if has more than 2 letters + * before dash or underscore + * + */ - - -/* test("Karma.kMedia.init load event", ); - test("Karma.kMedia.init error event", ); - test("Karma.kMedia.init abort event", ); + // test valid locale + ok(Karma.karma.isValidLocale("en"), "Valid locale option accepted"); + + // test valid locale + ok(Karma.karma.isValidLocale("en-us"), "Valid locale option accepted"); + + //test invalid locale + ok(!Karma.karma.isValidLocale("foo"), "Invalid locale rejected"); + + //test invalid locale + ok(!Karma.karma.isValidLocale("en_Foobar"), "Invalid locale rejected"); + + }); + + + test("karma.normalizeLocale(locale)", function () { + /* + * change any "-" dash to underscore + * make sure first part lowercase + * make sure part after underscore is uppercase + * + * don't do anything if already ok + * + * don't choke on locale w/ only two letters + */ + + ok (Karma.karma.normalizeLocale("EN-us") === "en_US", + "lowercase, uppercase, and dash properly changed"); + ok (Karma.karma.normalizeLocale("en_US") === "en_US", + "Doesn't screw up locale that is already ok"); + ok (Karma.karma.normalizeLocale("en") === "en", + "handles 2 letter locale."); + console.log(Karma.karma.normalizeLocale("en")); + + + }); - test("Karma.kImage", function () { + test("karma.computeLocalePath(locale)", + function() { + /* + * for locale es_SP + * make sure returns path "../assets/locale_name/" + * + */ + + ok(Karma.karma.computeLocalePath("en_US") === + "../assets/en_US/", "computes correct path"); + + ok(Karma.karma.computeLocalePath("es") === + "../assets/es/", "computes correct path"); + }); - }); + test("Karma.kMedia", + function (){ + + + }); - - test("Karma.kSound", function () { + 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 + * + */ - }); - - test("Karma.kSvg", function () { + + 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.karma.kMedia); + var oldErrors = Karma.karma._counters.errors; + var oldTotal = Karma.karma._counters.total; + kMedia1.init({name: "notthere", type : "image", + file: "notthere.png"}); + ok(kMedia1.status === "error", "bad file name produces error"); + ok(Karma.karma._counters.errors === oldErrors + 1 , + "Error counter was incremented on load error"); + ok(Karma.karma._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; + ok(shouldError( + function () { + kMock.init({ name: 'esMonkey', file: 'HappyMonkey.jpg', + type: 'image', localized: true }); + }), + "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, + "Loading a localized file emits an error event if a localized version doesn't exist"); + 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, + "Properly loads localized file"); + ok(Karma.karma._counters.total === oldTotal + 1 , + "Total Assets counter was incremented"); + }); + + + + test("Karma.karma.checkLocalized", + function(){ + /* + * reject non-boolean values + * + * produce error if item is localized but not + * locale isn't set for karma object + */ + + ok(Karma.karma.checkLocalized(true), + "handles true string value"); + ok(Karma.karma.checkLocalized(false), + "handles false string value"); + ok(shouldError(function(){ + Karma.karma.checkLocalized("true");}), + "rejects non-boolean value"); + + }); - }); - */ - - - }); \ No newline at end of file + + + }); \ No newline at end of file -- cgit v0.9.1