mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
added/updated service/osm, osm/note, mode/add_note tests
This commit is contained in:
@@ -82,6 +82,7 @@
|
||||
<script src='spec/lib/locale.js'></script>
|
||||
|
||||
<script src='spec/modes/add_point.js'></script>
|
||||
<script src='spec/modes/add_note.js'></script>
|
||||
|
||||
<script src='spec/osm/changeset.js'></script>
|
||||
<script src='spec/osm/entity.js'></script>
|
||||
|
||||
63
test/spec/modes/add_note.js
Normal file
63
test/spec/modes/add_note.js
Normal file
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user