diff --git a/modules/svg/notes.js b/modules/svg/notes.js
index a42b9cde7..4350f85b1 100644
--- a/modules/svg/notes.js
+++ b/modules/svg/notes.js
@@ -125,24 +125,6 @@ export function svgNotes(projection, context, dispatch) {
}
- function toggleEdit(service, enabled) {
-
- function dimensions() {
- return [window.innerWidth, window.innerHeight];
- }
-
- if (enabled) {
- if (service && ~~context.map().zoom() >= minZoom) {
- editOn();
- service.loadNotes(projection, dimensions());
- update();
- } else {
- editOff();
- }
- }
- }
-
-
function drawNotes(selection) {
var enabled = svgNotes.enabled;
var service = getService();
@@ -159,7 +141,19 @@ export function svgNotes(projection, context, dispatch) {
.style('display', enabled ? 'block' : 'none')
.merge(layer);
- toggleEdit(service, enabled);
+ function dimensions() {
+ return [window.innerWidth, window.innerHeight];
+ }
+
+ if (enabled) {
+ if (service && ~~context.map().zoom() >= minZoom) {
+ editOn();
+ service.loadNotes(projection, dimensions());
+ update();
+ } else {
+ editOff();
+ }
+ }
}
drawNotes.enabled = function(_) {
diff --git a/test/index.html b/test/index.html
index 188b9084c..2dc8938e4 100644
--- a/test/index.html
+++ b/test/index.html
@@ -89,6 +89,7 @@
+
@@ -115,6 +116,7 @@
+
diff --git a/test/spec/osm/note.js b/test/spec/osm/note.js
new file mode 100644
index 000000000..4e3d24817
--- /dev/null
+++ b/test/spec/osm/note.js
@@ -0,0 +1,15 @@
+describe('iD.osmNote', function () {
+ it('returns a note', function () {
+ expect(iD.osmNote()).to.be.an.instanceOf(iD.osmNote);
+ expect(iD.osmNote().type).to.equal('note');
+ });
+
+ describe('#extent', function() {
+ it('returns a note extent', function() {
+ expect(iD.osmNote({loc: [5, 10]}).extent().equals([[5, 10], [5, 10]])).to.be.ok;
+ });
+ });
+
+ // TODO: add tests for #update, or remove function
+
+});
\ No newline at end of file
diff --git a/test/spec/services/osm.js b/test/spec/services/osm.js
index 9e2832b92..929b14f69 100644
--- a/test/spec/services/osm.js
+++ b/test/spec/services/osm.js
@@ -137,7 +137,7 @@ describe('iD.serviceOsm', function () {
});
describe('#loadFromAPI', function () {
- var path = '/api/0.6/map?bbox=-74.542,40.655,-74.541,40.656';
+ var path = '/aapi/0.6/map?bbox=-74.542,40.655,-74.541,40.656';
var response = '' +
'' +
' ' +
- '' +
- '' +
- '814798' +
- 'https://api.openstreetmap.org/api/0.6/notes/814798' +
- 'https://api.openstreetmap.org/api/0.6/notes/814798/comment' +
- 'https://api.openstreetmap.org/api/0.6/notes/814798/close' +
- '2016-12-13 11:02:44 UTC' +
- 'open' +
- '' +
- '' +
- '2016-12-13 11:02:44 UTC' +
- 'opened' +
- 'Otford Scout Hut' +
- '<p>Otford Scout Hut</p>' +
- '' +
- '' +
- '' +
- '';
-
- beforeEach(function() {
- connection.reset();
- server = sinon.fakeServer.create();
- spy = sinon.spy();
- });
-
- afterEach(function() {
- server.restore();
- });
-
- it('returns an object', function (done) {
- connection.loadFromAPI(path, function (err, xml) {
- expect(err).to.not.be.ok;
- expect(typeof xml).to.eql('object');
- done();
- });
-
- server.respondWith('GET', 'http://www.openstreetmap.org' + path,
- [200, { 'Content-Type': 'text/xml' }, response]);
- server.respond();
- });
});
@@ -584,6 +537,97 @@ describe('iD.serviceOsm', function () {
});
+ describe('#caches', function() {
+ it('loads reset caches', function (done) {
+ var resetCaches = {
+ tile: {
+ inflight: {}, loaded: {}, seen: {}
+ },
+ note: {
+ loaded: {}, inflight: {}, inflightPost: {}, note: {} // not including rtree
+ },
+ user: {
+ toLoad: {}, user: {}
+ }
+ };
+ var caches = connection.caches();
+ expect(caches.tile).to.eql(resetCaches.tile);
+ expect(caches.note.loaded).to.eql(resetCaches.note.loaded);
+ expect(caches.user).to.eql(resetCaches.user);
+ done();
+ });
+
+ describe('sets/gets caches', function() {
+ it('sets/gets a tile', function (done) {
+ var obj = {
+ tile: { loaded: { '1,2,16': true, '3,4,16': true } }
+ };
+ connection.caches(obj);
+ expect(connection.caches().tile.loaded['1,2,16']).to.eql(true);
+ expect(Object.keys(connection.caches().tile.loaded).length).to.eql(2);
+ done();
+ });
+
+ it('sets/gets a note', function (done) {
+ var note = iD.osmNote({ id: 1, loc: [0, 0] });
+ var note2 = iD.osmNote({ id: 2, loc: [0, 0] });
+ var obj = {
+ note: { note: { 1: note, 2: note2 } }
+ };
+ connection.caches(obj);
+ expect(connection.caches().note.note[note.id]).to.eql(note);
+ expect(Object.keys(connection.caches().note.note).length).to.eql(2);
+ done();
+ });
+
+ it('sets/gets a user', function (done) {
+ var user = { id: 1, display_name: 'Name' };
+ var user2 = { id: 2, display_name: 'Name' };
+ var obj = {
+ user: { user: { 1: user, 2: user2 } }
+ };
+ connection.caches(obj);
+ expect(connection.caches().user.user[user.id]).to.eql(user);
+ expect(Object.keys(connection.caches().user.user).length).to.eql(2);
+ done();
+ });
+ });
+
+ });
+
+
+ describe('#getNote', function() {
+ it('returns a note', function (done) {
+ var note = iD.osmNote({ id: 1, loc: [0, 0], });
+ var obj = {
+ note: { note: { 1: note } }
+ };
+ connection.caches(obj);
+ var result = connection.getNote(1);
+ expect(result).to.deep.equal(note);
+ done();
+ });
+ });
+
+
+ describe('#replaceNote', function() {
+ it('returns a new note', function (done) {
+ var note = iD.osmNote({ id: 2, loc: [0, 0], });
+ var result = connection.replaceNote(note);
+ expect(result.id).to.eql(2);
+ done();
+ });
+
+ it('replaces a note', function (done) {
+ var note = iD.osmNote({ id: 2, loc: [0, 0], });
+ connection.replaceNote(note);
+ note.status = 'closed';
+ var result = connection.replaceNote(note);
+ expect(result.status).to.eql('closed');
+ done();
+ });
+ });
+
describe('API capabilities', function() {
var capabilitiesXML = '' +