Convert tests to mocha+chai+sinon

This commit is contained in:
John Firebaugh
2012-12-03 15:11:32 -05:00
parent 9057d40672
commit c7fa59661a
25 changed files with 13468 additions and 3453 deletions

8
js/lib/d3.one.js Normal file
View File

@@ -0,0 +1,8 @@
d3.selection.prototype.one = function (type, listener, capture) {
var target = this, typeOnce = type + ".once";
function one() {
target.on(typeOnce, null);
listener.apply(this, arguments);
}
target.on(typeOnce, one, capture);
};

View File

@@ -2,103 +2,82 @@
<html>
<head>
<meta charset='utf-8'>
<title>Jasmine Spec Runner</title>
<title>Mocha Tests</title>
<link rel="stylesheet" href="lib/mocha.css">
</head>
<body>
<div id="mocha"></div>
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>
<script type="text/javascript" src="lib/console-runner.js"></script>
<script type="text/javascript" src="lib/bind-shim.js"></script>
<script type="text/javascript" src="lib/happen.js"></script>
<script src="lib/mocha.js"></script>
<script src="lib/chai.js"></script>
<script src="lib/sinon.js"></script>
<script src="lib/sinon-chai.js"></script>
<script src="lib/bind-shim.js"></script>
<script src="lib/happen.js"></script>
<!-- include source files here... -->
<script type='text/javascript' src='../js/lib/lodash.js'></script>
<script type='text/javascript' src='../js/lib/d3.v3.js'></script>
<script type='text/javascript' src='../js/lib/sha.js'></script>
<script type='text/javascript' src='../js/lib/d3.geo.tile.js'></script>
<script type='text/javascript' src='../js/lib/d3.size.js'></script>
<script type='text/javascript' src='../js/lib/ohauth.js'></script>
<script type='text/javascript' src='../js/lib/jxon.js'></script>
<script src='../js/lib/lodash.js'></script>
<script src='../js/lib/d3.v3.js'></script>
<script src='../js/lib/sha.js'></script>
<script src='../js/lib/d3.geo.tile.js'></script>
<script src='../js/lib/d3.size.js'></script>
<script src='../js/lib/d3.one.js'></script>
<script src='../js/lib/ohauth.js'></script>
<script src='../js/lib/jxon.js'></script>
<script type='text/javascript' src='../js/id/id.js'></script>
<script type='text/javascript' src='../js/id/util.js'></script>
<script type='text/javascript' src='../js/id/oauth.js'></script>
<script type='text/javascript' src='../js/id/renderer/style.js'></script>
<script src='../js/id/id.js'></script>
<script src='../js/id/util.js'></script>
<script src='../js/id/oauth.js'></script>
<script src='../js/id/renderer/style.js'></script>
<script type='text/javascript' src='../js/id/renderer/background.js'></script>
<script type='text/javascript' src='../js/id/renderer/map.js'></script>
<script type='text/javascript' src='../js/id/renderer/hash.js'></script>
<script type='text/javascript' src='../js/id/renderer/markers.js'></script>
<script type='text/javascript' src='../js/id/renderer/style.js'></script>
<script type='text/javascript' src='../js/id/ui/inspector.js'></script>
<script src='../js/id/renderer/background.js'></script>
<script src='../js/id/renderer/map.js'></script>
<script src='../js/id/renderer/hash.js'></script>
<script src='../js/id/renderer/markers.js'></script>
<script src='../js/id/renderer/style.js'></script>
<script src='../js/id/ui/inspector.js'></script>
<script src='../js/id/ui/commit.js'></script>
<script src='../js/id/ui/loading.js'></script>
<script src='../js/id/ui/userpanel.js'></script>
<script type='text/javascript' src='../js/id/actions/modes.js'></script>
<script type='text/javascript' src='../js/id/actions/actions.js'></script>
<script src='../js/id/actions/modes.js'></script>
<script src='../js/id/actions/actions.js'></script>
<script type='text/javascript' src='../js/id/controller/controller.js'></script>
<script src='../js/id/controller/controller.js'></script>
<script type='text/javascript' src='../js/id/format/format.js'></script>
<script type='text/javascript' src='../js/id/format/geojson.js'></script>
<script type='text/javascript' src='../js/id/format/xml.js'></script>
<script src='../js/id/format/format.js'></script>
<script src='../js/id/format/geojson.js'></script>
<script src='../js/id/format/xml.js'></script>
<script type='text/javascript' src='../js/id/graph/entity.js'></script>
<script type='text/javascript' src='../js/id/graph/way.js'></script>
<script type='text/javascript' src='../js/id/graph/graph.js'></script>
<script type='text/javascript' src='../js/id/graph/history.js'></script>
<script type='text/javascript' src='../js/id/connection.js'></script>
<script src='../js/id/graph/entity.js'></script>
<script src='../js/id/graph/way.js'></script>
<script src='../js/id/graph/graph.js'></script>
<script src='../js/id/graph/history.js'></script>
<script src='../js/id/connection.js'></script>
<script>
iD.debug = true;
mocha.setup('bdd');
var expect = chai.expect;
</script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/util.js"></script>
<script type="text/javascript" src="spec/background.js"></script>
<script type="text/javascript" src="spec/way.js"></script>
<script type="text/javascript" src="spec/map.js"></script>
<script type="text/javascript" src="spec/hash.js"></script>
<script type="text/javascript" src="spec/oauth.js"></script>
<script type="text/javascript" src="spec/graph.js"></script>
<script type="text/javascript" src="spec/entity.js"></script>
<script type="text/javascript" src="spec/connection.js"></script>
<script type="text/javascript" src="spec/geojson.js"></script>
<script type="text/javascript" src="spec/xml.js"></script>
<script type="text/javascript" src="spec/style.js"></script>
<script type="text/javascript" src="spec/inspector.js"></script>
<script src="spec/util.js"></script>
<script src="spec/background.js"></script>
<script src="spec/way.js"></script>
<script src="spec/map.js"></script>
<script src="spec/hash.js"></script>
<script src="spec/oauth.js"></script>
<script src="spec/graph.js"></script>
<script src="spec/entity.js"></script>
<script src="spec/connection.js"></script>
<script src="spec/geojson.js"></script>
<script src="spec/xml.js"></script>
<script src="spec/style.js"></script>
<script src="spec/inspector.js"></script>
<script type="text/javascript">
iD.debug = true;
<script>
mocha.run();
</script>
<script type="text/javascript">
(function () {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
window.console_reporter = new jasmine.ConsoleReporter();
jasmineEnv.addReporter(console_reporter);
jasmineEnv.specFilter = function (spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function () {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>

3767
test/lib/chai.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,20 +0,0 @@
Copyright (c) 2008-2011 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.

View File

@@ -1,616 +0,0 @@
jasmine.HtmlReporterHelpers = {};
jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.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;
};
jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
var results = child.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
return status;
};
jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
var parentDiv = this.dom.summary;
var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
var parent = child[parentSuite];
if (parent) {
if (typeof this.views.suites[parent.id] == 'undefined') {
this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
}
parentDiv = this.views.suites[parent.id].element;
}
parentDiv.appendChild(childElement);
};
jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
for(var fn in jasmine.HtmlReporterHelpers) {
ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
}
};
jasmine.HtmlReporter = function(_doc) {
var self = this;
var doc = _doc || window.document;
var reporterView;
var dom = {};
// Jasmine Reporter Public Interface
self.logRunningSpecs = false;
self.reportRunnerStarting = function(runner) {
var specs = runner.specs() || [];
if (specs.length == 0) {
return;
}
createReporterDom(runner.env.versionString());
doc.body.appendChild(dom.reporter);
reporterView = new jasmine.HtmlReporter.ReporterView(dom);
reporterView.addSpecs(specs, self.specFilter);
};
self.reportRunnerResults = function(runner) {
reporterView && reporterView.complete();
};
self.reportSuiteResults = function(suite) {
reporterView.suiteComplete(suite);
};
self.reportSpecStarting = function(spec) {
if (self.logRunningSpecs) {
self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
self.reportSpecResults = function(spec) {
reporterView.specComplete(spec);
};
self.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
self.specFilter = function(spec) {
if (!focusedSpecName()) {
return true;
}
return spec.getFullName().indexOf(focusedSpecName()) === 0;
};
return self;
function focusedSpecName() {
var specName;
(function memoizeFocusedSpec() {
if (specName) {
return;
}
var paramMap = [];
var params = doc.location.search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
specName = paramMap.spec;
})();
return specName;
}
function createReporterDom(version) {
dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
dom.banner = self.createDom('div', { className: 'banner' },
self.createDom('span', { className: 'title' }, "Jasmine "),
self.createDom('span', { className: 'version' }, version)),
dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
dom.alert = self.createDom('div', {className: 'alert'}),
dom.results = self.createDom('div', {className: 'results'},
dom.summary = self.createDom('div', { className: 'summary' }),
dom.details = self.createDom('div', { id: 'details' }))
);
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);jasmine.HtmlReporter.ReporterView = function(dom) {
this.startedAt = new Date();
this.runningSpecCount = 0;
this.completeSpecCount = 0;
this.passedCount = 0;
this.failedCount = 0;
this.skippedCount = 0;
this.createResultsMenu = function() {
this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
' | ',
this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
this.summaryMenuItem.onclick = function() {
dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
};
this.detailsMenuItem.onclick = function() {
showDetails();
};
};
this.addSpecs = function(specs, specFilter) {
this.totalSpecCount = specs.length;
this.views = {
specs: {},
suites: {}
};
for (var i = 0; i < specs.length; i++) {
var spec = specs[i];
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
if (specFilter(spec)) {
this.runningSpecCount++;
}
}
};
this.specComplete = function(spec) {
this.completeSpecCount++;
if (isUndefined(this.views.specs[spec.id])) {
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
}
var specView = this.views.specs[spec.id];
switch (specView.status()) {
case 'passed':
this.passedCount++;
break;
case 'failed':
this.failedCount++;
break;
case 'skipped':
this.skippedCount++;
break;
}
specView.refresh();
this.refresh();
};
this.suiteComplete = function(suite) {
var suiteView = this.views.suites[suite.id];
if (isUndefined(suiteView)) {
return;
}
suiteView.refresh();
};
this.refresh = function() {
if (isUndefined(this.resultsMenu)) {
this.createResultsMenu();
}
// currently running UI
if (isUndefined(this.runningAlert)) {
this.runningAlert = this.createDom('a', {href: "?", className: "runningAlert bar"});
dom.alert.appendChild(this.runningAlert);
}
this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
// skipped specs UI
if (isUndefined(this.skippedAlert)) {
this.skippedAlert = this.createDom('a', {href: "?", className: "skippedAlert bar"});
}
this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
if (this.skippedCount === 1 && isDefined(dom.alert)) {
dom.alert.appendChild(this.skippedAlert);
}
// passing specs UI
if (isUndefined(this.passedAlert)) {
this.passedAlert = this.createDom('span', {href: "?", className: "passingAlert bar"});
}
this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
// failing specs UI
if (isUndefined(this.failedAlert)) {
this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
}
this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
if (this.failedCount === 1 && isDefined(dom.alert)) {
dom.alert.appendChild(this.failedAlert);
dom.alert.appendChild(this.resultsMenu);
}
// summary info
this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
};
this.complete = function() {
dom.alert.removeChild(this.runningAlert);
this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
if (this.failedCount === 0) {
dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
} else {
showDetails();
}
dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
};
return this;
function showDetails() {
if (dom.reporter.className.search(/showDetails/) === -1) {
dom.reporter.className += " showDetails";
}
}
function isUndefined(obj) {
return typeof obj === 'undefined';
}
function isDefined(obj) {
return !isUndefined(obj);
}
function specPluralizedFor(count) {
var str = count + " spec";
if (count > 1) {
str += "s"
}
return str;
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
this.spec = spec;
this.dom = dom;
this.views = views;
this.symbol = this.createDom('li', { className: 'pending' });
this.dom.symbolSummary.appendChild(this.symbol);
this.summary = this.createDom('div', { className: 'specSummary' },
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.description)
);
this.detail = this.createDom('div', { className: 'specDetail' },
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.getFullName())
);
};
jasmine.HtmlReporter.SpecView.prototype.status = function() {
return this.getSpecStatus(this.spec);
};
jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
this.symbol.className = this.status();
switch (this.status()) {
case 'skipped':
break;
case 'passed':
this.appendSummaryToSuiteDiv();
break;
case 'failed':
this.appendSummaryToSuiteDiv();
this.appendFailureDetail();
break;
}
};
jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
this.summary.className += ' ' + this.status();
this.appendToSummary(this.spec, this.summary);
};
jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
this.detail.className += ' ' + this.status();
var resultItems = this.spec.results().getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
this.detail.appendChild(messagesDiv);
this.dom.details.appendChild(this.detail);
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
this.suite = suite;
this.dom = dom;
this.views = views;
this.element = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(this.suite.getFullName()) }, this.suite.description)
);
this.appendToSummary(this.suite, this.element);
};
jasmine.HtmlReporter.SuiteView.prototype.status = function() {
return this.getSpecStatus(this.suite);
};
jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
this.element.className += " " + this.status();
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
/* @deprecated Use jasmine.HtmlReporter instead
*/
jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.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;
};
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
this.createDom('span', { className: 'title' }, "Jasmine"),
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onclick = function(evt) {
if (showPassed.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onclick = function(evt) {
if (showSkipped.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
//do it twice for IE
this.runnerDiv.setAttribute("className", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount === 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
if (this.logRunningSpecs) {
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap.spec) {
return true;
}
return spec.getFullName().indexOf(paramMap.spec) === 0;
};

View File

@@ -1,81 +0,0 @@
body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
#HTMLReporter { font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; }
#HTMLReporter a { text-decoration: none; }
#HTMLReporter a:hover { text-decoration: underline; }
#HTMLReporter p, #HTMLReporter h1, #HTMLReporter h2, #HTMLReporter h3, #HTMLReporter h4, #HTMLReporter h5, #HTMLReporter h6 { margin: 0; line-height: 14px; }
#HTMLReporter .banner, #HTMLReporter .symbolSummary, #HTMLReporter .summary, #HTMLReporter .resultMessage, #HTMLReporter .specDetail .description, #HTMLReporter .alert .bar, #HTMLReporter .stackTrace { padding-left: 9px; padding-right: 9px; }
#HTMLReporter #jasmine_content { position: fixed; right: 100%; }
#HTMLReporter .version { color: #aaaaaa; }
#HTMLReporter .banner { margin-top: 14px; }
#HTMLReporter .duration { color: #aaaaaa; float: right; }
#HTMLReporter .symbolSummary { overflow: hidden; *zoom: 1; margin: 14px 0; }
#HTMLReporter .symbolSummary li { display: block; float: left; height: 7px; width: 14px; margin-bottom: 7px; font-size: 16px; }
#HTMLReporter .symbolSummary li.passed { font-size: 14px; }
#HTMLReporter .symbolSummary li.passed:before { color: #5e7d00; content: "\02022"; }
#HTMLReporter .symbolSummary li.failed { line-height: 9px; }
#HTMLReporter .symbolSummary li.failed:before { color: #b03911; content: "x"; font-weight: bold; margin-left: -1px; }
#HTMLReporter .symbolSummary li.skipped { font-size: 14px; }
#HTMLReporter .symbolSummary li.skipped:before { color: #bababa; content: "\02022"; }
#HTMLReporter .symbolSummary li.pending { line-height: 11px; }
#HTMLReporter .symbolSummary li.pending:before { color: #aaaaaa; content: "-"; }
#HTMLReporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; }
#HTMLReporter .runningAlert { background-color: #666666; }
#HTMLReporter .skippedAlert { background-color: #aaaaaa; }
#HTMLReporter .skippedAlert:first-child { background-color: #333333; }
#HTMLReporter .skippedAlert:hover { text-decoration: none; color: white; text-decoration: underline; }
#HTMLReporter .passingAlert { background-color: #a6b779; }
#HTMLReporter .passingAlert:first-child { background-color: #5e7d00; }
#HTMLReporter .failingAlert { background-color: #cf867e; }
#HTMLReporter .failingAlert:first-child { background-color: #b03911; }
#HTMLReporter .results { margin-top: 14px; }
#HTMLReporter #details { display: none; }
#HTMLReporter .resultsMenu, #HTMLReporter .resultsMenu a { background-color: #fff; color: #333333; }
#HTMLReporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; }
#HTMLReporter.showDetails .summaryMenuItem:hover { text-decoration: underline; }
#HTMLReporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; }
#HTMLReporter.showDetails .summary { display: none; }
#HTMLReporter.showDetails #details { display: block; }
#HTMLReporter .summaryMenuItem { font-weight: bold; text-decoration: underline; }
#HTMLReporter .summary { margin-top: 14px; }
#HTMLReporter .summary .suite .suite, #HTMLReporter .summary .specSummary { margin-left: 14px; }
#HTMLReporter .summary .specSummary.passed a { color: #5e7d00; }
#HTMLReporter .summary .specSummary.failed a { color: #b03911; }
#HTMLReporter .description + .suite { margin-top: 0; }
#HTMLReporter .suite { margin-top: 14px; }
#HTMLReporter .suite a { color: #333333; }
#HTMLReporter #details .specDetail { margin-bottom: 28px; }
#HTMLReporter #details .specDetail .description { display: block; color: white; background-color: #b03911; }
#HTMLReporter .resultMessage { padding-top: 14px; color: #333333; }
#HTMLReporter .resultMessage span.result { display: block; }
#HTMLReporter .stackTrace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; }
#TrivialReporter { padding: 8px 13px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow-y: scroll; background-color: white; font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; /*.resultMessage {*/ /*white-space: pre;*/ /*}*/ }
#TrivialReporter a:visited, #TrivialReporter a { color: #303; }
#TrivialReporter a:hover, #TrivialReporter a:active { color: blue; }
#TrivialReporter .run_spec { float: right; padding-right: 5px; font-size: .8em; text-decoration: none; }
#TrivialReporter .banner { color: #303; background-color: #fef; padding: 5px; }
#TrivialReporter .logo { float: left; font-size: 1.1em; padding-left: 5px; }
#TrivialReporter .logo .version { font-size: .6em; padding-left: 1em; }
#TrivialReporter .runner.running { background-color: yellow; }
#TrivialReporter .options { text-align: right; font-size: .8em; }
#TrivialReporter .suite { border: 1px outset gray; margin: 5px 0; padding-left: 1em; }
#TrivialReporter .suite .suite { margin: 5px; }
#TrivialReporter .suite.passed { background-color: #dfd; }
#TrivialReporter .suite.failed { background-color: #fdd; }
#TrivialReporter .spec { margin: 5px; padding-left: 1em; clear: both; }
#TrivialReporter .spec.failed, #TrivialReporter .spec.passed, #TrivialReporter .spec.skipped { padding-bottom: 5px; border: 1px solid gray; }
#TrivialReporter .spec.failed { background-color: #fbb; border-color: red; }
#TrivialReporter .spec.passed { background-color: #bfb; border-color: green; }
#TrivialReporter .spec.skipped { background-color: #bbb; }
#TrivialReporter .messages { border-left: 1px dashed gray; padding-left: 1em; padding-right: 1em; }
#TrivialReporter .passed { background-color: #cfc; display: none; }
#TrivialReporter .failed { background-color: #fbb; }
#TrivialReporter .skipped { color: #777; background-color: #eee; display: none; }
#TrivialReporter .resultMessage span.result { display: block; line-height: 2em; color: black; }
#TrivialReporter .resultMessage .mismatch { color: black; }
#TrivialReporter .stackTrace { white-space: pre; font-size: .8em; margin-left: 10px; max-height: 5em; overflow: auto; border: 1px inset red; padding: 1em; background: #eef; }
#TrivialReporter .finished-at { padding-left: 1em; font-size: .6em; }
#TrivialReporter.show-passed .passed, #TrivialReporter.show-skipped .skipped { display: block; }
#TrivialReporter #jasmine_content { position: fixed; right: 100%; }
#TrivialReporter .runner { border: 1px solid gray; display: block; margin: 5px 0; padding: 2px 0 2px 10px; }

File diff suppressed because it is too large Load Diff

227
test/lib/mocha.css Normal file
View File

@@ -0,0 +1,227 @@
@charset "UTF-8";
body {
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 60px 50px;
}
#mocha ul, #mocha li {
margin: 0;
padding: 0;
}
#mocha ul {
list-style: none;
}
#mocha h1, #mocha h2 {
margin: 0;
}
#mocha h1 {
margin-top: 15px;
font-size: 1em;
font-weight: 200;
}
#mocha h1 a {
text-decoration: none;
color: inherit;
}
#mocha h1 a:hover {
text-decoration: underline;
}
#mocha .suite .suite h1 {
margin-top: 0;
font-size: .8em;
}
.hidden {
display: none;
}
#mocha h2 {
font-size: 12px;
font-weight: normal;
cursor: pointer;
}
#mocha .suite {
margin-left: 15px;
}
#mocha .test {
margin-left: 15px;
}
#mocha .test.pending:hover h2::after {
content: '(pending)';
font-family: arial;
}
#mocha .test.pass.medium .duration {
background: #C09853;
}
#mocha .test.pass.slow .duration {
background: #B94A48;
}
#mocha .test.pass::before {
content: '✓';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #00d6b2;
}
#mocha .test.pass .duration {
font-size: 9px;
margin-left: 5px;
padding: 2px 5px;
color: white;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
#mocha .test.pass.fast .duration {
display: none;
}
#mocha .test.pending {
color: #0b97c4;
}
#mocha .test.pending::before {
content: '◦';
color: #0b97c4;
}
#mocha .test.fail {
color: #c00;
}
#mocha .test.fail pre {
color: black;
}
#mocha .test.fail::before {
content: '✖';
font-size: 12px;
display: block;
float: left;
margin-right: 5px;
color: #c00;
}
#mocha .test pre.error {
color: #c00;
max-height: 300px;
overflow: auto;
}
#mocha .test pre {
display: inline-block;
font: 12px/1.5 monaco, monospace;
margin: 5px;
padding: 15px;
border: 1px solid #eee;
border-bottom-color: #ddd;
-webkit-border-radius: 3px;
-webkit-box-shadow: 0 1px 3px #eee;
-moz-border-radius: 3px;
-moz-box-shadow: 0 1px 3px #eee;
}
#mocha .test h2 {
position: relative;
}
#mocha .test a.replay {
position: absolute;
top: 3px;
right: -20px;
text-decoration: none;
vertical-align: middle;
display: block;
width: 15px;
height: 15px;
line-height: 15px;
text-align: center;
background: #eee;
font-size: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
-webkit-transition: opacity 200ms;
-moz-transition: opacity 200ms;
transition: opacity 200ms;
opacity: 0.2;
color: #888;
}
#mocha .test:hover a.replay {
opacity: 1;
}
#mocha-report.pass .test.fail {
display: none;
}
#mocha-report.fail .test.pass {
display: none;
}
#mocha-error {
color: #c00;
font-size: 1.5 em;
font-weight: 100;
letter-spacing: 1px;
}
#mocha-stats {
position: fixed;
top: 15px;
right: 10px;
font-size: 12px;
margin: 0;
color: #888;
}
#mocha-stats .progress {
float: right;
padding-top: 0;
}
#mocha-stats em {
color: black;
}
#mocha-stats a {
text-decoration: none;
color: inherit;
}
#mocha-stats a:hover {
border-bottom: 1px solid #eee;
}
#mocha-stats li {
display: inline-block;
margin: 0 5px;
list-style: none;
padding-top: 11px;
}
code .comment { color: #ddd }
code .init { color: #2F6FAD }
code .string { color: #5890AD }
code .keyword { color: #8A6343 }
code .number { color: #2F6FAD }

4999
test/lib/mocha.js Normal file

File diff suppressed because it is too large Load Diff

106
test/lib/sinon-chai.js Normal file
View File

@@ -0,0 +1,106 @@
(function (sinonChai) {
"use strict";
// Module systems magic dance.
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
// NodeJS
module.exports = sinonChai;
} else if (typeof define === "function" && define.amd) {
// AMD
define(function () {
return sinonChai;
});
} else {
// Other environment (usually <script> tag): plug in to global chai instance directly.
chai.use(sinonChai);
}
}(function sinonChai(chai, utils) {
"use strict";
var slice = Array.prototype.slice;
function isSpy(putativeSpy) {
return typeof putativeSpy === "function" &&
typeof putativeSpy.getCall === "function" &&
typeof putativeSpy.calledWithExactly === "function";
}
function isCall(putativeCall) {
return putativeCall && isSpy(putativeCall.proxy);
}
function assertCanWorkWith(assertion) {
if (!isSpy(assertion._obj) && !isCall(assertion._obj)) {
throw new TypeError(utils.inspect(assertion._obj) + " is not a spy or a call to a spy!");
}
}
function getMessages(spy, action, nonNegatedSuffix, always, args) {
var verbPhrase = always ? "always have " : "have ";
nonNegatedSuffix = nonNegatedSuffix || "";
spy = spy.proxy || spy;
function printfArray(array) {
return spy.printf.apply(spy, array);
}
return {
affirmative: printfArray(["expected %n to " + verbPhrase + action + nonNegatedSuffix].concat(args)),
negative: printfArray(["expected %n to not " + verbPhrase + action].concat(args))
};
}
function sinonProperty(name, action, nonNegatedSuffix) {
utils.addProperty(chai.Assertion.prototype, name, function () {
assertCanWorkWith(this);
var messages = getMessages(this._obj, action, nonNegatedSuffix, false);
this.assert(this._obj[name], messages.affirmative, messages.negative);
});
}
function createSinonMethodHandler(sinonName, action, nonNegatedSuffix) {
return function () {
assertCanWorkWith(this);
var alwaysSinonMethod = "always" + sinonName[0].toUpperCase() + sinonName.substring(1);
var shouldBeAlways = utils.flag(this, "always") && typeof this._obj[alwaysSinonMethod] === "function";
var sinonMethod = shouldBeAlways ? alwaysSinonMethod : sinonName;
var messages = getMessages(this._obj, action, nonNegatedSuffix, shouldBeAlways, slice.call(arguments));
this.assert(this._obj[sinonMethod].apply(this._obj, arguments), messages.affirmative, messages.negative);
};
}
function sinonMethodAsProperty(name, action, nonNegatedSuffix) {
var handler = createSinonMethodHandler(name, action, nonNegatedSuffix);
utils.addProperty(chai.Assertion.prototype, name, handler);
}
function exceptionalSinonMethod(chaiName, sinonName, action, nonNegatedSuffix) {
var handler = createSinonMethodHandler(sinonName, action, nonNegatedSuffix);
utils.addMethod(chai.Assertion.prototype, chaiName, handler);
}
function sinonMethod(name, action, nonNegatedSuffix) {
exceptionalSinonMethod(name, name, action, nonNegatedSuffix);
}
utils.addProperty(chai.Assertion.prototype, "always", function () {
utils.flag(this, "always", true);
});
sinonProperty("called", "been called", " at least once, but it was never called");
sinonProperty("calledOnce", "been called exactly once", ", but it was called %c%C");
sinonProperty("calledTwice", "been called exactly twice", ", but it was called %c%C");
sinonProperty("calledThrice", "been called exactly thrice", ", but it was called %c%C");
sinonMethodAsProperty("calledWithNew", "been called with new");
sinonMethod("calledBefore", "been called before %1");
sinonMethod("calledAfter", "been called after %1");
sinonMethod("calledOn", "been called with %1 as this", ", but it was called with %t instead");
sinonMethod("calledWith", "been called with arguments %*", "%C");
sinonMethod("calledWithExactly", "been called with exact arguments %*", "%C");
sinonMethod("returned", "returned %1");
exceptionalSinonMethod("thrown", "threw", "thrown %1");
}));

4153
test/lib/sinon.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -6,19 +6,19 @@ describe('Connection', function() {
});
it('is instantiated', function() {
expect(c).toBeTruthy();
expect(c).to.be.ok;
});
it('gets/sets url', function() {
var new_url = 'http://api06.openstreetmap.org';
expect(c.url(new_url)).toEqual(c);
expect(c.url()).toEqual(new_url);
expect(c.url(new_url)).to.equal(c);
expect(c.url()).to.equal(new_url);
});
it('gets/sets user', function() {
var user = { name: 'tom' };
expect(c.user(user)).toEqual(c);
expect(c.user()).toEqual(user);
expect(c.user(user)).to.equal(c);
expect(c.user()).to.equal(user);
});
});

View File

@@ -3,66 +3,66 @@ describe('Entity', function () {
it("returns a new Entity", function () {
var a = iD.Entity(),
b = a.update({});
expect(b instanceof iD.Entity).toBeTruthy();
expect(a).not.toBe(b);
expect(b instanceof iD.Entity).to.be.true;
expect(a).not.to.equal(b);
});
it("updates the specified attributes", function () {
var tags = {foo: 'bar'},
e = iD.Entity().update({tags: tags});
expect(e.tags).toBe(tags);
expect(e.tags).to.equal(tags);
});
it("tags the entity as updated", function () {
var tags = {foo: 'bar'},
e = iD.Entity().update({tags: tags});
expect(e._updated).toBe(true);
expect(e._updated).to.to.be.true;
});
});
describe("#created", function () {
it("returns false for an unmodified Entity", function () {
expect(iD.Entity({id: 'w1234'}).created()).toBeFalsy();
it("returns falsy for an unmodified Entity", function () {
expect(iD.Entity({id: 'w1234'}).created()).not.to.be.ok;
});
it("returns false for a modified Entity with positive ID", function () {
expect(iD.Entity({id: 'w1234'}).update({}).created()).toBeFalsy();
it("returns falsy for a modified Entity with positive ID", function () {
expect(iD.Entity({id: 'w1234'}).update({}).created()).not.to.be.ok;
});
it("returns true for a modified Entity with negative ID", function () {
expect(iD.Entity({id: 'w-1234'}).update({}).created()).toBeTruthy();
it("returns truthy for a modified Entity with negative ID", function () {
expect(iD.Entity({id: 'w-1234'}).update({}).created()).to.be.ok;
});
});
describe("#modified", function () {
it("returns false for an unmodified Entity", function () {
expect(iD.Entity({id: 'w1234'}).modified()).toBeFalsy();
it("returns falsy for an unmodified Entity", function () {
expect(iD.Entity({id: 'w1234'}).modified()).not.to.be.ok;
});
it("returns true for a modified Entity with positive ID", function () {
expect(iD.Entity({id: 'w1234'}).update({}).modified()).toBeTruthy();
it("returns truthy for a modified Entity with positive ID", function () {
expect(iD.Entity({id: 'w1234'}).update({}).modified()).to.be.ok;
});
it("returns false for a modified Entity with negative ID", function () {
expect(iD.Entity({id: 'w-1234'}).update({}).modified()).toBeFalsy();
it("returns falsy for a modified Entity with negative ID", function () {
expect(iD.Entity({id: 'w-1234'}).update({}).modified()).not.to.be.ok;
});
});
});
describe('Node', function () {
it("returns a created Entity if no ID is specified", function () {
expect(iD.Node().created()).toBeTruthy();
expect(iD.Node().created()).to.be.true;
});
});
describe('Way', function () {
it("returns a created Entity if no ID is specified", function () {
expect(iD.Way().created()).toBeTruthy();
expect(iD.Way().created()).to.be.true;
});
});
describe('Relation', function () {
it("returns a created Entity if no ID is specified", function () {
expect(iD.Relation().created()).toBeTruthy();
expect(iD.Relation().created()).to.be.true;
});
});

View File

@@ -2,13 +2,13 @@ describe('GeoJSON', function() {
describe('#mapping', function() {
it('should be able to map a node to geojson', function() {
expect(iD.format.GeoJSON.mapping({ type: 'node', lat: 38, lon: -77 }).geometry.type).toEqual('Point');
expect(iD.format.GeoJSON.mapping({ type: 'node', lat: 38, lon: -77 }).geometry.type).to.equal('Point');
});
it('should be able to map a way to geojson', function() {
var way = { type: 'way', nodes: [] };
var gj = iD.format.GeoJSON.mapping(way);
expect(gj.type).toEqual('Feature');
expect(gj.geometry.type).toEqual('LineString');
expect(gj.type).to.equal('Feature');
expect(gj.geometry.type).to.equal('LineString');
});
});
});

View File

@@ -10,12 +10,12 @@ describe('Graph', function() {
}
};
var graph = iD.Graph(entities, 'first graph');
expect(graph.entity('n-1')).toEqual(entities['n-1']);
expect(graph.entity('n-1')).to.equal(entities['n-1']);
});
it('annotation', function() {
var graph = iD.Graph({}, 'first graph');
expect(graph.annotation).toEqual('first graph');
expect(graph.annotation).to.equal('first graph');
});
});
@@ -30,8 +30,8 @@ describe('Graph', function() {
};
var graph = iD.Graph(entities, 'first graph');
var g2 = graph.remove(entities['n-1'], 'Removed node');
expect(graph.entity('n-1')).toEqual(entities['n-1']);
expect(g2.entity('n-1')).toEqual(undefined);
expect(graph.entity('n-1')).to.equal(entities['n-1']);
expect(g2.entity('n-1')).to.equal(undefined);
});
it('#replace', function() {
var entities = { 'n-1': {
@@ -49,8 +49,8 @@ describe('Graph', function() {
};
var graph = iD.Graph(entities, 'first graph');
var g2 = graph.replace(replacement, 'Removed node');
expect(graph.entity('n-1').lat).toEqual(30);
expect(g2.entity('n-1').lat).toEqual(40);
expect(graph.entity('n-1').lat).to.equal(30);
expect(g2.entity('n-1').lat).to.equal(40);
});
});
@@ -59,7 +59,7 @@ describe('Graph', function() {
var a = {id: 'a', modified: function () { return true; }},
b = {id: 'b', modified: function () { return false; }},
graph = iD.Graph({ 'a': a, 'b': b });
expect(graph.modifications()).toEqual([graph.fetch('a')]);
expect(graph.modifications()).to.eql([graph.fetch('a')]);
});
});
@@ -68,7 +68,7 @@ describe('Graph', function() {
var a = {id: 'a', created: function () { return true; }},
b = {id: 'b', created: function () { return false; }},
graph = iD.Graph({ 'a': a, 'b': b });
expect(graph.creations()).toEqual([graph.fetch('a')]);
expect(graph.creations()).to.eql([graph.fetch('a')]);
});
});
});

View File

@@ -15,29 +15,29 @@ describe("Inspector", function () {
});
it("emits a close event when the close button is clicked", function () {
var spy = jasmine.createSpy();
var spy = sinon.spy();
inspector.on('close', spy);
happen.click(element.select('.close').node());
expect(spy).toHaveBeenCalledWith(entity);
expect(spy).to.have.been.calledWith(entity);
});
it("emits a changeTags event when the save button is clicked", function () {
var spy = jasmine.createSpy();
var spy = sinon.spy();
inspector.on('changeTags', spy);
happen.click(element.select('.save').node());
expect(spy).toHaveBeenCalledWith(entity, {});
expect(spy).to.have.been.calledWith(entity, {});
});
it("emits a remove event when the delete button is clicked", function () {
var spy = jasmine.createSpy();
var spy = sinon.spy();
inspector.on('remove', spy);
happen.click(element.select('.delete').node());
expect(spy).toHaveBeenCalledWith(entity);
expect(spy).to.have.been.calledWith(entity);
});
});

