diff --git a/js/id/actions/reverse_way.js b/js/id/actions/reverse_way.js
index b170bf883..5b93f5578 100644
--- a/js/id/actions/reverse_way.js
+++ b/js/id/actions/reverse_way.js
@@ -2,7 +2,7 @@
iD.actions.ReverseWay = function(wayId) {
return function(graph) {
var way = graph.entity(wayId),
- nodes = way.nodes.slice();
+ nodes = way.nodes.slice().reverse();
return graph.replace(way.update({nodes: nodes}), 'changed way direction');
};
};
diff --git a/js/id/graph/graph.js b/js/id/graph/graph.js
index a830214d4..fe878de2c 100644
--- a/js/id/graph/graph.js
+++ b/js/id/graph/graph.js
@@ -70,7 +70,7 @@ iD.Graph.prototype = {
// Resolve the id references in a way, replacing them with actual objects.
fetch: function(id) {
var entity = this.entities[id], nodes = [];
- if (!entity.nodes || !entity.nodes.length) return iD.Entity(entity); // TODO: shouldn't be necessary
+ if (!entity.nodes || !entity.nodes.length) return entity;
for (var i = 0, l = entity.nodes.length; i < l; i++) {
nodes[i] = this.fetch(entity.nodes[i]);
}
diff --git a/js/id/modes/add_area.js b/js/id/modes/add_area.js
index 7a76a98db..d9ecdbcce 100644
--- a/js/id/modes/add_area.js
+++ b/js/id/modes/add_area.js
@@ -7,31 +7,36 @@ iD.modes.AddArea = function() {
};
mode.enter = function() {
- mode.map.dblclickEnable(false);
- mode.map.hint('Click on the map to start drawing an area, like a park, lake, or building.');
+ var map = mode.map,
+ history = mode.history,
+ controller = mode.controller;
- mode.map.surface.on('click.addarea', function() {
+ map.dblclickEnable(false)
+ .hint('Click on the map to start drawing an area, like a park, lake, or building.');
+
+ map.surface.on('click.addarea', function() {
var datum = d3.select(d3.event.target).datum() || {},
way = iD.Way({tags: { building: 'yes', area: 'yes' }});
- // connect a way to an existing way
if (datum.type === 'node') {
- mode.history.perform(
+ // start from an existing node
+ history.perform(
iD.actions.AddWay(way),
iD.actions.AddWayNode(way.id, datum.id));
} else {
- var node = iD.Node({loc: mode.map.mouseCoordinates()});
- mode.history.perform(
+ // start from a new node
+ var node = iD.Node({loc: map.mouseCoordinates()});
+ history.perform(
iD.actions.AddWay(way),
iD.actions.AddNode(node),
iD.actions.AddWayNode(way.id, node.id));
}
- mode.controller.enter(iD.modes.DrawArea(way.id));
+ controller.enter(iD.modes.DrawArea(way.id));
});
- mode.map.keybinding().on('⎋.addarea', function() {
- mode.controller.exit();
+ map.keybinding().on('⎋.addarea', function() {
+ controller.exit();
});
};
diff --git a/js/id/modes/add_place.js b/js/id/modes/add_place.js
index 780023e76..56e54959d 100644
--- a/js/id/modes/add_place.js
+++ b/js/id/modes/add_place.js
@@ -6,16 +6,20 @@ iD.modes.AddPlace = function() {
};
mode.enter = function() {
- mode.map.hint('Click on the map to add a place.');
+ var map = mode.map,
+ history = mode.history,
+ controller = mode.controller;
- mode.map.surface.on('click.addplace', function() {
- var node = iD.Node({loc: mode.map.mouseCoordinates(), _poi: true});
- mode.history.perform(iD.actions.AddNode(node));
- mode.controller.enter(iD.modes.Select(node));
+ map.hint('Click on the map to add a place.');
+
+ map.surface.on('click.addplace', function() {
+ var node = iD.Node({loc: map.mouseCoordinates(), _poi: true});
+ history.perform(iD.actions.AddNode(node));
+ controller.enter(iD.modes.Select(node));
});
- mode.map.keybinding().on('⎋.addplace', function() {
- mode.controller.exit();
+ map.keybinding().on('⎋.addplace', function() {
+ controller.exit();
});
};
diff --git a/js/id/modes/add_road.js b/js/id/modes/add_road.js
index a194b3295..879f930c8 100644
--- a/js/id/modes/add_road.js
+++ b/js/id/modes/add_road.js
@@ -7,27 +7,29 @@ iD.modes.AddRoad = function() {
};
mode.enter = function() {
- var map = mode.map;
+ var map = mode.map,
+ history = mode.history,
+ controller = mode.controller;
map.dblclickEnable(false)
.hint('Click on the map to start drawing an road, path, or route.');
map.surface.on('click.addroad', function() {
var datum = d3.select(d3.event.target).datum() || {},
- direction = 'forward',
- way = iD.Way({ tags: { highway: 'residential' } });
+ way = iD.Way({ tags: { highway: 'residential' } }),
+ direction = 'forward';
if (datum.type === 'node') {
// continue an existing way
var id = datum.id;
- var parents = mode.history.graph().parentWays(id);
+ var parents = history.graph().parentWays(id);
if (parents.length && parents[0].nodes[0] === id) {
way = parents[0];
direction = 'backward';
} else if (parents.length && _.last(parents[0].nodes) === id) {
way = parents[0];
} else {
- mode.history.perform(
+ history.perform(
iD.actions.AddWay(way),
iD.actions.AddWayNode(way.id, datum.id));
}
@@ -36,7 +38,7 @@ iD.modes.AddRoad = function() {
var node = iD.Node({loc: map.mouseCoordinates()}),
index = iD.util.geo.chooseIndex(datum, d3.mouse(map.surface.node()), map);
- mode.history.perform(
+ history.perform(
iD.actions.AddWay(way),
iD.actions.AddWayNode(datum.id, node, index),
iD.actions.AddWayNode(way.id, node.id));
@@ -44,17 +46,17 @@ iD.modes.AddRoad = function() {
// begin a new way
var node = iD.Node({loc: map.mouseCoordinates()});
- mode.history.perform(
+ history.perform(
iD.actions.AddWay(way),
iD.actions.AddNode(node),
iD.actions.AddWayNode(way.id, node.id));
}
- mode.controller.enter(iD.modes.DrawRoad(way.id, direction));
+ controller.enter(iD.modes.DrawRoad(way.id, direction));
});
map.keybinding().on('⎋.addroad', function() {
- mode.controller.exit();
+ controller.exit();
});
};
diff --git a/js/id/modes/draw_road.js b/js/id/modes/draw_road.js
index 46ac3e818..769c4412c 100644
--- a/js/id/modes/draw_road.js
+++ b/js/id/modes/draw_road.js
@@ -14,7 +14,6 @@ iD.modes.DrawRoad = function(wayId, direction) {
tailId = (direction === 'forward') ? _.first(way.nodes) : _.last(way.nodes);
map.dblclickEnable(false)
- .dragEnable(false)
.fastEnable(false)
.hint('Click to add more points to the road. ' +
'Click on other roads to connect to them, and double-click to ' +
@@ -90,7 +89,6 @@ iD.modes.DrawRoad = function(wayId, direction) {
.on('⌫.drawroad', null);
window.setTimeout(function() {
mode.map.dblclickEnable(true);
- mode.map.dragEnable(true);
}, 1000);
};
diff --git a/js/id/modes/select.js b/js/id/modes/select.js
index 07dc36723..d34d144bc 100644
--- a/js/id/modes/select.js
+++ b/js/id/modes/select.js
@@ -12,8 +12,6 @@ iD.modes.Select = function (entity) {
return { x: p[0], y: p[1] };
})
.on('drag', function(entity) {
- if (!mode.map.dragEnable()) return;
-
d3.event.sourceEvent.stopPropagation();
if (!dragging) {
@@ -31,7 +29,7 @@ iD.modes.Select = function (entity) {
});
})
.on('dragend', function () {
- if (!mode.map.dragEnable() || !dragging) return;
+ if (!dragging) return;
dragging = undefined;
mode.map.redraw();
});
diff --git a/test/index.html b/test/index.html
index dbfd7cba6..e904c9276 100644
--- a/test/index.html
+++ b/test/index.html
@@ -83,10 +83,18 @@
+
+
+
+
+
+
+
+
diff --git a/test/index_packaged.html b/test/index_packaged.html
index f1e70b069..8271e3886 100644
--- a/test/index_packaged.html
+++ b/test/index_packaged.html
@@ -25,10 +25,18 @@
+
+
+
+
+
+
+
+
diff --git a/test/spec/actions/add_node.js b/test/spec/actions/add_node.js
new file mode 100644
index 000000000..ae066edc5
--- /dev/null
+++ b/test/spec/actions/add_node.js
@@ -0,0 +1,7 @@
+describe("iD.actions.AddNode", function () {
+ it("adds a node to the graph", function () {
+ var node = iD.Node(),
+ graph = iD.actions.AddNode(node)(iD.Graph());
+ expect(graph.entity(node.id)).to.equal(node);
+ });
+});
diff --git a/test/spec/actions/add_way.js b/test/spec/actions/add_way.js
new file mode 100644
index 000000000..19948c5b2
--- /dev/null
+++ b/test/spec/actions/add_way.js
@@ -0,0 +1,7 @@
+describe("iD.actions.AddWay", function () {
+ it("adds a way to the graph", function () {
+ var way = iD.Way(),
+ graph = iD.actions.AddWay(way)(iD.Graph());
+ expect(graph.entity(way.id)).to.equal(way);
+ });
+});
diff --git a/test/spec/actions/change_entity_tags.js b/test/spec/actions/change_entity_tags.js
new file mode 100644
index 000000000..bfa9830c6
--- /dev/null
+++ b/test/spec/actions/change_entity_tags.js
@@ -0,0 +1,8 @@
+describe("iD.actions.ChangeEntityTags", function () {
+ it("changes an entity's tags", function () {
+ var entity = iD.Entity(),
+ tags = {foo: 'bar'},
+ graph = iD.actions.ChangeEntityTags(entity.id, tags)(iD.Graph([entity]));
+ expect(graph.entity(entity.id).tags).to.eql(tags);
+ });
+});
diff --git a/test/spec/actions/move.js b/test/spec/actions/move.js
new file mode 100644
index 000000000..5e4163af7
--- /dev/null
+++ b/test/spec/actions/move.js
@@ -0,0 +1,8 @@
+describe("iD.actions.Move", function () {
+ it("changes an entity's location", function () {
+ var entity = iD.Entity(),
+ loc = [2, 3],
+ graph = iD.actions.Move(entity.id, loc)(iD.Graph([entity]));
+ expect(graph.entity(entity.id).loc).to.eql(loc);
+ });
+});
diff --git a/test/spec/actions/noop.js b/test/spec/actions/noop.js
new file mode 100644
index 000000000..677c3a2e0
--- /dev/null
+++ b/test/spec/actions/noop.js
@@ -0,0 +1,7 @@
+describe("iD.actions.Noop", function () {
+ it("does nothing", function () {
+ var graph = iD.Graph(),
+ action = iD.actions.Noop(graph);
+ expect(action(graph)).to.equal(graph);
+ });
+});
diff --git a/test/spec/actions/remove_relation_member.js b/test/spec/actions/remove_relation_member.js
new file mode 100644
index 000000000..2c7c329ab
--- /dev/null
+++ b/test/spec/actions/remove_relation_member.js
@@ -0,0 +1,8 @@
+describe("iD.actions.RemoveRelationMember", function () {
+ it("removes a member from a relation", function () {
+ var node = iD.Node(),
+ relation = iD.Way({members: [node.id]}),
+ graph = iD.actions.RemoveRelationMember(relation.id, node.id)(iD.Graph([node, relation]));
+ expect(graph.entity(relation.id).members).to.eql([]);
+ });
+});
diff --git a/test/spec/actions/reverse_way.js b/test/spec/actions/reverse_way.js
new file mode 100644
index 000000000..0df898ae7
--- /dev/null
+++ b/test/spec/actions/reverse_way.js
@@ -0,0 +1,9 @@
+describe("iD.actions.ReverseWay", function () {
+ it("reverses the order of nodes in the way", function () {
+ var node1 = iD.Node(),
+ node2 = iD.Node(),
+ way = iD.Way({nodes: [node1.id, node2.id]}),
+ graph = iD.actions.ReverseWay(way.id)(iD.Graph([node1, node2, way]));
+ expect(graph.entity(way.id).nodes).to.eql([node2.id, node1.id]);
+ });
+});
diff --git a/test/spec/graph/graph.js b/test/spec/graph/graph.js
index 16cbf6995..b0f71cd91 100644
--- a/test/spec/graph/graph.js
+++ b/test/spec/graph/graph.js
@@ -83,7 +83,7 @@ describe('iD.Graph', function() {
var node = iD.Node({id: "n1"}),
way = iD.Way({id: "w1", nodes: ["n1"]}),
graph = iD.Graph({n1: node, w1: way});
- expect(graph.fetch("w1").nodes[0].id).to.equal("n1");
+ expect(graph.fetch("w1").nodes).to.eql([node]);
});
});