diff options
author | Bryan Berry <bryan@olenepal.org> | 2009-11-07 00:56:12 (GMT) |
---|---|---|
committer | Bryan Berry <bryan@olenepal.org> | 2009-11-07 00:56:12 (GMT) |
commit | cb199410f8d8de39796bed713da9b1b7fc35716e (patch) | |
tree | 404407697098f40dd4e12ac4124966094bf45fa9 | |
parent | feed7998609084797fe97e0c0c0f721f01f0c864 (diff) |
tests for the helper methods work
22 files changed, 171 insertions, 44 deletions
diff --git a/examples/Conozco-Uruguay/assets/generic/images/Uruguay_departments_blank.svg b/examples/Conozco-Uruguay/assets/generic/images/Uruguay_departments_blank.svg index 5f9d64a..5f9d64a 100644..100755 --- a/examples/Conozco-Uruguay/assets/generic/images/Uruguay_departments_blank.svg +++ b/examples/Conozco-Uruguay/assets/generic/images/Uruguay_departments_blank.svg diff --git a/examples/Conozco-Uruguay/assets/generic/images/capitals.svg b/examples/Conozco-Uruguay/assets/generic/images/capitals.svg index 16f973f..16f973f 100644..100755 --- a/examples/Conozco-Uruguay/assets/generic/images/capitals.svg +++ b/examples/Conozco-Uruguay/assets/generic/images/capitals.svg diff --git a/examples/Conozco-Uruguay/assets/generic/images/capitals1-bak.svg b/examples/Conozco-Uruguay/assets/generic/images/capitals1-bak.svg index 6eaf340..6eaf340 100644..100755 --- a/examples/Conozco-Uruguay/assets/generic/images/capitals1-bak.svg +++ b/examples/Conozco-Uruguay/assets/generic/images/capitals1-bak.svg diff --git a/examples/Conozco-Uruguay/assets/generic/images/capitals1.svg b/examples/Conozco-Uruguay/assets/generic/images/capitals1.svg index 24c886c..24c886c 100644..100755 --- a/examples/Conozco-Uruguay/assets/generic/images/capitals1.svg +++ b/examples/Conozco-Uruguay/assets/generic/images/capitals1.svg diff --git a/examples/Conozco-Uruguay/css/jquery.svg.css b/examples/Conozco-Uruguay/css/jquery.svg.css index c181ec1..c181ec1 100644..100755 --- a/examples/Conozco-Uruguay/css/jquery.svg.css +++ b/examples/Conozco-Uruguay/css/jquery.svg.css diff --git a/examples/Conozco-Uruguay/css/lesson.css b/examples/Conozco-Uruguay/css/lesson.css index fb645dd..fb645dd 100644..100755 --- a/examples/Conozco-Uruguay/css/lesson.css +++ b/examples/Conozco-Uruguay/css/lesson.css diff --git a/examples/Conozco-Uruguay/js/jquery.svg.pack.js b/examples/Conozco-Uruguay/js/jquery.svg.pack.js index 4727218..4727218 100644..100755 --- a/examples/Conozco-Uruguay/js/jquery.svg.pack.js +++ b/examples/Conozco-Uruguay/js/jquery.svg.pack.js diff --git a/examples/Conozco-Uruguay/js/jquery.svgdom.pack.js b/examples/Conozco-Uruguay/js/jquery.svgdom.pack.js index be88a52..be88a52 100644..100755 --- a/examples/Conozco-Uruguay/js/jquery.svgdom.pack.js +++ b/examples/Conozco-Uruguay/js/jquery.svgdom.pack.js diff --git a/examples/Conozco-Uruguay/js/old-lesson.js b/examples/Conozco-Uruguay/js/old-lesson.js index bc1aae9..bc1aae9 100644..100755 --- a/examples/Conozco-Uruguay/js/old-lesson.js +++ b/examples/Conozco-Uruguay/js/old-lesson.js diff --git a/examples/Conozco-Uruguay/js/tests.js b/examples/Conozco-Uruguay/js/tests.js index 540473e..540473e 100644..100755 --- a/examples/Conozco-Uruguay/js/tests.js +++ b/examples/Conozco-Uruguay/js/tests.js diff --git a/examples/Conozco-Uruguay/tests.html b/examples/Conozco-Uruguay/tests.html index cb1f7c7..cb1f7c7 100644..100755 --- a/examples/Conozco-Uruguay/tests.html +++ b/examples/Conozco-Uruguay/tests.html diff --git a/js/karma.js b/js/karma.js index e99bd5c..603c602 100644..100755 --- a/js/karma.js +++ b/js/karma.js @@ -22,13 +22,17 @@ * @exports $ as jQuery */ - - var Karma = function (options) { - var karmaRoot; - var karma; +//this.exports is used by narwhal but undefined in other contexts +if(!this.exports) { + exports = {}; +} + +var Karma = exports.Karma = function (options) { + var karmaRoot; + var karma; - return Karma.create(Karma.karma).init(options); - + return Karma.create(Karma.karma).init(options); + }; //helper functions, all in the Karma namespace @@ -77,7 +81,7 @@ if ( typeof localised === "boolean" ) { return localised; } - }}; + }; diff --git a/js/karma.js.~2~ b/js/karma.js.~2~ index 1be398b..1be398b 100644..100755 --- a/js/karma.js.~2~ +++ b/js/karma.js.~2~ diff --git a/js/karma.js.~3~ b/js/karma.js.~3~ index 4d8f9d0..4d8f9d0 100644..100755 --- a/js/karma.js.~3~ +++ b/js/karma.js.~3~ diff --git a/tests/.#tests.js b/tests/.#tests.js new file mode 120000 index 0000000..c77966a --- /dev/null +++ b/tests/.#tests.js @@ -0,0 +1 @@ +hitman@hitman.3554:1257448840
\ No newline at end of file diff --git a/tests/data/happyMonkey.jpg b/tests/data/happyMonkey.jpg Binary files differnew file mode 100755 index 0000000..bfe0d38 --- /dev/null +++ b/tests/data/happyMonkey.jpg diff --git a/tests/data/trigger.ogg b/tests/data/trigger.ogg Binary files differnew file mode 100755 index 0000000..f22512a --- /dev/null +++ b/tests/data/trigger.ogg diff --git a/tests/index.html b/tests/index.html index 9f97734..e82bbbd 100755 --- a/tests/index.html +++ b/tests/index.html @@ -11,9 +11,8 @@ <script src="../js/karma.js" type="text/javascript"></script> <script src="tests.js" type="text/javascript"></script> - -<link rel="stylesheet" href="../css/qunit.css" type="text/css"/> -<link rel="stylesheet" href="test.css" type="text/css"/> + <link rel="stylesheet" href="../css/qunit.css" type="text/css"/> + <link rel="stylesheet" href="test.css" type="text/css"/> </head> <body> diff --git a/tests/tests.css b/tests/tests.css index 63a49ba..63a49ba 100644..100755 --- a/tests/tests.css +++ b/tests/tests.css diff --git a/tests/tests.js b/tests/tests.js index 30a90c1..e686106 100644..100755 --- a/tests/tests.js +++ b/tests/tests.js @@ -1,9 +1,56 @@ $(document).ready(function(){ + var hasProperties = function (properties) { + for ( prop in properties) { + if (!this[prop]){ + return false; + } + 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 { + return true; + } + + 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; + }; - // Testing helper methods 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 @@ -45,8 +92,10 @@ 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"); + ninja1.name === ninja.name, + "target object wasn't updated with source"); + ok ( warrior.__proto__.isPrototypeOf(ninja1), + "the protoypeObject changed"); }); @@ -54,37 +103,99 @@ module("Module Karma core library"); test("Karma", function () { + + + same( Karma.karma, Karma({}), + "Karma() returns the karma object"); + var options = {locale: "en-US", - images: [ {name: "ball", file: "ball37px.png"}], - sounds: [ {name: "correct", file: "correct.ogg"}], - surfaces: [ {name:"topLt", canvas:"topLtCanvas"}]}; + images: [ {name: "monkey", file: "happyMonkey.jpg"}], + sounds: [ {name: "trigger", file: "trigger.ogg"}], + surfaces: [ {name:"testCanvas", canvas:"testCanvas"}]}; + + + karma1 = Karma(options); + ok(karma1.images[0].name === "ball", "image name set properly"); - var karma1 = 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"); - ok( karma1.__proto__.isPrototypeOf(Karma.karma), "Karma() doesn't return" + - " a prototype of Karma.karma "); + //check that the image file matches original + 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"); - test("kObject", function () { - var kMock = Karma.kObject; - ok ( kMock.localized === false, "kObject is properly instantiated"); - var options = {localized: true}; - kMock.init(options); - ok (kMock.localized === true, "kObject init properly sets localized value"); + }); + + + test("Karma.karma", function () { + var options; + karma1 = Karma.create(Karma.karma); + var goodOptions = {locale : "en", images : [{ name: "chimp", + file : 'chimp.png' }], + sounds : [{ name: "correct", file : 'correct.ogg'}], + surfaces : [{ name: "test", canvas : 'testCanvas'}]}; + + // check valid locale + ok(Karma.karma.checkLocale("en"), "Valid locale option accepted"); - test("Karma.karma.validate", function () { - var kMock = Karma.karma; + + //test invalid locale + ok(Karma.karma.checkLocale("foo"), "Invalid locale rejected"); + - kMock.images = [{ name: "chimp", file : 'chimp.png' }] ; - kMock.sounds = [{ name: "correct", file : 'correct.ogg'}]; - kMock.surfaces = [{ name: "test", canvas : 'testCanvas'}]; - ok( kMock.validate(options), "It didn't accept good options"); +/* //check that init() called on each asset + ok(function () { + for ( var category in karma1){ + initCategories = new RegExp("images||sounds||svg||videos"); + + if (initCategories.match(category.toString())){ + for ( var asset in category) { + if (!asset.hasOwnProperty("init")){ + return false; + } + } + } + } + return true; + }, "an init method called on each asset"); +*/ + }); + + + + 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"; - kMock.images = [{ name: "chimp", file : 'notThere.png' }] ; - ok( Karma.karma.validate(options), "It accepted an image that" + - "doesn't exist"); + ok(shouldError({ func: kMock.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"); + + //test load event + + //test error event + + //test abort event + + + }); + + /* kMock.sounds = [{ name: "correct", file : 'notthere.ogg'}]; ok( Karma.karma.validate(options), "It accepted a sound that" + @@ -94,26 +205,38 @@ ok( Karma.karma.validate(options), "It accepted a canvas element" + "that doesn't exist"); */ - }); - - test("Karma.karma.init", function () { - - }); + /* test("Karma.kMedia.init localized", + function() { + properties = ["name", "localised", "file", ]; + + ok(hasProperties.call(Karma.kMedia, properties), + "kMedia has the " + "properties it should have"); + + }); + + test("Karma.kMedia.init load event", ); + test("Karma.kMedia.init error event", ); + test("Karma.kMedia.init abort event", ); - - test("Karma.kimage.validate", function () { + test("Karma.kImage", function () { }); + - test("Karma.kimage.init", function () { + test("Karma.kSound", function () { }); - + test("Karma.kSvg", function () { + + }); + +*/ + });
\ No newline at end of file diff --git a/tests/tests.js.~2~ b/tests/tests.js.~2~ index a6e1464..a6e1464 100644..100755 --- a/tests/tests.js.~2~ +++ b/tests/tests.js.~2~ diff --git a/tests/trigger.ogg b/tests/trigger.ogg Binary files differnew file mode 100755 index 0000000..f22512a --- /dev/null +++ b/tests/trigger.ogg |