View File

@@ -14,56 +14,56 @@ describe('Map', function() {
describe('#connection', function() {
it('gets and sets connection', function() {
var connection = {};
expect(map.connection(connection)).toBe(map);
expect(map.connection()).toBe(connection);
expect(map.connection(connection)).to.equal(map);
expect(map.connection()).to.equal(connection);
});
});
describe('#zoom', function() {
it('gets and sets zoom level', function() {
expect(map.zoom(4)).toEqual(map);
expect(map.zoom()).toEqual(4);
expect(map.zoom(4)).to.equal(map);
expect(map.zoom()).to.equal(4);
});
});
describe('#zoomIn', function() {
it('increments zoom', function() {
expect(map.zoom(4)).toEqual(map);
expect(map.zoomIn()).toEqual(map);
expect(map.zoom()).toEqual(5);
expect(map.zoom(4)).to.equal(map);
expect(map.zoomIn()).to.equal(map);
expect(map.zoom()).to.equal(5);
});
});
describe('#zoomOut', function() {
it('decrements zoom', function() {
expect(map.zoom(4)).toEqual(map);
expect(map.zoomOut()).toEqual(map);
expect(map.zoom()).toEqual(3);
expect(map.zoom(4)).to.equal(map);
expect(map.zoomOut()).to.equal(map);
expect(map.zoom()).to.equal(3);
});
});
describe('#center', function() {
it('gets and sets center', function() {
expect(map.center([0, 0])).toEqual(map);
expect(map.center()).toEqual([0, 0]);
expect(map.center([10, 15])).toEqual(map);
expect(map.center()[0]).toBeCloseTo(10);
expect(map.center()[1]).toBeCloseTo(15);
expect(map.center([0, 0])).to.equal(map);
expect(map.center()).to.eql([0, 0]);
expect(map.center([10, 15])).to.equal(map);
expect(map.center()[0]).to.be.closeTo(10, 0.5);
expect(map.center()[1]).to.be.closeTo(15, 0.5);
});
});
describe('#extent', function() {
it('reports extent', function() {
expect(map.size([100, 100])).toEqual(map);
expect(map.center([0, 0])).toEqual(map);
expect(map.extent()[0][0]).toBeCloseTo(-36);
expect(map.extent()[1][0]).toBeCloseTo(36);
expect(map.size([100, 100])).to.equal(map);
expect(map.center([0, 0])).to.equal(map);
expect(map.extent()[0][0]).to.be.closeTo(-36, 0.5);
expect(map.extent()[1][0]).to.be.closeTo(36, 0.5);
});
});
describe("surface", function() {
it("is an SVG element", function() {
expect(map.surface.node().tagName).toEqual("svg");
expect(map.surface.node().tagName).to.equal("svg");
});
});
});

