From baad5f0cc589e4f033fd8a12446428a9da23b06d Mon Sep 17 00:00:00 2001 From: Thomas Hervey Date: Sat, 21 Jul 2018 21:44:07 -0400 Subject: [PATCH] added tests for osm/note --- modules/actions/move_note.js | 1 - modules/services/osm.js | 2 +- test/spec/osm/note.js | 38 +++++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/modules/actions/move_note.js b/modules/actions/move_note.js index e7c1a273d..97d89b97a 100644 --- a/modules/actions/move_note.js +++ b/modules/actions/move_note.js @@ -9,7 +9,6 @@ export function actionMoveNote(noteID, toLoc) { var note = services.osm.getNote(noteID); note.move(geoVecInterp(note.loc, toLoc, t)); - // TODO: update }; action.transitionable = true; diff --git a/modules/services/osm.js b/modules/services/osm.js index d33b941b7..89e0ae958 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -329,7 +329,7 @@ function parseXML(xml, callback, options) { // replace or remove note from rtree function updateRtree(item, replace) { // update (or insert) in _noteCache.rtree - // TODO: other checks needed? (e.g., if cache.data.children.length decrements ...) + // NOTE: other checks needed? (e.g., if cache.data.children.length decrements ...) // remove note _noteCache.rtree.remove(item, function isEql(a, b) { return a.data.id === b.data.id; }); diff --git a/test/spec/osm/note.js b/test/spec/osm/note.js index 4e3d24817..6dc2f99ea 100644 --- a/test/spec/osm/note.js +++ b/test/spec/osm/note.js @@ -1,3 +1,5 @@ +import { geoVecInterp } from '../geo'; + describe('iD.osmNote', function () { it('returns a note', function () { expect(iD.osmNote()).to.be.an.instanceOf(iD.osmNote); @@ -10,6 +12,40 @@ describe('iD.osmNote', function () { }); }); - // TODO: add tests for #update, or remove function + describe('#update', function() { + it('returns an updated note', function() { + + }); + }); + + describe('#isNew', function() { + it('returns true if a note is new', function() { + var note = iD.osmNote({ + id: -1, + loc: [5, 10] + }); + expect(note.isNew()).to.be.true; + }); + it('returns false if a note is not new', function() { + var note = iD.osmNote({ + id: 1, + loc: [5, 10] + }); + expect(note.isNew()).to.be.false; + }); + }); + + describe('#move', function() { + it('returns an moved note', function() { + var note = iD.osmNote({ + id: 1, + loc: [5, 10] + }); + + var moveAmount = geoVecInterp(note.loc, [10, 10], 1); + note.move(moveAmount); + expect(note.loc).to.equal([10, 10]); + }); + }); }); \ No newline at end of file