|
| 1 | +"use strict"; |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +define(["/lib/jquery-2.0.2.min.js", "/lib/async.js"], function(jq, async){ |
| 6 | + var isFunction = function(functionToCheck) { |
| 7 | + var getType = {}; |
| 8 | + return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]'; |
| 9 | + }; |
| 10 | + |
| 11 | + var testsDefinitions = [ |
| 12 | + { name : "checkHomepage", |
| 13 | + message: "The title should be Exquis", |
| 14 | + assertion: document.title == "Exquis" |
| 15 | + }, |
| 16 | + { name: "editorIsNotVisibleOnStartUp", |
| 17 | + message: "The editor should not be visible", |
| 18 | + assertion: $("#editor").hasClass("invisible") |
| 19 | + }, |
| 20 | + { name: "nineCanvasElements", |
| 21 | + message: "we should have 9 canvas elements", |
| 22 | + assertion: $("canvas").length == 9 |
| 23 | + }, |
| 24 | + function(){ |
| 25 | + $("#hint-2-1").click(); |
| 26 | + |
| 27 | + var results = [ |
| 28 | + { name: "onCanvasClickEditorVisible", |
| 29 | + message: "on canvas click editor should be visible", |
| 30 | + assertion: ! $("#editor").hasClass("invisible") |
| 31 | + }]; |
| 32 | + $("#editor").addClass("invisible"); |
| 33 | + |
| 34 | + return results; |
| 35 | + } |
| 36 | + ]; |
| 37 | + |
| 38 | + var asyncTests = [ |
| 39 | + function(done, net){ |
| 40 | + |
| 41 | + var savedAnimation, |
| 42 | + fileName, |
| 43 | + originalNetSaveAnimation = net.saveAnimation; |
| 44 | + net.saveAnimation = function(cell, callback, _fileName){ |
| 45 | + console.log(_fileName); |
| 46 | + savedAnimation = cell.animation.drawString; |
| 47 | + fileName = _fileName; |
| 48 | + net.saveAnimation = originalNetSaveAnimation; |
| 49 | + }; |
| 50 | + var correctFileName = "someTestAnim"; |
| 51 | + // var codeString = "var i = 0;"; |
| 52 | + // $("#hint-2-1").click(); |
| 53 | + // $("#ace > textarea").val(codeString); |
| 54 | + // $("#ace > textarea").keyup(); |
| 55 | + setTimeout(function(){ |
| 56 | + $("#animation_save_as_button").click(); |
| 57 | + $("#prompt_input").value = correctFileName; |
| 58 | + $("#ok_button").click(); |
| 59 | + |
| 60 | + var result = [ |
| 61 | + // {name : "onSaveAsClick", |
| 62 | + // message: codeString + " != " + savedAnimation, |
| 63 | + // assertion: codeString === savedAnimation |
| 64 | + // }, |
| 65 | + {name: "onSaveAsClick", |
| 66 | + message: "file name should be " + correctFileName + " not " + fileName, |
| 67 | + assertion: fileName === correctFileName |
| 68 | + }]; |
| 69 | + done(null, result); |
| 70 | + }, 1000); |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | + ]; |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + var test = function(net){ |
| 79 | + var failureCount = 0, |
| 80 | + testCount = 0, |
| 81 | + tests; |
| 82 | + |
| 83 | + |
| 84 | + tests = testsDefinitions.reduce(function(accum, nextValue){ |
| 85 | + if (isFunction(nextValue)){ |
| 86 | + var asserts = nextValue(net); |
| 87 | + accum = accum.concat(asserts); |
| 88 | + }else{ |
| 89 | + accum.push(nextValue); |
| 90 | + } |
| 91 | + |
| 92 | + return accum; |
| 93 | + }, []); |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + async.mapSeries(asyncTests, function(val, cb){ |
| 98 | + val(cb, net); |
| 99 | + }, function(err, results){ |
| 100 | + var flatResults = results.reduce(function(a, b) { |
| 101 | + return a.concat(b); |
| 102 | + }); |
| 103 | + |
| 104 | + var allResults = tests.concat(flatResults); |
| 105 | + |
| 106 | + allResults.forEach(function(test){ |
| 107 | + |
| 108 | + testCount ++; |
| 109 | + |
| 110 | + if (!test.assertion){ |
| 111 | + failureCount ++; |
| 112 | + console.log(test.message); |
| 113 | + }; |
| 114 | + }); |
| 115 | + |
| 116 | + console.log(failureCount + " failures out of " +testCount + " tests."); |
| 117 | + }); |
| 118 | + |
| 119 | + |
| 120 | + }; |
| 121 | + |
| 122 | + |
| 123 | + return { |
| 124 | + test: test |
| 125 | + }; |
| 126 | +}); |
0 commit comments