View File

@@ -6,19 +6,19 @@ describe('Util', function() {
b = iD.Util.id(),
c = iD.Util.id(),
d = iD.Util.id();
expect(a === b).toEqual(false);
expect(b === c).toEqual(false);
expect(c === d).toEqual(false);
expect(a === b).to.equal(false);
expect(b === c).to.equal(false);
expect(c === d).to.equal(false);
});
it('#trueObj', function() {
expect(iD.Util.trueObj(['a', 'b', 'c'])).toEqual({ a: true, b: true, c: true });
expect(iD.Util.trueObj([])).toEqual({});
expect(iD.Util.trueObj(['a', 'b', 'c'])).to.eql({ a: true, b: true, c: true });
expect(iD.Util.trueObj([])).to.eql({});
});
it('#friendlyName', function() {
expect(iD.Util.friendlyName({ tags: { name: 'hi' }})).toEqual('hi');
expect(iD.Util.friendlyName({ tags: { highway: 'Route 5' }})).toEqual('Route 5');
expect(iD.Util.friendlyName({ tags: { name: 'hi', highway: 'Route 5' }})).toEqual('hi');
expect(iD.Util.friendlyName({ tags: { name: 'hi' }})).to.equal('hi');
expect(iD.Util.friendlyName({ tags: { highway: 'Route 5' }})).to.equal('Route 5');
expect(iD.Util.friendlyName({ tags: { name: 'hi', highway: 'Route 5' }})).to.equal('hi');
});
});

