diff --git a/test/index.html b/test/index.html
index b094f4b32..938c897bd 100644
--- a/test/index.html
+++ b/test/index.html
@@ -82,6 +82,7 @@
+
diff --git a/test/spec/modes/add_note.js b/test/spec/modes/add_note.js
new file mode 100644
index 000000000..7b1e7a37c
--- /dev/null
+++ b/test/spec/modes/add_note.js
@@ -0,0 +1,63 @@
+describe('iD.modeAddNote', function() {
+ var context;
+
+ before(function() {
+ iD.services.osm = iD.serviceOsm;
+ });
+
+ after(function() {
+ delete iD.services.osm;
+ });
+
+ beforeEach(function() {
+ var container = d3.select(document.createElement('div'));
+
+ context = iD.Context()
+ .container(container);
+
+ context.loadTiles = function () {};
+
+ container.call(context.map())
+ .append('div')
+ .attr('class', 'inspector-wrap');
+
+ context.map().centerZoom([-77.02271, 38.90085], 20);
+ context.enter(iD.modeAddNote(context));
+ });
+
+ describe('clicking the map', function () {
+ it('adds a note', function() {
+ var note = iD.osmNote({
+ id: -1,
+ comments: {},
+ loc: [-77.02271, 38.90085],
+ newFeature: true,
+ status: 'open'
+ });
+ happen.mousedown(context.surface().node(), {});
+ happen.mouseup(window, {});
+ expect(iD.services.osm.caches().note.note[-1]).to.eql(note);
+ context.mode().exit();
+ d3.select('window').on('click.draw-block', null);
+ });
+
+ it('selects the node', function() {
+ happen.mousedown(context.surface().node(), {});
+ happen.mouseup(window, {});
+ expect(context.selectedNoteID()).to.eql(-1);
+ expect(context.mode().id).to.equal('select-note');
+ context.mode().exit();
+ d3.select('window').on('click.draw-block', null);
+ });
+ });
+
+ describe('pressing ⎋', function() {
+ it('exits to browse mode', function(done) {
+ happen.keydown(document, {keyCode: 27});
+ window.setTimeout(function() {
+ expect(context.mode().id).to.equal('browse');
+ done();
+ }, 200);
+ });
+ });
+});
diff --git a/test/spec/osm/note.js b/test/spec/osm/note.js
index 6dc2f99ea..241dfea0b 100644
--- a/test/spec/osm/note.js
+++ b/test/spec/osm/note.js
@@ -1,5 +1,3 @@
-import { geoVecInterp } from '../geo';
-
describe('iD.osmNote', function () {
it('returns a note', function () {
expect(iD.osmNote()).to.be.an.instanceOf(iD.osmNote);
@@ -39,12 +37,10 @@ describe('iD.osmNote', function () {
it('returns an moved note', function() {
var note = iD.osmNote({
id: 1,
- loc: [5, 10]
+ loc: [5, 5]
});
-
- var moveAmount = geoVecInterp(note.loc, [10, 10], 1);
- note.move(moveAmount);
- expect(note.loc).to.equal([10, 10]);
+ note = note.move([10, 10]);
+ expect(note.loc).to.eql([10, 10]);
});
});
diff --git a/test/spec/services/osm.js b/test/spec/services/osm.js
index bc1617b4c..b8080b2c5 100644
--- a/test/spec/services/osm.js
+++ b/test/spec/services/osm.js
@@ -658,12 +658,28 @@ describe('iD.serviceOsm', function () {
});
});
+ describe('#removeNote', function() {
+ it('removes a note that is new', function(done) {
+ var note = iD.osmNote({ id: -1, loc: [0, 0], });
+ connection.replaceNote(note);
+ connection.removeNote(note);
+ var result = connection.getNote(-1);
+ expect(result).to.eql(undefined);
+ 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);
+ expect(connection.caches().note.note[2]).to.eql(note);
+ var rtree = connection.caches().note.rtree;
+ var result_rtree = rtree.search({ 'minX': -1, 'minY': -1, 'maxX': 1, 'maxY': 1 });
+ expect(result_rtree.length).to.eql(1);
+ expect(result_rtree[0].data).to.eql(note);
done();
});
@@ -673,6 +689,12 @@ describe('iD.serviceOsm', function () {
note.status = 'closed';
var result = connection.replaceNote(note);
expect(result.status).to.eql('closed');
+
+ var rtree = connection.caches().note.rtree;
+ var result_rtree = rtree.search({ 'minX': -1, 'minY': -1, 'maxX': 1, 'maxY': 1 });
+ expect(result_rtree.length).to.eql(1);
+ expect(result_rtree[0].data.status).to.eql('closed');
+
done();
});
});