Test actual data parsing, add test data, more tests

This commit is contained in:
Tom MacWright
2012-12-07 18:03:33 -05:00
parent bba14c2cba
commit 50ef08c723
4 changed files with 5493 additions and 6 deletions
+6 -5
View File
@@ -72,7 +72,7 @@ iD.Connection = function() {
}
function parse(dom) {
if (!dom.childNodes) return new Error('Bad request');
if (!dom || !dom.childNodes) return new Error('Bad request');
var root = dom.childNodes[0];
var entities = {};
refNodes = {};
@@ -100,28 +100,30 @@ iD.Connection = function() {
return oauth.authenticated();
}
function putChangeset(changes, comment, callback) {
connection.putChangeset = function(changes, comment, callback) {
oauth.xhr({
method: 'PUT',
path: '/api/0.6/changeset/create',
options: { header: { 'Content-Type': 'text/xml' } },
content: iD.format.XML.changeset(comment)
}, function (err, changeset_id) {
if (err) return callback(err);
oauth.xhr({
method: 'POST',
path: '/api/0.6/changeset/' + changeset_id + '/upload',
options: { header: { 'Content-Type': 'text/xml' } },
content: iD.format.XML.osmChange(user.id, changeset_id, changes)
}, function (err) {
if (err) return callback(err);
oauth.xhr({
method: 'PUT',
path: '/api/0.6/changeset/' + changeset_id + '/close'
}, function (err) {
callback(changeset_id);
callback(err, changeset_id);
});
});
});
}
};
function userDetails(callback) {
oauth.xhr({ method: 'GET', path: '/api/0.6/user/details' }, function(err, user_details) {
@@ -218,7 +220,6 @@ iD.Connection = function() {
connection.userDetails = userDetails;
connection.authenticate = authenticate;
connection.authenticated = authenticated;
connection.putChangeset = putChangeset;
connection.objectData = objectData;
connection.apiURL = apiURL;
+1 -1
View File
@@ -82,7 +82,7 @@ window.iD = function(container) {
function save(e) {
d3.select('.shaded').remove();
var l = iD.loading('uploading changes to openstreetmap');
connection.putChangeset(history.changes(), e.comment, function() {
connection.putChangeset(history.changes(), e.comment, function(err, changeset_id) {
l.remove();
history.reset();
map.flush().redraw();
+5449
View File
File diff suppressed because it is too large Load Diff
+37
View File
@@ -21,4 +21,41 @@ describe('Connection', function() {
expect(c.user()).to.equal(user);
});
describe('#loadFromURL', function() {
it('loads test data', function(done) {
c.loadFromURL('data/map.xml', done);
});
it('returns a graph', function(done) {
c.loadFromURL('data/map.xml', function(err, graph) {
expect(err).to.be.a('null');
expect(graph).to.be.instanceOf(iD.Graph);
done();
});
});
it('parses a node', function(done) {
c.loadFromURL('data/map.xml', function(err, graph) {
expect(graph.entity('n1193811')).to.be.instanceOf(iD.Entity);
done();
});
});
it('parses a way', function(done) {
c.loadFromURL('data/map.xml', function(err, graph) {
expect(graph.entity('w53471')).to.be.instanceOf(iD.Entity);
done();
});
});
it('passes errors for 404s', function(done) {
c.loadFromURL('404', function(err, graph) {
expect(err.status).to.eql(404);
expect(graph).to.be.a('Error');
done();
});
});
});
});