View File

@@ -8,7 +8,7 @@ describe('Way', function() {
describe('#isClosed', function() {
it('is not closed with two distinct nodes ', function() {
expect(iD.Way.isClosed(way)).toEqual(false);
expect(iD.Way.isClosed(way)).to.equal(false);
});
});
});

View File

@@ -2,23 +2,23 @@ describe('XML', function() {
describe('#rep', function() {
it('converts a node to jxon', function() {
expect(iD.format.XML.rep({ id: 'n-1', type: 'node', lat: 38, lon: -77 }))
.toEqual({ node : { '@id': '-1', '@lat': 38, '@lon': -77, '@version': 0, tag: [ ] } });
.to.eql({ node : { '@id': '-1', '@lat': 38, '@lon': -77, '@version': 0, tag: [ ] } });
});
it('converts a way to jxon', function() {
expect(iD.format.XML.rep({ id: 'w-1', type: 'way', nodes: [] }))
.toEqual({ way : { '@id' : '-1', nd : [ ], '@version': 0, tag: [ ] } });
.to.eql({ way : { '@id' : '-1', nd : [ ], '@version': 0, tag: [ ] } });
});
});
describe('#mapping', function() {
it('serializes a node to xml', function() {
expect(iD.format.XML.mapping({ id: 'n-1', type: 'node', lat: 38, lon: -77 }))
.toEqual('&lt;node id=&quot;-1&quot; lat=&quot;38&quot; lon=&quot;-77&quot; version=&quot;0&quot;/&gt;');
.to.equal('&lt;node id=&quot;-1&quot; lat=&quot;38&quot; lon=&quot;-77&quot; version=&quot;0&quot;/&gt;');
});
it('serializes a way to xml', function() {
expect(iD.format.XML.mapping({ type: 'way', nodes: [], id: 'w-1' }))
.toEqual('&lt;way id=&quot;-1&quot; version=&quot;0&quot;/&gt;');
.to.equal('&lt;way id=&quot;-1&quot; version=&quot;0&quot;/&gt;');
});
});
});

