mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Built the client test view (rebased from feature/testclient).
This commit is contained in:
parent
435ec1b6aa
commit
49c9c6bfc9
29 changed files with 3512 additions and 154 deletions
181
app/assets/javascripts/boot.js
Executable file
181
app/assets/javascripts/boot.js
Executable file
|
@ -0,0 +1,181 @@
|
|||
/**
|
||||
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
|
||||
|
||||
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
|
||||
|
||||
The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
|
||||
|
||||
[jasmine-gem]: http://github.com/pivotal/jasmine-gem
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
/**
|
||||
* ## Require & Instantiate
|
||||
*
|
||||
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
|
||||
*/
|
||||
window.jasmine = jasmineRequire.core(jasmineRequire);
|
||||
|
||||
/**
|
||||
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
|
||||
*/
|
||||
jasmineRequire.html(jasmine);
|
||||
|
||||
/**
|
||||
* Create the Jasmine environment. This is used to run all specs in a project.
|
||||
*/
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
/**
|
||||
* ## The Global Interface
|
||||
*
|
||||
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
|
||||
*/
|
||||
var jasmineInterface = {
|
||||
describe: function(description, specDefinitions) {
|
||||
return env.describe(description, specDefinitions);
|
||||
},
|
||||
|
||||
xdescribe: function(description, specDefinitions) {
|
||||
return env.xdescribe(description, specDefinitions);
|
||||
},
|
||||
|
||||
it: function(desc, func) {
|
||||
return env.it(desc, func);
|
||||
},
|
||||
|
||||
xit: function(desc, func) {
|
||||
return env.xit(desc, func);
|
||||
},
|
||||
|
||||
beforeEach: function(beforeEachFunction) {
|
||||
return env.beforeEach(beforeEachFunction);
|
||||
},
|
||||
|
||||
afterEach: function(afterEachFunction) {
|
||||
return env.afterEach(afterEachFunction);
|
||||
},
|
||||
|
||||
expect: function(actual) {
|
||||
return env.expect(actual);
|
||||
},
|
||||
|
||||
pending: function() {
|
||||
return env.pending();
|
||||
},
|
||||
|
||||
spyOn: function(obj, methodName) {
|
||||
return env.spyOn(obj, methodName);
|
||||
},
|
||||
|
||||
jsApiReporter: new jasmine.JsApiReporter({
|
||||
timer: new jasmine.Timer()
|
||||
})
|
||||
};
|
||||
|
||||
/**
|
||||
* Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
|
||||
*/
|
||||
if (typeof window == "undefined" && typeof exports == "object") {
|
||||
extend(exports, jasmineInterface);
|
||||
} else {
|
||||
extend(window, jasmineInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose the interface for adding custom equality testers.
|
||||
*/
|
||||
jasmine.addCustomEqualityTester = function(tester) {
|
||||
env.addCustomEqualityTester(tester);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose the interface for adding custom expectation matchers
|
||||
*/
|
||||
jasmine.addMatchers = function(matchers) {
|
||||
return env.addMatchers(matchers);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose the mock interface for the JavaScript timeout functions
|
||||
*/
|
||||
jasmine.clock = function() {
|
||||
return env.clock;
|
||||
};
|
||||
|
||||
/**
|
||||
* ## Runner Parameters
|
||||
*
|
||||
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
|
||||
*/
|
||||
|
||||
var queryString = new jasmine.QueryString({
|
||||
getWindowLocation: function() { return window.location; }
|
||||
});
|
||||
|
||||
var catchingExceptions = queryString.getParam("catch");
|
||||
env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
|
||||
|
||||
/**
|
||||
* ## Reporters
|
||||
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
|
||||
*/
|
||||
var htmlReporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
|
||||
getContainer: function() { return $('#testing-area')[0]; },
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||
timer: new jasmine.Timer()
|
||||
});
|
||||
|
||||
/**
|
||||
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
|
||||
*/
|
||||
env.addReporter(jasmineInterface.jsApiReporter);
|
||||
env.addReporter(htmlReporter);
|
||||
|
||||
/**
|
||||
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
|
||||
*/
|
||||
var specFilter = new jasmine.HtmlSpecFilter({
|
||||
filterString: function() { return queryString.getParam("spec"); }
|
||||
});
|
||||
|
||||
env.specFilter = function(spec) {
|
||||
return specFilter.matches(spec.getFullName());
|
||||
};
|
||||
|
||||
/**
|
||||
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
|
||||
*/
|
||||
window.setTimeout = window.setTimeout;
|
||||
window.setInterval = window.setInterval;
|
||||
window.clearTimeout = window.clearTimeout;
|
||||
window.clearInterval = window.clearInterval;
|
||||
|
||||
/**
|
||||
* ## Execution
|
||||
*
|
||||
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
|
||||
*/
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
htmlReporter.initialize();
|
||||
env.execute();
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function for readability above.
|
||||
*/
|
||||
function extend(destination, source) {
|
||||
for (var property in source) destination[property] = source[property];
|
||||
return destination;
|
||||
}
|
||||
|
||||
}());
|
359
app/assets/javascripts/jasmine-html.js
Executable file
359
app/assets/javascripts/jasmine-html.js
Executable file
|
@ -0,0 +1,359 @@
|
|||
/*
|
||||
Copyright (c) 2008-2013 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
jasmineRequire.html = function(j$) {
|
||||
j$.ResultsNode = jasmineRequire.ResultsNode();
|
||||
j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
|
||||
j$.QueryString = jasmineRequire.QueryString();
|
||||
j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
|
||||
};
|
||||
|
||||
jasmineRequire.HtmlReporter = function(j$) {
|
||||
|
||||
var noopTimer = {
|
||||
start: function() {},
|
||||
elapsed: function() { return 0; }
|
||||
};
|
||||
|
||||
function HtmlReporter(options) {
|
||||
var env = options.env || {},
|
||||
getContainer = options.getContainer,
|
||||
createElement = options.createElement,
|
||||
createTextNode = options.createTextNode,
|
||||
onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
|
||||
timer = options.timer || noopTimer,
|
||||
results = [],
|
||||
specsExecuted = 0,
|
||||
failureCount = 0,
|
||||
pendingSpecCount = 0,
|
||||
htmlReporterMain,
|
||||
symbols;
|
||||
|
||||
this.initialize = function() {
|
||||
htmlReporterMain = createDom("div", {className: "html-reporter"},
|
||||
createDom("div", {className: "banner"},
|
||||
createDom("span", {className: "title"}, "Jasmine"),
|
||||
createDom("span", {className: "version"}, j$.version)
|
||||
),
|
||||
createDom("ul", {className: "symbol-summary"}),
|
||||
createDom("div", {className: "alert"}),
|
||||
createDom("div", {className: "results"},
|
||||
createDom("div", {className: "failures"})
|
||||
)
|
||||
);
|
||||
getContainer().appendChild(htmlReporterMain);
|
||||
|
||||
symbols = find(".symbol-summary");
|
||||
};
|
||||
|
||||
var totalSpecsDefined;
|
||||
this.jasmineStarted = function(options) {
|
||||
totalSpecsDefined = options.totalSpecsDefined || 0;
|
||||
timer.start();
|
||||
};
|
||||
|
||||
var summary = createDom("div", {className: "summary"});
|
||||
|
||||
var topResults = new j$.ResultsNode({}, "", null),
|
||||
currentParent = topResults;
|
||||
|
||||
this.suiteStarted = function(result) {
|
||||
currentParent.addChild(result, "suite");
|
||||
currentParent = currentParent.last();
|
||||
};
|
||||
|
||||
this.suiteDone = function(result) {
|
||||
if (currentParent == topResults) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentParent = currentParent.parent;
|
||||
};
|
||||
|
||||
this.specStarted = function(result) {
|
||||
currentParent.addChild(result, "spec");
|
||||
};
|
||||
|
||||
var failures = [];
|
||||
this.specDone = function(result) {
|
||||
if (result.status != "disabled") {
|
||||
specsExecuted++;
|
||||
}
|
||||
|
||||
symbols.appendChild(createDom("li", {
|
||||
className: result.status,
|
||||
id: "spec_" + result.id,
|
||||
title: result.fullName
|
||||
}
|
||||
));
|
||||
|
||||
if (result.status == "failed") {
|
||||
failureCount++;
|
||||
|
||||
var failure =
|
||||
createDom("div", {className: "spec-detail failed"},
|
||||
createDom("div", {className: "description"},
|
||||
createDom("a", {title: result.fullName, href: specHref(result)}, result.fullName)
|
||||
),
|
||||
createDom("div", {className: "messages"})
|
||||
);
|
||||
var messages = failure.childNodes[1];
|
||||
|
||||
for (var i = 0; i < result.failedExpectations.length; i++) {
|
||||
var expectation = result.failedExpectations[i];
|
||||
messages.appendChild(createDom("div", {className: "result-message"}, expectation.message));
|
||||
messages.appendChild(createDom("div", {className: "stack-trace"}, expectation.stack));
|
||||
}
|
||||
|
||||
failures.push(failure);
|
||||
}
|
||||
|
||||
if (result.status == "pending") {
|
||||
pendingSpecCount++;
|
||||
}
|
||||
};
|
||||
|
||||
this.jasmineDone = function() {
|
||||
var banner = find(".banner");
|
||||
banner.appendChild(createDom("span", {className: "duration"}, "finished in " + timer.elapsed() / 1000 + "s"));
|
||||
|
||||
var alert = find(".alert");
|
||||
|
||||
alert.appendChild(createDom("span", { className: "exceptions" },
|
||||
createDom("label", { className: "label", 'for': "raise-exceptions" }, "raise exceptions"),
|
||||
createDom("input", {
|
||||
className: "raise",
|
||||
id: "raise-exceptions",
|
||||
type: "checkbox"
|
||||
})
|
||||
));
|
||||
var checkbox = find("input");
|
||||
|
||||
checkbox.checked = !env.catchingExceptions();
|
||||
checkbox.onclick = onRaiseExceptionsClick;
|
||||
|
||||
if (specsExecuted < totalSpecsDefined) {
|
||||
var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all";
|
||||
alert.appendChild(
|
||||
createDom("span", {className: "bar skipped"},
|
||||
createDom("a", {href: "?", title: "Run all specs"}, skippedMessage)
|
||||
)
|
||||
);
|
||||
}
|
||||
var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount);
|
||||
if (pendingSpecCount) { statusBarMessage += ", " + pluralize("pending spec", pendingSpecCount); }
|
||||
|
||||
var statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed");
|
||||
alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage));
|
||||
|
||||
var results = find(".results");
|
||||
results.appendChild(summary);
|
||||
|
||||
summaryList(topResults, summary);
|
||||
|
||||
function summaryList(resultsTree, domParent) {
|
||||
var specListNode;
|
||||
for (var i = 0; i < resultsTree.children.length; i++) {
|
||||
var resultNode = resultsTree.children[i];
|
||||
if (resultNode.type == "suite") {
|
||||
var suiteListNode = createDom("ul", {className: "suite", id: "suite-" + resultNode.result.id},
|
||||
createDom("li", {className: "suite-detail"},
|
||||
createDom("a", {href: specHref(resultNode.result)}, resultNode.result.description)
|
||||
)
|
||||
);
|
||||
|
||||
summaryList(resultNode, suiteListNode);
|
||||
domParent.appendChild(suiteListNode);
|
||||
}
|
||||
if (resultNode.type == "spec") {
|
||||
if (domParent.getAttribute("class") != "specs") {
|
||||
specListNode = createDom("ul", {className: "specs"});
|
||||
domParent.appendChild(specListNode);
|
||||
}
|
||||
specListNode.appendChild(
|
||||
createDom("li", {
|
||||
className: resultNode.result.status,
|
||||
id: "spec-" + resultNode.result.id
|
||||
},
|
||||
createDom("a", {href: specHref(resultNode.result)}, resultNode.result.description)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (failures.length) {
|
||||
alert.appendChild(
|
||||
createDom('span', {className: "menu bar spec-list"},
|
||||
createDom("span", {}, "Spec List | "),
|
||||
createDom('a', {className: "failures-menu", href: "#"}, "Failures")));
|
||||
alert.appendChild(
|
||||
createDom('span', {className: "menu bar failure-list"},
|
||||
createDom('a', {className: "spec-list-menu", href: "#"}, "Spec List"),
|
||||
createDom("span", {}, " | Failures ")));
|
||||
|
||||
find(".failures-menu").onclick = function() {
|
||||
setMenuModeTo('failure-list');
|
||||
};
|
||||
find(".spec-list-menu").onclick = function() {
|
||||
setMenuModeTo('spec-list');
|
||||
};
|
||||
|
||||
setMenuModeTo('failure-list');
|
||||
|
||||
var failureNode = find(".failures");
|
||||
for (var i = 0; i < failures.length; i++) {
|
||||
failureNode.appendChild(failures[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return this;
|
||||
|
||||
function find(selector) {
|
||||
return getContainer().querySelector(selector);
|
||||
}
|
||||
|
||||
function createDom(type, attrs, childrenVarArgs) {
|
||||
var el = createElement(type);
|
||||
|
||||
for (var i = 2; i < arguments.length; i++) {
|
||||
var child = arguments[i];
|
||||
|
||||
if (typeof child === 'string') {
|
||||
el.appendChild(createTextNode(child));
|
||||
} else {
|
||||
if (child) {
|
||||
el.appendChild(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var attr in attrs) {
|
||||
if (attr == "className") {
|
||||
el[attr] = attrs[attr];
|
||||
} else {
|
||||
el.setAttribute(attr, attrs[attr]);
|
||||
}
|
||||
}
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
function pluralize(singular, count) {
|
||||
var word = (count == 1 ? singular : singular + "s");
|
||||
|
||||
return "" + count + " " + word;
|
||||
}
|
||||
|
||||
function specHref(result) {
|
||||
return "?spec=" + encodeURIComponent(result.fullName);
|
||||
}
|
||||
|
||||
function setMenuModeTo(mode) {
|
||||
htmlReporterMain.setAttribute("class", "html-reporter " + mode);
|
||||
}
|
||||
}
|
||||
|
||||
return HtmlReporter;
|
||||
};
|
||||
|
||||
jasmineRequire.HtmlSpecFilter = function() {
|
||||
function HtmlSpecFilter(options) {
|
||||
var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
var filterPattern = new RegExp(filterString);
|
||||
|
||||
this.matches = function(specName) {
|
||||
return filterPattern.test(specName);
|
||||
};
|
||||
}
|
||||
|
||||
return HtmlSpecFilter;
|
||||
};
|
||||
|
||||
jasmineRequire.ResultsNode = function() {
|
||||
function ResultsNode(result, type, parent) {
|
||||
this.result = result;
|
||||
this.type = type;
|
||||
this.parent = parent;
|
||||
|
||||
this.children = [];
|
||||
|
||||
this.addChild = function(result, type) {
|
||||
this.children.push(new ResultsNode(result, type, this));
|
||||
};
|
||||
|
||||
this.last = function() {
|
||||
return this.children[this.children.length - 1];
|
||||
};
|
||||
}
|
||||
|
||||
return ResultsNode;
|
||||
};
|
||||
|
||||
jasmineRequire.QueryString = function() {
|
||||
function QueryString(options) {
|
||||
|
||||
this.setParam = function(key, value) {
|
||||
var paramMap = queryStringToParamMap();
|
||||
paramMap[key] = value;
|
||||
options.getWindowLocation().search = toQueryString(paramMap);
|
||||
};
|
||||
|
||||
this.getParam = function(key) {
|
||||
return queryStringToParamMap()[key];
|
||||
};
|
||||
|
||||
return this;
|
||||
|
||||
function toQueryString(paramMap) {
|
||||
var qStrPairs = [];
|
||||
for (var prop in paramMap) {
|
||||
qStrPairs.push(encodeURIComponent(prop) + "=" + encodeURIComponent(paramMap[prop]));
|
||||
}
|
||||
return "?" + qStrPairs.join('&');
|
||||
}
|
||||
|
||||
function queryStringToParamMap() {
|
||||
var paramStr = options.getWindowLocation().search.substring(1),
|
||||
params = [],
|
||||
paramMap = {};
|
||||
|
||||
if (paramStr.length > 0) {
|
||||
params = paramStr.split('&');
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var p = params[i].split('=');
|
||||
var value = decodeURIComponent(p[1]);
|
||||
if (value === "true" || value === "false") {
|
||||
value = JSON.parse(value);
|
||||
}
|
||||
paramMap[decodeURIComponent(p[0])] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return paramMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return QueryString;
|
||||
};
|
2402
app/assets/javascripts/jasmine.js
Executable file
2402
app/assets/javascripts/jasmine.js
Executable file
File diff suppressed because it is too large
Load diff
295
app/assets/javascripts/mock-ajax.js
Normal file
295
app/assets/javascripts/mock-ajax.js
Normal file
|
@ -0,0 +1,295 @@
|
|||
/*
|
||||
|
||||
Jasmine-Ajax : a set of helpers for testing AJAX requests under the Jasmine
|
||||
BDD framework for JavaScript.
|
||||
|
||||
http://github.com/pivotal/jasmine-ajax
|
||||
|
||||
Jasmine Home page: http://pivotal.github.com/jasmine
|
||||
|
||||
Copyright (c) 2008-2013 Pivotal Labs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
(function() {
|
||||
function extend(destination, source, propertiesToSkip) {
|
||||
propertiesToSkip = propertiesToSkip || [];
|
||||
for (var property in source) {
|
||||
if (!arrayContains(propertiesToSkip, property)) {
|
||||
destination[property] = source[property];
|
||||
}
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
function arrayContains(arr, item) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (arr[i] === item) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function MockAjax(global) {
|
||||
var requestTracker = new RequestTracker(),
|
||||
stubTracker = new StubTracker(),
|
||||
realAjaxFunction = global.XMLHttpRequest,
|
||||
mockAjaxFunction = fakeRequest(requestTracker, stubTracker);
|
||||
|
||||
this.install = function() {
|
||||
global.XMLHttpRequest = mockAjaxFunction;
|
||||
};
|
||||
|
||||
this.uninstall = function() {
|
||||
global.XMLHttpRequest = realAjaxFunction;
|
||||
|
||||
this.stubs.reset();
|
||||
this.requests.reset();
|
||||
};
|
||||
|
||||
this.stubRequest = function(url, data) {
|
||||
var stub = new RequestStub(url, data);
|
||||
stubTracker.addStub(stub);
|
||||
return stub;
|
||||
};
|
||||
|
||||
this.withMock = function(closure) {
|
||||
this.install();
|
||||
try {
|
||||
closure();
|
||||
} finally {
|
||||
this.uninstall();
|
||||
}
|
||||
};
|
||||
|
||||
this.requests = requestTracker;
|
||||
this.stubs = stubTracker;
|
||||
}
|
||||
|
||||
function StubTracker() {
|
||||
var stubs = [];
|
||||
|
||||
this.addStub = function(stub) {
|
||||
stubs.push(stub);
|
||||
};
|
||||
|
||||
this.reset = function() {
|
||||
stubs = [];
|
||||
};
|
||||
|
||||
this.findStub = function(url, data) {
|
||||
for (var i = stubs.length - 1; i >= 0; i--) {
|
||||
var stub = stubs[i];
|
||||
if (stub.matches(url, data)) {
|
||||
return stub;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function fakeRequest(requestTracker, stubTracker) {
|
||||
function FakeXMLHttpRequest() {
|
||||
requestTracker.track(this);
|
||||
this.requestHeaders = {};
|
||||
}
|
||||
|
||||
var iePropertiesThatCannotBeCopied = ['responseBody', 'responseText', 'responseXML', 'status', 'statusText', 'responseTimeout'];
|
||||
extend(FakeXMLHttpRequest.prototype, new window.XMLHttpRequest(), iePropertiesThatCannotBeCopied);
|
||||
extend(FakeXMLHttpRequest.prototype, {
|
||||
open: function() {
|
||||
this.method = arguments[0];
|
||||
this.url = arguments[1];
|
||||
this.username = arguments[3];
|
||||
this.password = arguments[4];
|
||||
this.readyState = 1;
|
||||
this.onreadystatechange();
|
||||
},
|
||||
|
||||
setRequestHeader: function(header, value) {
|
||||
this.requestHeaders[header] = value;
|
||||
},
|
||||
|
||||
abort: function() {
|
||||
this.readyState = 0;
|
||||
this.status = 0;
|
||||
this.statusText = "abort";
|
||||
this.onreadystatechange();
|
||||
},
|
||||
|
||||
readyState: 0,
|
||||
|
||||
onload: function() {
|
||||
},
|
||||
|
||||
onreadystatechange: function(isTimeout) {
|
||||
},
|
||||
|
||||
status: null,
|
||||
|
||||
send: function(data) {
|
||||
this.params = data;
|
||||
this.readyState = 2;
|
||||
this.onreadystatechange();
|
||||
|
||||
var stub = stubTracker.findStub(this.url, data);
|
||||
if (stub) {
|
||||
this.response(stub);
|
||||
}
|
||||
},
|
||||
|
||||
data: function() {
|
||||
var data = {};
|
||||
if (typeof this.params !== 'string') { return data; }
|
||||
var params = this.params.split('&');
|
||||
|
||||
for (var i = 0; i < params.length; ++i) {
|
||||
var kv = params[i].replace(/\+/g, ' ').split('=');
|
||||
var key = decodeURIComponent(kv[0]);
|
||||
data[key] = data[key] || [];
|
||||
data[key].push(decodeURIComponent(kv[1]));
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
getResponseHeader: function(name) {
|
||||
return this.responseHeaders[name];
|
||||
},
|
||||
|
||||
getAllResponseHeaders: function() {
|
||||
var responseHeaders = [];
|
||||
for (var i in this.responseHeaders) {
|
||||
if (this.responseHeaders.hasOwnProperty(i)) {
|
||||
responseHeaders.push(i + ': ' + this.responseHeaders[i]);
|
||||
}
|
||||
}
|
||||
return responseHeaders.join('\r\n');
|
||||
},
|
||||
|
||||
responseText: null,
|
||||
|
||||
response: function(response) {
|
||||
this.status = response.status;
|
||||
this.statusText = response.statusText || "";
|
||||
this.responseText = response.responseText || "";
|
||||
this.readyState = 4;
|
||||
this.responseHeaders = response.responseHeaders ||
|
||||
{"Content-type": response.contentType || "application/json" };
|
||||
|
||||
this.onload();
|
||||
this.onreadystatechange();
|
||||
},
|
||||
|
||||
responseTimeout: function() {
|
||||
this.readyState = 4;
|
||||
jasmine.clock().tick(30000);
|
||||
this.onreadystatechange('timeout');
|
||||
}
|
||||
});
|
||||
|
||||
return FakeXMLHttpRequest;
|
||||
}
|
||||
|
||||
function RequestTracker() {
|
||||
var requests = [];
|
||||
|
||||
this.track = function(request) {
|
||||
requests.push(request);
|
||||
};
|
||||
|
||||
this.first = function() {
|
||||
return requests[0];
|
||||
};
|
||||
|
||||
this.count = function() {
|
||||
return requests.length;
|
||||
};
|
||||
|
||||
this.reset = function() {
|
||||
requests = [];
|
||||
};
|
||||
|
||||
this.mostRecent = function() {
|
||||
return requests[requests.length - 1];
|
||||
};
|
||||
|
||||
this.at = function(index) {
|
||||
return requests[index];
|
||||
};
|
||||
|
||||
this.filter = function(url_to_match) {
|
||||
if (requests.length == 0) return [];
|
||||
var matching_requests = [];
|
||||
|
||||
for (var i = 0; i < requests.length; i++) {
|
||||
if (url_to_match instanceof RegExp &&
|
||||
url_to_match.test(requests[i].url)) {
|
||||
matching_requests.push(requests[i]);
|
||||
} else if (url_to_match instanceof Function &&
|
||||
url_to_match(requests[i])) {
|
||||
matching_requests.push(requests[i]);
|
||||
} else {
|
||||
if (requests[i].url == url_to_match) {
|
||||
matching_requests.push(requests[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matching_requests;
|
||||
};
|
||||
}
|
||||
|
||||
function RequestStub(url, stubData) {
|
||||
var split = url.split('?');
|
||||
this.url = split[0];
|
||||
|
||||
var normalizeQuery = function(query) {
|
||||
return query ? query.split('&').sort().join('&') : undefined;
|
||||
};
|
||||
|
||||
this.query = normalizeQuery(split[1]);
|
||||
this.data = normalizeQuery(stubData);
|
||||
|
||||
this.andReturn = function(options) {
|
||||
this.status = options.status || 200;
|
||||
|
||||
this.contentType = options.contentType;
|
||||
this.responseText = options.responseText;
|
||||
};
|
||||
|
||||
this.matches = function(fullUrl, data) {
|
||||
var urlSplit = fullUrl.split('?'),
|
||||
url = urlSplit[0],
|
||||
query = urlSplit[1];
|
||||
return this.url === url && this.query === normalizeQuery(query) && (!this.data || this.data === normalizeQuery(data));
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof window === "undefined" && typeof exports === "object") {
|
||||
exports.MockAjax = MockAjax;
|
||||
jasmine.Ajax = new MockAjax(exports);
|
||||
} else {
|
||||
window.MockAjax = MockAjax;
|
||||
jasmine.Ajax = new MockAjax(window);
|
||||
}
|
||||
}());
|
||||
|
|
@ -17,6 +17,7 @@ module.exports = class CocoRouter extends Backbone.Router
|
|||
'editor/:model(/:slug_or_id)(/:subview)': 'editorModelView'
|
||||
|
||||
# Experimenting with direct links
|
||||
'test/*subpath': go('test')
|
||||
'play/ladder/:levelID': go('play/ladder/ladder_view')
|
||||
'play/ladder': go('play/ladder_home')
|
||||
|
||||
|
@ -93,6 +94,8 @@ module.exports = class CocoRouter extends Backbone.Router
|
|||
return view
|
||||
|
||||
routeDirectly: (path, args) ->
|
||||
if window.currentView?.reloadOnClose
|
||||
return document.location.reload()
|
||||
path = "views/#{path}"
|
||||
ViewClass = @tryToLoadModule path
|
||||
return @showNotFound() if not ViewClass
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
|
||||
CocoClass = require 'lib/CocoClass'
|
||||
CocoView = require 'views/kinds/CocoView'
|
||||
{scriptMatchesEventPrereqs} = require './../world/script_event_prereqs'
|
||||
|
||||
allScriptModules = []
|
||||
|
@ -47,9 +48,8 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
|
|||
constructor: (options) ->
|
||||
super(options)
|
||||
@originalScripts = options.scripts
|
||||
@view = options.view
|
||||
@session = options.session
|
||||
@debugScripts = @view.getQueryVariable 'dev'
|
||||
@debugScripts = CocoView.getQueryVariable 'dev'
|
||||
@initProperties()
|
||||
@addScriptSubscriptions()
|
||||
@beginTicking()
|
||||
|
@ -210,7 +210,7 @@ module.exports = ScriptManager = class ScriptManager extends CocoClass
|
|||
noteGroup.script ?= {}
|
||||
noteGroup.script.yields ?= true
|
||||
noteGroup.script.skippable ?= true
|
||||
noteGroup.modules = (new Module(noteGroup, @view) for Module in allScriptModules when Module.neededFor(noteGroup))
|
||||
noteGroup.modules = (new Module(noteGroup) for Module in allScriptModules when Module.neededFor(noteGroup))
|
||||
|
||||
endYieldingNote: ->
|
||||
if @scriptInProgress and @currentNoteGroup?.script.yields
|
||||
|
|
|
@ -5,7 +5,7 @@ module.exports = class ScriptModule extends CocoClass
|
|||
scrubbingTime = 0
|
||||
movementTime = 0
|
||||
|
||||
constructor: (@noteGroup, @view) ->
|
||||
constructor: (@noteGroup) ->
|
||||
super()
|
||||
if not @noteGroup.prepared
|
||||
@analyzeNoteGroup(noteGroup)
|
||||
|
|
14
app/styles/test.sass
Normal file
14
app/styles/test.sass
Normal file
|
@ -0,0 +1,14 @@
|
|||
#test-view
|
||||
margin: 0 20px
|
||||
|
||||
h2
|
||||
background: #add8e6
|
||||
font-family: Arial, Geneva, sans-serif
|
||||
padding: 20px
|
||||
font-weight: bold
|
||||
|
||||
#test-wrapper
|
||||
width: 78%
|
||||
|
||||
#test-nav
|
||||
width: 20%
|
22
app/templates/test.jade
Normal file
22
app/templates/test.jade
Normal file
|
@ -0,0 +1,22 @@
|
|||
h2 Testing Page
|
||||
|
||||
ol.breadcrumb
|
||||
for path in parentFolders
|
||||
li
|
||||
a(href=path.url)= path.name
|
||||
li.active= currentFolder
|
||||
|
||||
.well.pull-left#test-wrapper
|
||||
#testing-area
|
||||
|
||||
.nav.nav-pills.nav-stacked.pull-right.well#test-nav
|
||||
for child in children
|
||||
li(class=child.type)
|
||||
a(href=child.url).small
|
||||
if child.type == 'folder'
|
||||
span.glyphicon.glyphicon-folder-close
|
||||
else
|
||||
span.glyphicon.glyphicon-file
|
||||
span.spl= child.name
|
||||
if child.type == 'folder'
|
||||
strong (#{child.size})
|
|
@ -264,7 +264,8 @@ module.exports = class CocoView extends Backbone.View
|
|||
|
||||
# Utilities
|
||||
|
||||
getQueryVariable: (param, defaultValue) ->
|
||||
getQueryVariable: (param, defaultValue) -> CocoView.getQueryVariable(param, defaultValue)
|
||||
@getQueryVariable: (param, defaultValue) ->
|
||||
query = document.location.search.substring 1
|
||||
pairs = (pair.split("=") for pair in query.split "&")
|
||||
for pair in pairs when pair[0] is param
|
||||
|
|
110
app/views/test.coffee
Normal file
110
app/views/test.coffee
Normal file
|
@ -0,0 +1,110 @@
|
|||
CocoView = require 'views/kinds/CocoView'
|
||||
template = require 'templates/test'
|
||||
|
||||
TEST_BASE_PATH = 'test/app/'
|
||||
|
||||
module.exports = class TestView extends CocoView
|
||||
id: "test-view"
|
||||
template: template
|
||||
reloadOnClose: true
|
||||
|
||||
# INITIALIZE
|
||||
|
||||
constructor: (options, @subPath='') ->
|
||||
super(options)
|
||||
@subPath = @subPath[1..] if @subPath[0] is '/'
|
||||
@loadJasmine() unless TestView.loaded
|
||||
|
||||
loadJasmine: ->
|
||||
@queue = new createjs.LoadQueue()
|
||||
@queue.on('complete', @scriptsLoaded, @)
|
||||
for f in ['jasmine', 'jasmine-html', 'boot', 'mock-ajax', 'test-app']
|
||||
@queue.loadFile({
|
||||
src: "/javascripts/#{f}.js"
|
||||
type: createjs.LoadQueue.JAVASCRIPT
|
||||
})
|
||||
|
||||
scriptsLoaded: ->
|
||||
@initSpecFiles()
|
||||
@render()
|
||||
@runTests()
|
||||
|
||||
# RENDER DATA
|
||||
|
||||
getRenderData: ->
|
||||
c = super(arguments...)
|
||||
c.parentFolders = @getParentFolders()
|
||||
c.children = @getChildren()
|
||||
parts = @subPath.split('/')
|
||||
c.currentFolder = parts[parts.length-1] or parts[parts.length-2] or 'All'
|
||||
c
|
||||
|
||||
getParentFolders: ->
|
||||
return [] unless @subPath
|
||||
paths = []
|
||||
parts = @subPath.split('/')
|
||||
while parts.length
|
||||
parts.pop()
|
||||
paths.unshift {
|
||||
name: parts[parts.length-1] or 'All'
|
||||
url: '/test/' + parts.join('/')
|
||||
}
|
||||
paths
|
||||
|
||||
getChildren: ->
|
||||
return [] unless @specFiles
|
||||
folders = {}
|
||||
files = {}
|
||||
|
||||
requirePrefix = TEST_BASE_PATH + @subPath
|
||||
if requirePrefix[requirePrefix.length-1] isnt '/'
|
||||
requirePrefix += '/'
|
||||
|
||||
for f in @specFiles
|
||||
f = f[requirePrefix.length..]
|
||||
continue unless f
|
||||
parts = f.split('/')
|
||||
name = parts[0]
|
||||
group = if parts.length is 1 then files else folders
|
||||
group[name] ?= 0
|
||||
group[name] += 1
|
||||
|
||||
children = []
|
||||
urlPrefix = '/test/'+@subPath
|
||||
urlPrefix += '/' if urlPrefix[urlPrefix.length-1] isnt '/'
|
||||
|
||||
for name in _.keys(folders)
|
||||
children.push {
|
||||
type:'folder',
|
||||
url: urlPrefix+name
|
||||
name: name+'/'
|
||||
size: folders[name]
|
||||
}
|
||||
for name in _.keys(files)
|
||||
children.push {
|
||||
type:'file',
|
||||
url: urlPrefix+name
|
||||
name: name
|
||||
}
|
||||
children
|
||||
|
||||
# RUNNING TESTS
|
||||
|
||||
initSpecFiles: ->
|
||||
allFiles = window.require.list()
|
||||
@specFiles = (f for f in allFiles when f.indexOf('.spec') > -1)
|
||||
if @subPath
|
||||
prefix = TEST_BASE_PATH + @subPath
|
||||
@specFiles = (f for f in @specFiles when f.startsWith prefix)
|
||||
|
||||
runTests: ->
|
||||
describe 'CodeCombat Client', =>
|
||||
beforeEach ->
|
||||
jasmine.Ajax.install()
|
||||
# TODO get some setup and teardown prepped
|
||||
require f for f in @specFiles # runs the tests
|
||||
|
||||
destroy: ->
|
||||
# hack to get jasmine tests to properly run again on clicking links, and make sure if you
|
||||
# leave this page (say, back to the main site) that test stuff doesn't follow you.
|
||||
document.location.reload()
|
|
@ -38,7 +38,7 @@ exports.config =
|
|||
'javascripts/aether.js': ///^(
|
||||
(bower_components[\/\\]aether[\/\\]build[\/\\]aether.js)
|
||||
)///
|
||||
# 'test/javascripts/test.js': /^test[\/\\](?!vendor)/
|
||||
'javascripts/test-app.js': /^test[\/\\]app/
|
||||
# 'test/javascripts/test-vendor.js': /^test[\/\\](?=vendor)/
|
||||
order:
|
||||
before: [
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
# Karma has real issues logging arbitrary objects
|
||||
# But we log them all the time
|
||||
# Wrapping console.log so this stops messing up our tests.
|
||||
|
||||
ll = console.log
|
||||
|
||||
console.log = (splat...) ->
|
||||
try
|
||||
s = (JSON.stringify(i) for i in splat)
|
||||
ll(_.string.join(', ', s...))
|
||||
catch TypeError
|
||||
console.log('could not log what you tried to log')
|
||||
|
||||
console.warn = (splat...) ->
|
||||
console.log("WARN", splat...)
|
||||
|
||||
console.error = (splat...) ->
|
||||
console.log("ERROR", splat...)
|
||||
|
||||
|
||||
# When the page loads the first time, it doesn't actually load if there's no 'me' loaded.
|
||||
# Get past this by creating a fake 'me'
|
||||
|
||||
#User = require 'models/User'
|
||||
#auth = require 'lib/auth'
|
||||
#auth.me = new User({anonymous:true})
|
|
@ -1,11 +1,11 @@
|
|||
describe('ScriptManager', ->
|
||||
SM = require 'lib/scripts/ScriptManager'
|
||||
ScriptManager = require 'lib/scripts/ScriptManager'
|
||||
xit('broadcasts note with event upon hearing from channel', ->
|
||||
note = {channel: 'cnn', event: {1:1}}
|
||||
noteGroup = {duration: 0, notes: [note]}
|
||||
script = {channel: 'pbs', noteChain: [noteGroup]}
|
||||
|
||||
sm = new SM({scripts: [script]})
|
||||
sm = new ScriptManager({scripts: [script]})
|
||||
sm.paused = false
|
||||
|
||||
gotEvent = {}
|
||||
|
@ -30,7 +30,7 @@ describe('ScriptManager', ->
|
|||
|
||||
noteChain: [noteGroup]
|
||||
|
||||
sm = new SM([script])
|
||||
sm = new ScriptManager([script])
|
||||
sm.paused = false
|
||||
|
||||
gotEvent = null
|
||||
|
@ -52,7 +52,7 @@ describe('ScriptManager', ->
|
|||
note = {event: {1:1}} # channel is required
|
||||
noteGroup = {notes: [note]}
|
||||
script = {channel: 'pbs', noteChain: [noteGroup]}
|
||||
sm = new SM([script])
|
||||
sm = new ScriptManager([script])
|
||||
expect(sm.subscriptions['pbs']).toBe(undefined)
|
||||
sm.destroy()
|
||||
)
|
||||
|
@ -71,7 +71,7 @@ describe('ScriptManager', ->
|
|||
|
||||
script = {channel: 'pbs', noteChain: [noteGroup]}
|
||||
|
||||
sm = new SM([script])
|
||||
sm = new ScriptManager([script])
|
||||
sm.paused = false
|
||||
|
||||
Backbone.Mediator.publish('pbs')
|
||||
|
@ -93,7 +93,7 @@ describe('ScriptManager', ->
|
|||
noteGroup1 = {duration: 0, notes: [note1]}
|
||||
noteGroup2 = {duration: 0, notes: [note2]}
|
||||
script = {channel: 'pbs', noteChain: [noteGroup1, noteGroup2]}
|
||||
sm = new SM({scripts:[script]})
|
||||
sm = new ScriptManager({scripts:[script]})
|
||||
sm.paused = false
|
||||
|
||||
gotCnnEvent = null
|
||||
|
@ -132,7 +132,7 @@ describe('ScriptManager', ->
|
|||
script1 = {channel: 'channel1', id: 'channel1Script', noteChain: [noteGroup1]}
|
||||
script2 = {channel: 'channel2', scriptPrereqs: ['channel1Script'], noteChain: [noteGroup2]}
|
||||
|
||||
sm = new SM([script1, script2])
|
||||
sm = new ScriptManager([script1, script2])
|
||||
sm.paused = false
|
||||
gotCbsEvent = null
|
||||
f = (event) -> gotCbsEvent = event
|
|
@ -1,21 +0,0 @@
|
|||
describe 'forms library', ->
|
||||
forms = require 'lib/forms'
|
||||
Router = require 'lib/Router'
|
||||
#it 'adds errors to the create account form', ->
|
||||
# router = new Router()
|
||||
# router.openRoute('home')
|
||||
#
|
||||
# # doesn't work
|
||||
# console.log "going to click", $('button[data-target="modal/signup"]').click().length, "signup buttons"
|
||||
# forms.applyErrorsToForm($('#signup-modal'), [message:"is bad", property:"email"])
|
||||
# messages = $('#signup-modal .help-inline')
|
||||
# expect(messages.length).toBe(1)
|
||||
# expect($('#signup-modal .error').length).toBe(1)
|
||||
# expect(messages.text()).toBe('Email is bad.')
|
||||
#
|
||||
#it 'clears errors from the create account form', ->
|
||||
# expect($('#signup-modal .help-inline').length).toBe(1)
|
||||
# expect($('#signup-modal .error').length).toBe(1)
|
||||
# forms.clearFormAlerts($('#signup-modal'))
|
||||
# expect($('#signup-modal .help-inline').length).toBe(0)
|
||||
# expect($('#signup-modal .error').length).toBe(0)
|
|
@ -1,26 +0,0 @@
|
|||
describe('Path.createPath', ->
|
||||
path = require 'lib/surface/path'
|
||||
it('ignores the first point', ->
|
||||
points = [[0,0], [1,1], [2,2]]
|
||||
g = new createjs.Graphics()
|
||||
g.lineTo = jasmine.createSpy('graphicz')
|
||||
path.createPath(points, {tailColor:[100,100,100,0.0]}, g)
|
||||
expect(g.lineTo.calls.length).toBe(1)
|
||||
expect(g.lineTo.calls[0].args[0]).toBe(points[2])
|
||||
)
|
||||
|
||||
# # BROKEN
|
||||
xit('dots correctly', ->
|
||||
points = ([x,x] for x in [0..30])
|
||||
g = new createjs.Graphics()
|
||||
calls = []
|
||||
funcs = ['lineTo', 'moveTo', 'beginStroke', 'endStroke', 'setStrokeStyle']
|
||||
for funcName in funcs
|
||||
f = (funcName) => (args...) =>
|
||||
calls.push("#{funcName}(#{args})")
|
||||
g[funcName] = jasmine.createSpy('graphics').andCallFake(f(funcName))
|
||||
path.createPath(points, {dotted:true}, g)
|
||||
expect(g.beginStroke.calls.length).toBe(4)
|
||||
)
|
||||
)
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
describe 'Router', ->
|
||||
Router = require 'lib/Router'
|
||||
xit 'caches the home view', ->
|
||||
router = new Router()
|
||||
router.openRoute('home')
|
||||
#currentView doesn't exist
|
||||
expect(router.cache['home']).toBe(router.currentView)
|
||||
home = router.currentView
|
||||
router.openRoute('home')
|
||||
expect(router.cache['home']).toBe(router.currentView)
|
|
@ -1,9 +1,7 @@
|
|||
describe('World', ->
|
||||
describe('GoalManager', ->
|
||||
GoalManager = require 'lib/world/GoalManager'
|
||||
#validator = require 'validators/goal'
|
||||
|
||||
killGoal = { name: 'Kill Guy', killGuy: ['Guy1', 'Guy2'], id:'killguy'}
|
||||
saveGoal = { name: 'Save Guy', saveGuy: ['Guy1', 'Guy2'], id:'saveguy'}
|
||||
killGoal = { name: 'Kill Guy', killThangs: ['Guy1', 'Guy2'], id:'killguy'}
|
||||
saveGoal = { name: 'Save Guy', saveThangs: ['Guy1', 'Guy2'], id:'saveguy'}
|
||||
getToLocGoal = { name: 'Go there', getToLocation: {target:'Frying Pan', who:'Potato'}, id:'id'}
|
||||
keepFromLocGoal = { name: 'Go there', keepFromLocation: {target:'Frying Pan', who:'Potato'}, id:'id'}
|
||||
leaveMapGoal = { name: 'Go away', leaveOffSide: {who:'Yall'}, id:'id'}
|
||||
|
@ -11,18 +9,7 @@ describe('World', ->
|
|||
getItemGoal = { name: 'Mine', getItem: {who:'Grabby', itemID:'Sandwich'}, id:'id'}
|
||||
keepItemGoal = { name: 'Not Yours', keepFromGettingItem: {who:'Grabby', itemID:'Sandwich'}, id:'id'}
|
||||
|
||||
xit 'uses valid goals', ->
|
||||
goals = [
|
||||
killGoal, saveGoal,
|
||||
getToLocGoal, keepFromLocGoal,
|
||||
leaveMapGoal, stayMapGoal,
|
||||
getItemGoal, keepItemGoal,
|
||||
]
|
||||
for goal in goals
|
||||
result = validator(goal)
|
||||
expect(result.valid).toBe(true)
|
||||
|
||||
xit('handles kill goal', ->
|
||||
it('handles kill goal', ->
|
||||
gm = new GoalManager()
|
||||
gm.setGoals([killGoal])
|
||||
gm.worldGenerationWillBegin()
|
||||
|
@ -42,7 +29,7 @@ describe('World', ->
|
|||
expect(goalStates.killguy.keyFrame).toBe(20)
|
||||
)
|
||||
|
||||
xit('handles save goal', ->
|
||||
it('handles save goal', ->
|
||||
gm = new GoalManager()
|
||||
gm.setGoals([saveGoal])
|
||||
gm.worldGenerationWillBegin()
|
|
@ -1,14 +0,0 @@
|
|||
describe 'Thang', ->
|
||||
Thang = require 'lib/world/thang'
|
||||
World = require 'lib/world/world'
|
||||
Rectangle = require 'lib/world/rectangle'
|
||||
Vector = require 'lib/world/vector'
|
||||
world = new World()
|
||||
|
||||
#it 'intersects itself', ->
|
||||
# spyOn(Vector, 'subtract').andCallThrough()
|
||||
# for thang in world.thangs
|
||||
# spyOn(thang, 'intersects').andCallThrough()
|
||||
# expect(thang.intersects thang).toBeTruthy()
|
||||
# #console.log thang.intersects.calls[0].args + ''
|
||||
# #console.log "Vector.subtract calls: " + Vector.subtract.calls.length
|
|
@ -1,2 +0,0 @@
|
|||
describe 'World', ->
|
||||
World = require 'lib/world/world'
|
52
test/app/models/SuperModel.spec.coffee
Normal file
52
test/app/models/SuperModel.spec.coffee
Normal file
|
@ -0,0 +1,52 @@
|
|||
SuperModel = require 'models/SuperModel'
|
||||
User = require 'models/User'
|
||||
ComponentsCollection = require 'collections/ComponentsCollection'
|
||||
|
||||
describe 'SuperModel', ->
|
||||
describe 'progress (property)', ->
|
||||
it 'is finished by default', ->
|
||||
s = new SuperModel()
|
||||
expect(s.finished()).toBeTruthy()
|
||||
|
||||
it 'is based on resource completion and value', (done) ->
|
||||
s = new SuperModel()
|
||||
r1 = s.addSomethingResource('???', 2)
|
||||
r2 = s.addSomethingResource('???', 3)
|
||||
expect(s.progress).toBe(0)
|
||||
r1.markLoaded()
|
||||
|
||||
# progress updates are deferred so defer more
|
||||
_.defer ->
|
||||
expect(s.progress).toBe(0.4)
|
||||
r2.markLoaded()
|
||||
_.defer ->
|
||||
expect(s.progress).toBe(1)
|
||||
done()
|
||||
|
||||
describe 'loadModel (function)', ->
|
||||
it 'starts loading the model if it isn\'t already loading', ->
|
||||
s = new SuperModel()
|
||||
m = new User({_id:'12345'})
|
||||
s.loadModel(m, 'user')
|
||||
request = jasmine.Ajax.requests.mostRecent()
|
||||
expect(request).toBeDefined()
|
||||
|
||||
it 'also loads collections', ->
|
||||
s = new SuperModel()
|
||||
c = new ComponentsCollection()
|
||||
s.loadModel(c, 'collection')
|
||||
request = jasmine.Ajax.requests.mostRecent()
|
||||
expect(request).toBeDefined()
|
||||
|
||||
describe 'events', ->
|
||||
it 'triggers "loaded-all" when finished', (done) ->
|
||||
s = new SuperModel()
|
||||
m = new User({_id:'12345'})
|
||||
triggered = false
|
||||
s.once 'loaded-all', -> triggered = true
|
||||
s.loadModel(m, 'user')
|
||||
request = jasmine.Ajax.requests.mostRecent()
|
||||
request.response({status: 200, responseText: '{}'})
|
||||
_.defer ->
|
||||
expect(triggered).toBe(true)
|
||||
done()
|
|
@ -1,4 +0,0 @@
|
|||
describe 'editor/level/thangs_tab', ->
|
||||
ComponentsTabView = require 'views/editor/level/components_tab_view'
|
||||
|
||||
it 'does stuff', ->
|
|
@ -1,4 +0,0 @@
|
|||
describe 'editor/level', ->
|
||||
EditorLevelView = require 'views/editor/level/home'
|
||||
|
||||
it 'does stuff', ->
|
|
@ -1,4 +0,0 @@
|
|||
describe 'editor/level/scripts_tab', ->
|
||||
ScriptsTabView = require 'views/editor/level/scripts_tab_view'
|
||||
|
||||
it 'does stuff', ->
|
|
@ -1,4 +0,0 @@
|
|||
describe 'editor/level/settings_tab', ->
|
||||
SettingsTabView = require 'views/editor/level/settings_tab_view'
|
||||
|
||||
it 'does stuff', ->
|
|
@ -1,4 +0,0 @@
|
|||
describe 'editor/level/systems_tab', ->
|
||||
SystemsTabView = require 'views/editor/level/systems_tab_view'
|
||||
|
||||
it 'does stuff', ->
|
|
@ -1,4 +0,0 @@
|
|||
describe 'editor/level/thangs_tab', ->
|
||||
ThangsTabView = require 'views/editor/level/thangs_tab_view'
|
||||
|
||||
it 'does stuff', ->
|
0
test/app/views/home_view.spec.coffee
Normal file
0
test/app/views/home_view.spec.coffee
Normal file
55
vendor/styles/jasmine.css
vendored
Executable file
55
vendor/styles/jasmine.css
vendored
Executable file
|
@ -0,0 +1,55 @@
|
|||
body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
|
||||
|
||||
.html-reporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; }
|
||||
.html-reporter a { text-decoration: none; }
|
||||
.html-reporter a:hover { text-decoration: underline; }
|
||||
.html-reporter p, .html-reporter h1, .html-reporter h2, .html-reporter h3, .html-reporter h4, .html-reporter h5, .html-reporter h6 { margin: 0; line-height: 14px; }
|
||||
.html-reporter .banner, .html-reporter .symbol-summary, .html-reporter .summary, .html-reporter .result-message, .html-reporter .spec .description, .html-reporter .spec-detail .description, .html-reporter .alert .bar, .html-reporter .stack-trace { padding-left: 9px; padding-right: 9px; }
|
||||
.html-reporter .banner .version { margin-left: 14px; }
|
||||
.html-reporter #jasmine_content { position: fixed; right: 100%; }
|
||||
.html-reporter .version { color: #aaaaaa; }
|
||||
.html-reporter .banner { margin-top: 14px; }
|
||||
.html-reporter .duration { color: #aaaaaa; float: right; }
|
||||
.html-reporter .symbol-summary { overflow: hidden; *zoom: 1; margin: 14px 0; }
|
||||
.html-reporter .symbol-summary li { display: inline-block; height: 8px; width: 14px; font-size: 16px; }
|
||||
.html-reporter .symbol-summary li.passed { font-size: 14px; }
|
||||
.html-reporter .symbol-summary li.passed:before { color: #5e7d00; content: "\02022"; }
|
||||
.html-reporter .symbol-summary li.failed { line-height: 9px; }
|
||||
.html-reporter .symbol-summary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
|
||||
.html-reporter .symbol-summary li.disabled { font-size: 14px; }
|
||||
.html-reporter .symbol-summary li.disabled:before { color: #bababa; content: "\02022"; }
|
||||
.html-reporter .symbol-summary li.pending { line-height: 17px; }
|
||||
.html-reporter .symbol-summary li.pending:before { color: #ba9d37; content: "*"; }
|
||||
.html-reporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; }
|
||||
.html-reporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
|
||||
.html-reporter .bar.failed { background-color: #b03911; }
|
||||
.html-reporter .bar.passed { background-color: #a6b779; }
|
||||
.html-reporter .bar.skipped { background-color: #bababa; }
|
||||
.html-reporter .bar.menu { background-color: #fff; color: #aaaaaa; }
|
||||
.html-reporter .bar.menu a { color: #333333; }
|
||||
.html-reporter .bar a { color: white; }
|
||||
.html-reporter.spec-list .bar.menu.failure-list, .html-reporter.spec-list .results .failures { display: none; }
|
||||
.html-reporter.failure-list .bar.menu.spec-list, .html-reporter.failure-list .summary { display: none; }
|
||||
.html-reporter .running-alert { background-color: #666666; }
|
||||
.html-reporter .results { margin-top: 14px; }
|
||||
.html-reporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; }
|
||||
.html-reporter.showDetails .summaryMenuItem:hover { text-decoration: underline; }
|
||||
.html-reporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; }
|
||||
.html-reporter.showDetails .summary { display: none; }
|
||||
.html-reporter.showDetails #details { display: block; }
|
||||
.html-reporter .summaryMenuItem { font-weight: bold; text-decoration: underline; }
|
||||
.html-reporter .summary { margin-top: 14px; }
|
||||
.html-reporter .summary ul { list-style-type: none; margin-left: 14px; padding-top: 0; padding-left: 0; }
|
||||
.html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; }
|
||||
.html-reporter .summary li.passed a { color: #5e7d00; }
|
||||
.html-reporter .summary li.failed a { color: #b03911; }
|
||||
.html-reporter .summary li.pending a { color: #ba9d37; }
|
||||
.html-reporter .description + .suite { margin-top: 0; }
|
||||
.html-reporter .suite { margin-top: 14px; }
|
||||
.html-reporter .suite a { color: #333333; }
|
||||
.html-reporter .failures .spec-detail { margin-bottom: 28px; }
|
||||
.html-reporter .failures .spec-detail .description { background-color: #b03911; }
|
||||
.html-reporter .failures .spec-detail .description a { color: white; }
|
||||
.html-reporter .result-message { padding-top: 14px; color: #333333; white-space: pre; }
|
||||
.html-reporter .result-message span.result { display: block; }
|
||||
.html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; }
|
Loading…
Reference in a new issue