View File

@@ -14,23 +14,23 @@ describe('Background', function() {
describe('iD.Background', function() {
it('is instantiated', function() {
expect(c).toBeTruthy();
expect(c).to.be.ok;
});
it('#size', function() {
expect(c.size([100, 100])).toEqual(c);
expect(c.size()).toEqual([100,100]);
expect(c.size([100, 100])).to.equal(c);
expect(c.size()).to.eql([100,100]);
});
it('#source', function() {
expect(c.source(iD.Background.Bing)).toEqual(c);
expect(c.source()).toEqual(iD.Background.Bing);
expect(c.source(iD.Background.Bing)).to.equal(c);
expect(c.source()).to.equal(iD.Background.Bing);
});
});
describe('iD.Background.Bing', function() {
it('generates tiles', function() {
expect(iD.Background.Bing([0,0,0])).toEqual('http://ecn.t0.tiles.virtualearth.net/tiles/a.jpeg?g=587&mkt=en-gb&n=z');
expect(iD.Background.Bing([0,0,0])).to.equal('http://ecn.t0.tiles.virtualearth.net/tiles/a.jpeg?g=587&mkt=en-gb&n=z');
});
});

View File

@@ -18,80 +18,80 @@ describe("hash", function () {
describe("#map()", function () {
it("gets and sets map", function () {
expect(hash.map(map)).toBe(hash);
expect(hash.map()).toBe(map);
expect(hash.map(map)).to.equal(hash);
expect(hash.map()).to.equal(map);
});
it("sets hadHash if location.hash is present", function () {
location.hash = "?map=20.00/38.87952/-77.02405";
hash.map(map);
expect(hash.hadHash).toBeTruthy();
expect(hash.hadHash).to.be.true;
});
it("zooms map to requested level", function () {
location.hash = "?map=20.00/38.87952/-77.02405";
spyOn(map, 'zoom').andCallThrough();
sinon.spy(map, 'zoom');
hash.map(map);
expect(map.zoom).toHaveBeenCalledWith(20.0);
expect(map.zoom).to.have.been.calledWith(20.0);
});
it("centers map at requested coordinates", function () {
location.hash = "?map=20.00/38.87952/-77.02405";
spyOn(map, 'center').andCallThrough();
sinon.spy(map, 'center');
hash.map(map);
expect(map.center).toHaveBeenCalledWith([-77.02405, 38.87952]);
expect(map.center).to.have.been.calledWith([-77.02405, 38.87952]);
});
it("binds the map's move event", function () {
spyOn(map, 'on');
sinon.spy(map, 'on');
hash.map(map);
expect(map.on).toHaveBeenCalledWith('move', jasmine.any(Function));
expect(map.on).to.have.been.calledWith('move', sinon.match.instanceOf(Function));
});
it("unbinds the map's move event", function () {
spyOn(map, 'on');
spyOn(map, 'off');
sinon.spy(map, 'on');
sinon.spy(map, 'off');
hash.map(map);
hash.map(null);
expect(map.off).toHaveBeenCalledWith('move', map.on.mostRecentCall.args[1]);
expect(map.off).to.have.been.calledWith('move', map.on.firstCall.args[1]);
});
});
describe("on window hashchange events", function () {
var hashchanged,
hashchange = function () { return hashchanged; };
beforeEach(function() {
hash.map(map);
hashchanged = false;
window.addEventListener("hashchange", function () { hashchanged = true; }, false);
});
it("zooms map to requested level", function () {
spyOn(map, 'zoom').andCallThrough();
location.hash = "#?map=20.00/38.87952/-77.02405";
waitsFor(hashchange);
runs(function () {
expect(map.zoom).toHaveBeenCalledWith(20.0);
function onhashchange(fn) {
d3.select(window).one("hashchange", fn);
}
it("zooms map to requested level", function (done) {
onhashchange(function () {
expect(map.zoom).to.have.been.calledWith(20.0);
done();
});
sinon.spy(map, 'zoom');
location.hash = "#?map=20.00/38.87952/-77.02405";
});
it("centers map at requested coordinates", function () {
spyOn(map, 'center').andCallThrough();
location.hash = "#?map=20.00/38.87952/-77.02405";
waitsFor(hashchange);
runs(function () {
expect(map.center).toHaveBeenCalledWith([-77.02405, 38.87952]);
it("centers map at requested coordinates", function (done) {
onhashchange(function () {
expect(map.center).to.have.been.calledWith([-77.02405, 38.87952]);
done();
});
sinon.spy(map, 'center');
location.hash = "#?map=20.00/38.87952/-77.02405";
});
});
describe("on map move events", function () {
it("stores the current zoom and coordinates in location.hash", function () {
spyOn(map, 'on');
sinon.stub(map, 'on').yields();
hash.map(map);
map.on.mostRecentCall.args[1]();
expect(location.hash).toEqual("#?map=0.00/0/0");
expect(location.hash).to.equal("#?map=0.00/0/0");
});
});
});

View File

@@ -0,0 +1,22 @@
describe("iD", function () {
var container, editor;
beforeEach(function() {
container = d3.select('body').append('div');
editor = iD()
editor.map().background.source(null);
editor.call(container);
});
afterEach(function() {
container.remove();
});
it("allows an editor to add a place", function () {
// click 'Add Place'
// click on map
// select tags
// save
// check uploaded XML
});
});

View File

@@ -5,14 +5,14 @@ describe('OAuth', function() {
});
describe('#logout', function() {
it('can log out and will no longer be authenticated', function() {
expect(o.logout()).toEqual(o);
expect(o.authenticated()).toBeFalsy();
expect(o.logout()).to.equal(o);
expect(o.authenticated()).not.to.be.ok;
});
});
describe('#api', function() {
it('gets and sets url', function() {
expect(o.api('foo')).toEqual(o);
expect(o.api()).toBe('foo');
expect(o.api('foo')).to.equal(o);
expect(o.api()).to.equal('foo');
});
});

View File

@@ -3,24 +3,24 @@ describe('Style', function() {
it('stacks bridges over non-bridges', function() {
var a = { tags: { bridge: 'yes' } },
b = { tags: {} };
expect(iD.Style.waystack(a, b)).toEqual(1);
expect(iD.Style.waystack(b, a)).toEqual(-1);
expect(iD.Style.waystack(a, b)).to.equal(1);
expect(iD.Style.waystack(b, a)).to.equal(-1);
});
it('stacks layers', function() {
var a = { tags: { layer: 1 } },
b = { tags: { layer: 0 } };
expect(iD.Style.waystack(a, b)).toEqual(1);
expect(iD.Style.waystack(b, a)).toEqual(-1);
expect(iD.Style.waystack(a, b)).to.equal(1);
expect(iD.Style.waystack(b, a)).to.equal(-1);
});
});
describe('#styleClasses', function() {
it('no valid classes', function() {
var a = { tags: { } };
expect(iD.Style.styleClasses('')(a)).toEqual('');
expect(iD.Style.styleClasses('')(a)).to.equal('');
});
it('a valid class', function() {
var a = { tags: { highway: 'primary' } };
expect(iD.Style.styleClasses('')(a)).toEqual(' highway-primary highway');
expect(iD.Style.styleClasses('')(a)).to.equal(' highway-primary highway');
});
});
});