Merge branch 'master' into validation

This commit is contained in:
Quincy Morgan
2019-01-30 16:44:14 -05:00
60 changed files with 1903 additions and 2002 deletions
+2 -2
View File
@@ -110,7 +110,7 @@ A **line** is a way that is not an area. Elements representing lines have a `.li
class. Since a line is also a way, they also have a `.way` class.
An **area** is a way that is circular, has certain tags, or lacks certain other
tags (see `iD.Way#isArea` for the exact definition). Elements representing areas
tags (see `iD.osmWay#isArea` for the exact definition). Elements representing areas
have `.area` and `.way` classes.
@@ -302,7 +302,7 @@ The minimum zoom at which iD enters the edit mode is configured using the `conte
```js
var id = iD.Context()
var id = iD.coreContext()
.minEditableZoom(zoom_level)
```
+2 -2
View File
@@ -89,7 +89,7 @@ preset are used. For example, `shop/convenience` automatically uses the same
fields as `shop`.
In both explicit and implicit inheritance, fields for keys that define the
preset are not inherited. E.g. the `shop` field is not inherited by `shop/…` presets.
preset are not inherited. E.g. the `shop` field is not inherited by `shop/…` presets.
##### `searchable`
@@ -320,7 +320,7 @@ iD supports deployments which use a custom set of presets. You can supply preset
the `presets` accessor:
```js
var id = iD.Context().presets({
var id = iD.coreContext().presets({
presets: { ... },
fields: { ... },
defaults: { ... },
+1 -1
View File
@@ -13,7 +13,7 @@
<div id='id-container'></div>
<script>
id = iD.Context()
id = iD.coreContext()
.assetPath('dist/');
// disable boundaries (unless we have an explicit disable_features list)
+1 -1
View File
@@ -505,7 +505,7 @@ export function coreContext() {
var maprules = utilStringQs(window.location.hash).maprules;
d3_json(maprules, function (err, mapcss) {
if (err) return;
services.maprules.init(context.presets().areaKeys());
services.maprules.init();
_each(mapcss, function(mapcssSelector) {
return services.maprules.addRule(mapcssSelector);
});
+1 -1
View File
@@ -25,7 +25,7 @@ export { IssueManager } from './validations/issue_manager';
import { services } from './services/index';
var Connection = services.osm;
export { Connection };
export { coreContext as Context, setAreaKeys } from './core/context';
export { coreContext as Context, setAreaKeys, areaKeys } from './core/context';
export { coreDifference as Difference } from './core/difference';
export { coreGraph as Graph } from './core/graph';
export { coreHistory as History } from './core/history';
-1
View File
@@ -4,7 +4,6 @@ export function osmIsInterestingTag(key) {
key !== 'source' &&
key !== 'odbl' &&
key.indexOf('tiger:') !== 0;
}
+10 -1
View File
@@ -2,6 +2,8 @@ import _isMatch from 'lodash-es/isMatch';
import _intersection from 'lodash-es/intersection';
import _reduce from 'lodash-es/reduce';
import _every from 'lodash-es/every';
import { areaKeys } from '../core/context';
import {
ValidationIssueType,
@@ -101,12 +103,13 @@ var buildLineKeys = function() {
};
export default {
init: function(areaKeys) {
init: function() {
this._ruleChecks = buildRuleChecks();
this._validationRules = [];
this._areaKeys = areaKeys;
this._lineKeys = buildLineKeys();
},
// list of rules only relevant to tag checks...
filterRuleChecks: function(selector) {
var _ruleChecks = this._ruleChecks;
@@ -117,6 +120,7 @@ export default {
return rules;
}, []);
},
// builds tagMap from mapcss-parse selector object...
buildTagMap: function(selector) {
var getRegexValues = function(regexes) {
@@ -159,6 +163,7 @@ export default {
return tagMap;
},
// inspired by osmWay#isArea()
inferGeometry: function(tagMap) {
var _lineKeys = this._lineKeys;
@@ -191,6 +196,7 @@ export default {
return 'line';
},
// adds from mapcss-parse selector check...
addRule: function(selector) {
var rule = {
@@ -228,9 +234,12 @@ export default {
};
this._validationRules.push(rule);
},
clearRules: function() { this._validationRules = []; },
// returns validationRules...
validationRules: function() { return this._validationRules; },
// returns ruleChecks
ruleChecks: function() { return this._ruleChecks; }
};
+1 -1
View File
@@ -1,7 +1,7 @@
describe('iD.actionAddEntity', function () {
it('adds an entity to the graph', function () {
var entity = iD.Entity(),
graph = iD.actionAddEntity(entity)(iD.Graph());
graph = iD.actionAddEntity(entity)(iD.coreGraph());
expect(graph.entity(entity.id)).to.equal(entity);
});
});
+21 -21
View File
@@ -1,35 +1,35 @@
describe('iD.actionAddMidpoint', function () {
it('adds the node at the midpoint location', function () {
var node = iD.Node(),
a = iD.Node(),
b = iD.Node(),
var node = iD.osmNode(),
a = iD.osmNode(),
b = iD.osmNode(),
midpoint = {loc: [1, 2], edge: [a.id, b.id]},
graph = iD.actionAddMidpoint(midpoint, node)(iD.Graph([a, b]));
graph = iD.actionAddMidpoint(midpoint, node)(iD.coreGraph([a, b]));
expect(graph.entity(node.id).loc).to.eql([1, 2]);
});
it('adds the node to a way that contains the given edge in forward order', function () {
var node = iD.Node(),
a = iD.Node(),
b = iD.Node(),
w1 = iD.Way(),
w2 = iD.Way({nodes: [a.id, b.id]}),
var node = iD.osmNode(),
a = iD.osmNode(),
b = iD.osmNode(),
w1 = iD.osmWay(),
w2 = iD.osmWay({nodes: [a.id, b.id]}),
midpoint = {loc: [1, 2], edge: [a.id, b.id]},
graph = iD.actionAddMidpoint(midpoint, node)(iD.Graph([a, b, w1, w2]));
graph = iD.actionAddMidpoint(midpoint, node)(iD.coreGraph([a, b, w1, w2]));
expect(graph.entity(w1.id).nodes).to.eql([]);
expect(graph.entity(w2.id).nodes).to.eql([a.id, node.id, b.id]);
});
it('adds the node to a way that contains the given edge in reverse order', function () {
var node = iD.Node(),
a = iD.Node(),
b = iD.Node(),
w1 = iD.Way(),
w2 = iD.Way({nodes: [b.id, a.id]}),
var node = iD.osmNode(),
a = iD.osmNode(),
b = iD.osmNode(),
w1 = iD.osmWay(),
w2 = iD.osmWay({nodes: [b.id, a.id]}),
midpoint = {loc: [1, 2], edge: [a.id, b.id]},
graph = iD.actionAddMidpoint(midpoint, node)(iD.Graph([a, b, w1, w2]));
graph = iD.actionAddMidpoint(midpoint, node)(iD.coreGraph([a, b, w1, w2]));
expect(graph.entity(w1.id).nodes).to.eql([]);
expect(graph.entity(w2.id).nodes).to.eql([b.id, node.id, a.id]);
@@ -42,12 +42,12 @@ describe('iD.actionAddMidpoint', function () {
// \ /
// c
var a = iD.Node(),
b = iD.Node(),
c = iD.Node(),
w = iD.Way({nodes: [a.id, b.id, a.id]}),
var a = iD.osmNode(),
b = iD.osmNode(),
c = iD.osmNode(),
w = iD.osmWay({nodes: [a.id, b.id, a.id]}),
midpoint = {loc: [1, 2], edge: [a.id, b.id]},
graph = iD.actionAddMidpoint(midpoint, c)(iD.Graph([a, b, w]));
graph = iD.actionAddMidpoint(midpoint, c)(iD.coreGraph([a, b, w]));
expect(graph.entity(w.id).nodes).to.eql([a.id, c.id, b.id, a.id]);
});
+3 -3
View File
@@ -1,9 +1,9 @@
describe('iD.actionChangeMember', function () {
it('updates the member at the specified index', function () {
var node = iD.Node(),
relation = iD.Relation({members: [{id: node.id}]}),
var node = iD.osmNode(),
relation = iD.osmRelation({members: [{id: node.id}]}),
action = iD.actionChangeMember(relation.id, {id: node.id, role: 'node'}, 0),
graph = action(iD.Graph([node, relation]));
graph = action(iD.coreGraph([node, relation]));
expect(graph.entity(relation.id).members).to.eql([{id: node.id, role: 'node'}]);
});
});
+6 -6
View File
@@ -3,22 +3,22 @@ describe('iD.actionChangePreset', function() {
newPreset = iD.presetPreset('new', {tags: {new: 'true'}});
it('changes from one preset\'s tags to another\'s', function() {
var entity = iD.Node({tags: {old: 'true'}}),
graph = iD.Graph([entity]),
var entity = iD.osmNode({tags: {old: 'true'}}),
graph = iD.coreGraph([entity]),
action = iD.actionChangePreset(entity.id, oldPreset, newPreset);
expect(action(graph).entity(entity.id).tags).to.eql({new: 'true'});
});
it('adds the tags of a new preset to an entity without an old preset', function() {
var entity = iD.Node(),
graph = iD.Graph([entity]),
var entity = iD.osmNode(),
graph = iD.coreGraph([entity]),
action = iD.actionChangePreset(entity.id, null, newPreset);
expect(action(graph).entity(entity.id).tags).to.eql({new: 'true'});
});
it('removes the tags of an old preset from an entity without a new preset', function() {
var entity = iD.Node({tags: {old: 'true'}}),
graph = iD.Graph([entity]),
var entity = iD.osmNode({tags: {old: 'true'}}),
graph = iD.coreGraph([entity]),
action = iD.actionChangePreset(entity.id, oldPreset, null);
expect(action(graph).entity(entity.id).tags).to.eql({});
});
+1 -1
View File
@@ -2,7 +2,7 @@ describe('iD.actionChangeTags', function () {
it('changes an entity\'s tags', function () {
var entity = iD.Entity(),
tags = {foo: 'bar'},
graph = iD.actionChangeTags(entity.id, tags)(iD.Graph([entity]));
graph = iD.actionChangeTags(entity.id, tags)(iD.coreGraph([entity]));
expect(graph.entity(entity.id).tags).to.eql(tags);
});
});
+90 -90
View File
@@ -50,12 +50,12 @@ describe('iD.actionCircularize', function () {
// d ---- c
// | |
// a ---- b
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionCircularize('-', projection)(graph);
@@ -68,13 +68,13 @@ describe('iD.actionCircularize', function () {
// d,e -- c
// | |
// a ---- b
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Node({id: 'e', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmNode({id: 'e', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']})
]),
nodes;
@@ -94,13 +94,13 @@ describe('iD.actionCircularize', function () {
// b ---- a
// | |
// c ---- d
var graph = iD.Graph([
iD.Node({id: 'a', loc: [2, 2]}),
iD.Node({id: 'b', loc: [-2, 2]}),
iD.Node({id: 'c', loc: [-2, -2]}),
iD.Node({id: 'd', loc: [2, -2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']}),
iD.Way({id: '=', nodes: ['d']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [2, 2]}),
iD.osmNode({id: 'b', loc: [-2, 2]}),
iD.osmNode({id: 'c', loc: [-2, -2]}),
iD.osmNode({id: 'd', loc: [2, -2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']}),
iD.osmWay({id: '=', nodes: ['d']})
]);
graph = iD.actionCircularize('-', projection)(graph);
@@ -113,12 +113,12 @@ describe('iD.actionCircularize', function () {
// d ---- c
// | |
// a ---- b
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]),
centroid, points;
@@ -140,12 +140,12 @@ describe('iD.actionCircularize', function () {
// d ---- c
// | |
// a ---- b
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '+', nodes: ['a', 'd', 'c', 'b', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmWay({id: '+', nodes: ['a', 'd', 'c', 'b', 'a']})
]);
expect(area('+', graph)).to.be.gt(0);
@@ -160,12 +160,12 @@ describe('iD.actionCircularize', function () {
// d ---- c
// | |
// a ---- b
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
expect(area('-', graph)).to.be.lt(0);
@@ -186,16 +186,16 @@ describe('iD.actionCircularize', function () {
// a-b-c-d-e-a is counterclockwise
// a-b-f-g-e-a is clockwise
//
var graph = iD.Graph([
iD.Node({id: 'a', loc: [ 0, 0]}),
iD.Node({id: 'b', loc: [ 1, 2]}),
iD.Node({id: 'c', loc: [-2, 2]}),
iD.Node({id: 'd', loc: [-2, -2]}),
iD.Node({id: 'e', loc: [ 1, -2]}),
iD.Node({id: 'f', loc: [ 3, 2]}),
iD.Node({id: 'g', loc: [ 3, -2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']}),
iD.Way({id: '=', nodes: ['a', 'b', 'f', 'g', 'e', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [ 0, 0]}),
iD.osmNode({id: 'b', loc: [ 1, 2]}),
iD.osmNode({id: 'c', loc: [-2, 2]}),
iD.osmNode({id: 'd', loc: [-2, -2]}),
iD.osmNode({id: 'e', loc: [ 1, -2]}),
iD.osmNode({id: 'f', loc: [ 3, 2]}),
iD.osmNode({id: 'g', loc: [ 3, -2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']}),
iD.osmWay({id: '=', nodes: ['a', 'b', 'f', 'g', 'e', 'a']})
]);
expect(intersection(graph.entity('-').nodes, graph.entity('=').nodes).length).to.eql(3);
@@ -220,16 +220,16 @@ describe('iD.actionCircularize', function () {
// a-b-c-d-e-a is counterclockwise
// a-e-g-f-b-a is counterclockwise
//
var graph = iD.Graph([
iD.Node({id: 'a', loc: [ 0, 0]}),
iD.Node({id: 'b', loc: [ 1, 2]}),
iD.Node({id: 'c', loc: [-2, 2]}),
iD.Node({id: 'd', loc: [-2, -2]}),
iD.Node({id: 'e', loc: [ 1, -2]}),
iD.Node({id: 'f', loc: [ 3, 2]}),
iD.Node({id: 'g', loc: [ 3, -2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']}),
iD.Way({id: '=', nodes: ['a', 'e', 'g', 'f', 'b', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [ 0, 0]}),
iD.osmNode({id: 'b', loc: [ 1, 2]}),
iD.osmNode({id: 'c', loc: [-2, 2]}),
iD.osmNode({id: 'd', loc: [-2, -2]}),
iD.osmNode({id: 'e', loc: [ 1, -2]}),
iD.osmNode({id: 'f', loc: [ 3, 2]}),
iD.osmNode({id: 'g', loc: [ 3, -2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']}),
iD.osmWay({id: '=', nodes: ['a', 'e', 'g', 'f', 'b', 'a']})
]);
expect(intersection(graph.entity('-').nodes, graph.entity('=').nodes).length).to.eql(3);
@@ -253,16 +253,16 @@ describe('iD.actionCircularize', function () {
//
// a-b-c-d-e-a is extremely concave and 'a' is to the left of centoid..
//
var graph = iD.Graph([
iD.Node({id: 'a', loc: [ 0, 0]}),
iD.Node({id: 'b', loc: [10, 2]}),
iD.Node({id: 'c', loc: [-2, 2]}),
iD.Node({id: 'd', loc: [-2, -2]}),
iD.Node({id: 'e', loc: [10, -2]}),
iD.Node({id: 'f', loc: [15, 2]}),
iD.Node({id: 'g', loc: [15, -2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']}),
iD.Way({id: '=', nodes: ['a', 'b', 'f', 'g', 'e', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [ 0, 0]}),
iD.osmNode({id: 'b', loc: [10, 2]}),
iD.osmNode({id: 'c', loc: [-2, 2]}),
iD.osmNode({id: 'd', loc: [-2, -2]}),
iD.osmNode({id: 'e', loc: [10, -2]}),
iD.osmNode({id: 'f', loc: [15, 2]}),
iD.osmNode({id: 'g', loc: [15, -2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']}),
iD.osmWay({id: '=', nodes: ['a', 'b', 'f', 'g', 'e', 'a']})
]);
expect(graph.entity('-').isConvex(graph)).to.be.false;
@@ -275,10 +275,10 @@ describe('iD.actionCircularize', function () {
});
it('circularizes a closed single line way', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'a']})
]);
expect(area('-', graph)).to.eql(0);
@@ -295,12 +295,12 @@ describe('iD.actionCircularize', function () {
});
it('circularize at t = 0', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionCircularize('-', projection)(graph, 0);
expect(isCircular('-', graph)).to.be.not.ok;
@@ -309,12 +309,12 @@ describe('iD.actionCircularize', function () {
});
it('circularize at t = 0.5', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionCircularize('-', projection)(graph, 0.5);
expect(isCircular('-', graph)).to.be.not.ok;
@@ -323,12 +323,12 @@ describe('iD.actionCircularize', function () {
});
it('circularize at t = 1', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionCircularize('-', projection)(graph, 1);
expect(isCircular('-', graph)).to.be.ok;
+18 -18
View File
@@ -1,7 +1,7 @@
describe('iD.actionCopyEntities', function () {
it('copies a node', function () {
var a = iD.Node({id: 'a'}),
base = iD.Graph([a]),
var a = iD.osmNode({id: 'a'}),
base = iD.coreGraph([a]),
head = iD.actionCopyEntities(['a'], base)(base),
diff = iD.Difference(base, head),
created = diff.created();
@@ -11,10 +11,10 @@ describe('iD.actionCopyEntities', function () {
});
it('copies a way', function () {
var a = iD.Node({id: 'a'}),
b = iD.Node({id: 'b'}),
w = iD.Way({id: 'w', nodes: ['a', 'b']}),
base = iD.Graph([a, b, w]),
var a = iD.osmNode({id: 'a'}),
b = iD.osmNode({id: 'b'}),
w = iD.osmWay({id: 'w', nodes: ['a', 'b']}),
base = iD.coreGraph([a, b, w]),
action = iD.actionCopyEntities(['w'], base),
head = action(base),
diff = iD.Difference(base, head),
@@ -25,9 +25,9 @@ describe('iD.actionCopyEntities', function () {
});
it('copies multiple nodes', function () {
var base = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'})
var base = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'})
]),
action = iD.actionCopyEntities(['a', 'b'], base),
head = action(base),
@@ -40,12 +40,12 @@ describe('iD.actionCopyEntities', function () {
});
it('copies multiple ways, keeping the same connections', function () {
var base = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Way({id: 'w1', nodes: ['a', 'b']}),
iD.Way({id: 'w2', nodes: ['b', 'c']})
var base = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmWay({id: 'w1', nodes: ['a', 'b']}),
iD.osmWay({id: 'w2', nodes: ['b', 'c']})
]),
action = iD.actionCopyEntities(['w1', 'w2'], base),
head = action(base),
@@ -57,9 +57,9 @@ describe('iD.actionCopyEntities', function () {
});
it('obtains source entities from an alternate graph', function () {
var a = iD.Node({id: 'a'}),
old = iD.Graph([a]),
base = iD.Graph(),
var a = iD.osmNode({id: 'a'}),
old = iD.coreGraph([a]),
base = iD.coreGraph(),
action = iD.actionCopyEntities(['a'], old),
head = action(base),
diff = iD.Difference(base, head);
+7 -7
View File
@@ -1,18 +1,18 @@
describe('iD.actionDeleteMember', function () {
it('removes the member at the specified index', function () {
var a = iD.Node({id: 'a'}),
b = iD.Node({id: 'b'}),
r = iD.Relation({members: [{id: 'a'}, {id: 'b'}]}),
var a = iD.osmNode({id: 'a'}),
b = iD.osmNode({id: 'b'}),
r = iD.osmRelation({members: [{id: 'a'}, {id: 'b'}]}),
action = iD.actionDeleteMember(r.id, 0),
graph = action(iD.Graph([a, b, r]));
graph = action(iD.coreGraph([a, b, r]));
expect(graph.entity(r.id).members).to.eql([{id: 'b'}]);
});
it('deletes relations that become degenerate', function () {
var a = iD.Node({id: 'a'}),
r = iD.Relation({id: 'r', members: [{id: 'a'}]}),
var a = iD.osmNode({id: 'a'}),
r = iD.osmRelation({id: 'r', members: [{id: 'a'}]}),
action = iD.actionDeleteMember(r.id, 0),
graph = action(iD.Graph([a, r]));
graph = action(iD.coreGraph([a, r]));
expect(graph.hasEntity('r')).to.be.undefined;
});
});
+10 -10
View File
@@ -1,20 +1,20 @@
describe('iD.actionDeleteMultiple', function () {
it('deletes multiple entities of heterogeneous types', function () {
var n = iD.Node(),
w = iD.Way(),
r = iD.Relation(),
var n = iD.osmNode(),
w = iD.osmWay(),
r = iD.osmRelation(),
action = iD.actionDeleteMultiple([n.id, w.id, r.id]),
graph = action(iD.Graph([n, w, r]));
graph = action(iD.coreGraph([n, w, r]));
expect(graph.hasEntity(n.id)).to.be.undefined;
expect(graph.hasEntity(w.id)).to.be.undefined;
expect(graph.hasEntity(r.id)).to.be.undefined;
});
it('deletes a way and one of its nodes', function () {
var n = iD.Node(),
w = iD.Way({nodes: [n.id]}),
var n = iD.osmNode(),
w = iD.osmWay({nodes: [n.id]}),
action = iD.actionDeleteMultiple([w.id, n.id]),
graph = action(iD.Graph([n, w]));
graph = action(iD.coreGraph([n, w]));
expect(graph.hasEntity(w.id)).to.be.undefined;
expect(graph.hasEntity(n.id)).to.be.undefined;
});
@@ -22,9 +22,9 @@ describe('iD.actionDeleteMultiple', function () {
// This was moved to operationDelete. We should test operations and move this test there.
// describe('#disabled', function () {
// it('returns the result of the first action that is disabled', function () {
// var node = iD.Node(),
// relation = iD.Relation({members: [{id: 'w'}]}),
// graph = iD.Graph([node, relation]),
// var node = iD.osmNode(),
// relation = iD.osmRelation({members: [{id: 'w'}]}),
// graph = iD.coreGraph([node, relation]),
// action = iD.actionDeleteMultiple([node.id, relation.id]);
// expect(action.disabled(graph)).to.equal('incomplete_relation');
// });
+22 -22
View File
@@ -1,53 +1,53 @@
describe('iD.actionDeleteNode', function () {
it('removes the node from the graph', function () {
var node = iD.Node(),
var node = iD.osmNode(),
action = iD.actionDeleteNode(node.id),
graph = action(iD.Graph([node]));
graph = action(iD.coreGraph([node]));
expect(graph.hasEntity(node.id)).to.be.undefined;
});
it('removes the node from parent ways', function () {
var node1 = iD.Node(),
node2 = iD.Node(),
node3 = iD.Node(),
way = iD.Way({nodes: [node1.id, node2.id, node3.id]}),
var node1 = iD.osmNode(),
node2 = iD.osmNode(),
node3 = iD.osmNode(),
way = iD.osmWay({nodes: [node1.id, node2.id, node3.id]}),
action = iD.actionDeleteNode(node1.id),
graph = action(iD.Graph([node1, node2, node3, way]));
graph = action(iD.coreGraph([node1, node2, node3, way]));
expect(graph.entity(way.id).nodes).to.eql([node2.id, node3.id]);
});
it('removes the node from parent relations', function () {
var node1 = iD.Node(),
node2 = iD.Node(),
relation = iD.Relation({members: [{ id: node1.id }, { id: node2.id }]}),
var node1 = iD.osmNode(),
node2 = iD.osmNode(),
relation = iD.osmRelation({members: [{ id: node1.id }, { id: node2.id }]}),
action = iD.actionDeleteNode(node1.id),
graph = action(iD.Graph([node1, node2, relation]));
graph = action(iD.coreGraph([node1, node2, relation]));
expect(graph.entity(relation.id).members).to.eql([{ id: node2.id }]);
});
it('deletes parent ways that would otherwise have less than two nodes', function () {
var node1 = iD.Node(),
node2 = iD.Node(),
way = iD.Way({nodes: [node1.id, node2.id]}),
var node1 = iD.osmNode(),
node2 = iD.osmNode(),
way = iD.osmWay({nodes: [node1.id, node2.id]}),
action = iD.actionDeleteNode(node1.id),
graph = action(iD.Graph([node1, node2, way]));
graph = action(iD.coreGraph([node1, node2, way]));
expect(graph.hasEntity(way.id)).to.be.undefined;
});
it('deletes degenerate circular ways', function () {
var node1 = iD.Node(),
node2 = iD.Node(),
way = iD.Way({nodes: [node1.id, node2.id, node1.id]}),
var node1 = iD.osmNode(),
node2 = iD.osmNode(),
way = iD.osmWay({nodes: [node1.id, node2.id, node1.id]}),
action = iD.actionDeleteNode(node2.id),
graph = action(iD.Graph([node1, node2, way]));
graph = action(iD.coreGraph([node1, node2, way]));
expect(graph.hasEntity(way.id)).to.be.undefined;
});
it('deletes parent relations that become empty', function () {
var node1 = iD.Node(),
relation = iD.Relation({members: [{ id: node1.id }]}),
var node1 = iD.osmNode(),
relation = iD.osmRelation({members: [{ id: node1.id }]}),
action = iD.actionDeleteNode(node1.id),
graph = action(iD.Graph([node1, relation]));
graph = action(iD.coreGraph([node1, relation]));
expect(graph.hasEntity(relation.id)).to.be.undefined;
});
});
+35 -35
View File
@@ -1,92 +1,92 @@
describe('iD.actionDeleteRelation', function () {
it('removes the relation from the graph', function () {
var relation = iD.Relation(),
var relation = iD.osmRelation(),
action = iD.actionDeleteRelation(relation.id),
graph = action(iD.Graph([relation]));
graph = action(iD.coreGraph([relation]));
expect(graph.hasEntity(relation.id)).to.be.undefined;
});
it('removes the relation from parent relations', function () {
var a = iD.Relation(),
b = iD.Relation(),
parent = iD.Relation({members: [{ id: a.id }, { id: b.id }]}),
var a = iD.osmRelation(),
b = iD.osmRelation(),
parent = iD.osmRelation({members: [{ id: a.id }, { id: b.id }]}),
action = iD.actionDeleteRelation(a.id),
graph = action(iD.Graph([a, b, parent]));
graph = action(iD.coreGraph([a, b, parent]));
expect(graph.entity(parent.id).members).to.eql([{ id: b.id }]);
});
it('deletes member nodes not referenced by another parent', function() {
var node = iD.Node(),
relation = iD.Relation({members: [{id: node.id}]}),
var node = iD.osmNode(),
relation = iD.osmRelation({members: [{id: node.id}]}),
action = iD.actionDeleteRelation(relation.id),
graph = action(iD.Graph([node, relation]));
graph = action(iD.coreGraph([node, relation]));
expect(graph.hasEntity(node.id)).to.be.undefined;
});
it('does not delete member nodes referenced by another parent', function() {
var node = iD.Node(),
way = iD.Way({nodes: [node.id]}),
relation = iD.Relation({members: [{id: node.id}]}),
var node = iD.osmNode(),
way = iD.osmWay({nodes: [node.id]}),
relation = iD.osmRelation({members: [{id: node.id}]}),
action = iD.actionDeleteRelation(relation.id),
graph = action(iD.Graph([node, way, relation]));
graph = action(iD.coreGraph([node, way, relation]));
expect(graph.hasEntity(node.id)).not.to.be.undefined;
});
it('does not delete member nodes with interesting tags', function() {
var node = iD.Node({tags: {highway: 'traffic_signals'}}),
relation = iD.Relation({members: [{id: node.id}]}),
var node = iD.osmNode({tags: {highway: 'traffic_signals'}}),
relation = iD.osmRelation({members: [{id: node.id}]}),
action = iD.actionDeleteRelation(relation.id),
graph = action(iD.Graph([node, relation]));
graph = action(iD.coreGraph([node, relation]));
expect(graph.hasEntity(node.id)).not.to.be.undefined;
});
it('deletes member ways not referenced by another parent', function() {
var way = iD.Way(),
relation = iD.Relation({members: [{id: way.id}]}),
var way = iD.osmWay(),
relation = iD.osmRelation({members: [{id: way.id}]}),
action = iD.actionDeleteRelation(relation.id),
graph = action(iD.Graph([way, relation]));
graph = action(iD.coreGraph([way, relation]));
expect(graph.hasEntity(way.id)).to.be.undefined;
});
it('does not delete member ways referenced by another parent', function() {
var way = iD.Way(),
relation1 = iD.Relation({members: [{id: way.id}]}),
relation2 = iD.Relation({members: [{id: way.id}]}),
var way = iD.osmWay(),
relation1 = iD.osmRelation({members: [{id: way.id}]}),
relation2 = iD.osmRelation({members: [{id: way.id}]}),
action = iD.actionDeleteRelation(relation1.id),
graph = action(iD.Graph([way, relation1, relation2]));
graph = action(iD.coreGraph([way, relation1, relation2]));
expect(graph.hasEntity(way.id)).not.to.be.undefined;
});
it('does not delete member ways with interesting tags', function() {
var way = iD.Node({tags: {highway: 'residential'}}),
relation = iD.Relation({members: [{id: way.id}]}),
var way = iD.osmNode({tags: {highway: 'residential'}}),
relation = iD.osmRelation({members: [{id: way.id}]}),
action = iD.actionDeleteRelation(relation.id),
graph = action(iD.Graph([way, relation]));
graph = action(iD.coreGraph([way, relation]));
expect(graph.hasEntity(way.id)).not.to.be.undefined;
});
it('deletes nodes of deleted member ways', function() {
var node = iD.Node(),
way = iD.Way({nodes: [node.id]}),
relation = iD.Relation({members: [{id: way.id}]}),
var node = iD.osmNode(),
way = iD.osmWay({nodes: [node.id]}),
relation = iD.osmRelation({members: [{id: way.id}]}),
action = iD.actionDeleteRelation(relation.id),
graph = action(iD.Graph([node, way, relation]));
graph = action(iD.coreGraph([node, way, relation]));
expect(graph.hasEntity(node.id)).to.be.undefined;
});
it('deletes parent relations that become empty', function () {
var child = iD.Relation(),
parent = iD.Relation({members: [{ id: child.id }]}),
var child = iD.osmRelation(),
parent = iD.osmRelation({members: [{ id: child.id }]}),
action = iD.actionDeleteRelation(child.id),
graph = action(iD.Graph([child, parent]));
graph = action(iD.coreGraph([child, parent]));
expect(graph.hasEntity(parent.id)).to.be.undefined;
});
// This was moved to operationDelete. We should test operations and move this test there.
// describe('#disabled', function() {
// it('returns \'incomplete_relation\' if the relation is incomplete', function() {
// var relation = iD.Relation({members: [{id: 'w'}]}),
// graph = iD.Graph([relation]),
// var relation = iD.osmRelation({members: [{id: 'w'}]}),
// graph = iD.coreGraph([relation]),
// action = iD.actionDeleteRelation(relation.id);
// expect(action.disabled(graph)).to.equal('incomplete_relation');
// });
+38 -38
View File
@@ -1,99 +1,99 @@
describe('iD.actionDeleteWay', function() {
it('removes the way from the graph', function() {
var way = iD.Way(),
var way = iD.osmWay(),
action = iD.actionDeleteWay(way.id),
graph = iD.Graph([way]).update(action);
graph = iD.coreGraph([way]).update(action);
expect(graph.hasEntity(way.id)).to.be.undefined;
});
it('removes a way from parent relations', function() {
var way = iD.Way(),
relation = iD.Relation({members: [{ id: way.id }, { id: 'w-2' }]}),
var way = iD.osmWay(),
relation = iD.osmRelation({members: [{ id: way.id }, { id: 'w-2' }]}),
action = iD.actionDeleteWay(way.id),
graph = iD.Graph([way, relation]).update(action),
graph = iD.coreGraph([way, relation]).update(action),
ids = graph.entity(relation.id).members.map(function (m) { return m.id; });
expect(ids).not.to.contain(way.id);
});
it('deletes member nodes not referenced by another parent', function() {
var node = iD.Node(),
way = iD.Way({nodes: [node.id]}),
var node = iD.osmNode(),
way = iD.osmWay({nodes: [node.id]}),
action = iD.actionDeleteWay(way.id),
graph = iD.Graph([node, way]).update(action);
graph = iD.coreGraph([node, way]).update(action);
expect(graph.hasEntity(node.id)).to.be.undefined;
});
it('does not delete member nodes referenced by another parent', function() {
var node = iD.Node(),
way1 = iD.Way({nodes: [node.id]}),
way2 = iD.Way({nodes: [node.id]}),
var node = iD.osmNode(),
way1 = iD.osmWay({nodes: [node.id]}),
way2 = iD.osmWay({nodes: [node.id]}),
action = iD.actionDeleteWay(way1.id),
graph = iD.Graph([node, way1, way2]).update(action);
graph = iD.coreGraph([node, way1, way2]).update(action);
expect(graph.hasEntity(node.id)).not.to.be.undefined;
});
it('deletes multiple member nodes', function() {
var a = iD.Node(),
b = iD.Node(),
way = iD.Way({nodes: [a.id, b.id]}),
var a = iD.osmNode(),
b = iD.osmNode(),
way = iD.osmWay({nodes: [a.id, b.id]}),
action = iD.actionDeleteWay(way.id),
graph = iD.Graph([a, b, way]).update(action);
graph = iD.coreGraph([a, b, way]).update(action);
expect(graph.hasEntity(a.id)).to.be.undefined;
expect(graph.hasEntity(b.id)).to.be.undefined;
});
it('deletes a circular way\'s start/end node', function() {
var a = iD.Node(),
b = iD.Node(),
c = iD.Node(),
way = iD.Way({nodes: [a.id, b.id, c.id, a.id]}),
var a = iD.osmNode(),
b = iD.osmNode(),
c = iD.osmNode(),
way = iD.osmWay({nodes: [a.id, b.id, c.id, a.id]}),
action = iD.actionDeleteWay(way.id),
graph = iD.Graph([a, b, c, way]).update(action);
graph = iD.coreGraph([a, b, c, way]).update(action);
expect(graph.hasEntity(a.id)).to.be.undefined;
expect(graph.hasEntity(b.id)).to.be.undefined;
expect(graph.hasEntity(c.id)).to.be.undefined;
});
it('does not delete member nodes with interesting tags', function() {
var node = iD.Node({tags: {highway: 'traffic_signals'}}),
way = iD.Way({nodes: [node.id]}),
var node = iD.osmNode({tags: {highway: 'traffic_signals'}}),
way = iD.osmWay({nodes: [node.id]}),
action = iD.actionDeleteWay(way.id),
graph = iD.Graph([node, way]).update(action);
graph = iD.coreGraph([node, way]).update(action);
expect(graph.hasEntity(node.id)).not.to.be.undefined;
});
it('deletes parent relations that become empty', function () {
var way = iD.Way(),
relation = iD.Relation({members: [{ id: way.id }]}),
var way = iD.osmWay(),
relation = iD.osmRelation({members: [{ id: way.id }]}),
action = iD.actionDeleteWay(way.id),
graph = iD.Graph([way, relation]).update(action);
graph = iD.coreGraph([way, relation]).update(action);
expect(graph.hasEntity(relation.id)).to.be.undefined;
});
// This was moved to operationDelete. We should test operations and move this test there.
// describe('#disabled', function () {
// it('returns \'part_of_relation\' for members of route and boundary relations', function () {
// var a = iD.Way({id: 'a'}),
// b = iD.Way({id: 'b'}),
// route = iD.Relation({members: [{id: 'a'}], tags: {type: 'route'}}),
// boundary = iD.Relation({members: [{id: 'b'}], tags: {type: 'boundary'}}),
// graph = iD.Graph([a, b, route, boundary]);
// var a = iD.osmWay({id: 'a'}),
// b = iD.osmWay({id: 'b'}),
// route = iD.osmRelation({members: [{id: 'a'}], tags: {type: 'route'}}),
// boundary = iD.osmRelation({members: [{id: 'b'}], tags: {type: 'boundary'}}),
// graph = iD.coreGraph([a, b, route, boundary]);
// expect(iD.actionDeleteWay('a').disabled(graph)).to.equal('part_of_relation');
// expect(iD.actionDeleteWay('b').disabled(graph)).to.equal('part_of_relation');
// });
// it('returns \'part_of_relation\' for outer members of multipolygons', function () {
// var way = iD.Way({id: 'w'}),
// relation = iD.Relation({members: [{id: 'w', role: 'outer'}], tags: {type: 'multipolygon'}}),
// graph = iD.Graph([way, relation]),
// var way = iD.osmWay({id: 'w'}),
// relation = iD.osmRelation({members: [{id: 'w', role: 'outer'}], tags: {type: 'multipolygon'}}),
// graph = iD.coreGraph([way, relation]),
// action = iD.actionDeleteWay(way.id);
// expect(action.disabled(graph)).to.equal('part_of_relation');
// });
// it('returns falsy for inner members of multipolygons', function () {
// var way = iD.Way({id: 'w'}),
// relation = iD.Relation({members: [{id: 'w', role: 'inner'}], tags: {type: 'multipolygon'}}),
// graph = iD.Graph([way, relation]),
// var way = iD.osmWay({id: 'w'}),
// relation = iD.osmRelation({members: [{id: 'w', role: 'inner'}], tags: {type: 'multipolygon'}}),
// graph = iD.coreGraph([way, relation]),
// action = iD.actionDeleteWay(way.id);
// expect(action.disabled(graph)).not.ok;
// });
+108 -108
View File
@@ -1,7 +1,7 @@
describe('iD.actionDisconnect', function () {
describe('#disabled', function () {
it('returns \'not_connected\' for a node shared by less than two ways', function () {
var graph = iD.Graph([iD.Node({id: 'a'})]);
var graph = iD.coreGraph([iD.osmNode({id: 'a'})]);
expect(iD.actionDisconnect('a').disabled(graph)).to.equal('not_connected');
});
@@ -9,12 +9,12 @@ describe('iD.actionDisconnect', function () {
// a ---- b
// | |
// d ---- c
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Way({id: 'w', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmWay({id: 'w', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
expect(iD.actionDisconnect('a').disabled(graph)).not.to.be.ok;
});
@@ -23,12 +23,12 @@ describe('iD.actionDisconnect', function () {
// a ---- b
// | |
// d ---- c
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Way({id: 'w', nodes: ['a', 'b', 'c', 'd', 'a'], tags: {area: 'yes'}})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmWay({id: 'w', nodes: ['a', 'b', 'c', 'd', 'a'], tags: {area: 'yes'}})
]);
expect(iD.actionDisconnect('a').disabled(graph)).to.equal('not_connected');
});
@@ -37,13 +37,13 @@ describe('iD.actionDisconnect', function () {
// a --- b --- c
// | |
// e --- d
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Node({id: 'e'}),
iD.Way({id: 'w', nodes: ['a', 'b', 'c', 'd', 'e', 'b', 'a'], tags: {area: 'yes'}})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmNode({id: 'e'}),
iD.osmWay({id: 'w', nodes: ['a', 'b', 'c', 'd', 'e', 'b', 'a'], tags: {area: 'yes'}})
]);
expect(iD.actionDisconnect('b').disabled(graph)).not.to.be.ok;
@@ -53,13 +53,13 @@ describe('iD.actionDisconnect', function () {
// a ---- b ---- c
// |
// d
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Way({id: '-', nodes: ['a', 'b', 'c']}),
iD.Way({id: '|', nodes: ['d', 'b']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}),
iD.osmWay({id: '|', nodes: ['d', 'b']})
]);
expect(iD.actionDisconnect('b').disabled(graph)).not.to.be.ok;
@@ -69,13 +69,13 @@ describe('iD.actionDisconnect', function () {
// a ---- b ---- c
// |
// d
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Way({id: '-', nodes: ['a', 'b', 'c']}),
iD.Way({id: '|', nodes: ['d', 'b']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}),
iD.osmWay({id: '|', nodes: ['d', 'b']})
]);
expect(iD.actionDisconnect('b', ['|']).disabled(graph)).not.to.be.ok;
@@ -84,13 +84,13 @@ describe('iD.actionDisconnect', function () {
it('returns \'relation\' for a node connecting any two members of the same relation', function () {
// Covers restriction relations, routes, multipolygons.
// a ---- b ---- c
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Way({id: 'f', nodes: ['a', 'b']}),
iD.Way({id: 't', nodes: ['b', 'c']}),
iD.Relation({id: 'r', members: [
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmWay({id: 'f', nodes: ['a', 'b']}),
iD.osmWay({id: 't', nodes: ['b', 'c']}),
iD.osmRelation({id: 'r', members: [
{ id: 'f' },
{ id: 't' }
]})
@@ -104,15 +104,15 @@ describe('iD.actionDisconnect', function () {
// |
// d
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Way({id: 'f', nodes: ['a', 'b']}),
iD.Way({id: 't', nodes: ['b', 'c']}),
iD.Way({id: '|', nodes: ['b', 'd']}),
iD.Relation({id: 'r', members: [
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmWay({id: 'f', nodes: ['a', 'b']}),
iD.osmWay({id: 't', nodes: ['b', 'c']}),
iD.osmWay({id: '|', nodes: ['b', 'd']}),
iD.osmRelation({id: 'r', members: [
{ id: 'f' },
{ id: 't' }
]})
@@ -136,13 +136,13 @@ describe('iD.actionDisconnect', function () {
// |
// d
//
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Way({id: '-', nodes: ['a', 'b', 'c']}),
iD.Way({id: '|', nodes: ['d', 'b']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}),
iD.osmWay({id: '|', nodes: ['d', 'b']})
]);
graph = iD.actionDisconnect('b', 'e')(graph);
@@ -163,14 +163,14 @@ describe('iD.actionDisconnect', function () {
// |
// d
//
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Way({id: '-', nodes: ['a', 'b']}),
iD.Way({id: '=', nodes: ['b', 'c']}),
iD.Way({id: '|', nodes: ['d', 'b']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmWay({id: '-', nodes: ['a', 'b']}),
iD.osmWay({id: '=', nodes: ['b', 'c']}),
iD.osmWay({id: '|', nodes: ['d', 'b']})
]);
graph = iD.actionDisconnect('b', 'e').limitWays(['-'])(graph);
@@ -193,11 +193,11 @@ describe('iD.actionDisconnect', function () {
// |
// d --- c
//
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Way({id: 'w', nodes: ['a', 'b', 'c', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmWay({id: 'w', nodes: ['a', 'b', 'c', 'a']})
]);
graph = iD.actionDisconnect('a', 'd')(graph);
expect(graph.entity('w').nodes).to.eql(['a', 'b', 'c', 'd']);
@@ -218,14 +218,14 @@ describe('iD.actionDisconnect', function () {
// e -- d
// 2 ways a-b and *-c-d-e-*
//
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Node({id: 'e'}),
iD.Way({id: 'w1', nodes: ['a', 'b']}),
iD.Way({id: 'w2', nodes: ['b', 'c', 'd', 'e', 'b']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmNode({id: 'e'}),
iD.osmWay({id: 'w1', nodes: ['a', 'b']}),
iD.osmWay({id: 'w2', nodes: ['b', 'c', 'd', 'e', 'b']})
]);
graph = iD.actionDisconnect('b', '*')(graph);
@@ -247,13 +247,13 @@ describe('iD.actionDisconnect', function () {
// | |
// * -- e -- d
//
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Node({id: 'e'}),
iD.Way({id: 'w', nodes: ['a', 'b', 'c', 'd', 'e', 'b', 'a'], tags: {area: 'yes'}})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmNode({id: 'e'}),
iD.osmWay({id: 'w', nodes: ['a', 'b', 'c', 'd', 'e', 'b', 'a'], tags: {area: 'yes'}})
]);
graph = iD.actionDisconnect('b', '*')(graph);
@@ -278,14 +278,14 @@ describe('iD.actionDisconnect', function () {
// c e
// 2 areas: a-b-c-a and *-d-e-*
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Node({id: 'e'}),
iD.Way({id: 'w1', nodes: ['a', 'b', 'c', 'a'], tags: {area: 'yes'}}),
iD.Way({id: 'w2', nodes: ['b', 'd', 'e', 'b'], tags: {area: 'yes'}})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmNode({id: 'e'}),
iD.osmWay({id: 'w1', nodes: ['a', 'b', 'c', 'a'], tags: {area: 'yes'}}),
iD.osmWay({id: 'w2', nodes: ['b', 'd', 'e', 'b'], tags: {area: 'yes'}})
]);
graph = iD.actionDisconnect('b', '*')(graph);
@@ -311,14 +311,14 @@ describe('iD.actionDisconnect', function () {
// c e
// 2 areas: b-c-a-b and *-d-e-*
var graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b'}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Node({id: 'e'}),
iD.Way({id: 'w1', nodes: ['b', 'c', 'a', 'b'], tags: {area: 'yes'}}),
iD.Way({id: 'w2', nodes: ['b', 'd', 'e', 'b'], tags: {area: 'yes'}})
var graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmNode({id: 'e'}),
iD.osmWay({id: 'w1', nodes: ['b', 'c', 'a', 'b'], tags: {area: 'yes'}}),
iD.osmWay({id: 'w2', nodes: ['b', 'd', 'e', 'b'], tags: {area: 'yes'}})
]);
graph = iD.actionDisconnect('b', '*')(graph);
@@ -330,13 +330,13 @@ describe('iD.actionDisconnect', function () {
it('copies location and tags to the new nodes', function () {
var tags = {highway: 'traffic_signals'},
loc = [1, 2],
graph = iD.Graph([
iD.Node({id: 'a'}),
iD.Node({id: 'b', loc: loc, tags: tags}),
iD.Node({id: 'c'}),
iD.Node({id: 'd'}),
iD.Way({id: '-', nodes: ['a', 'b', 'c']}),
iD.Way({id: '|', nodes: ['d', 'b']})
graph = iD.coreGraph([
iD.osmNode({id: 'a'}),
iD.osmNode({id: 'b', loc: loc, tags: tags}),
iD.osmNode({id: 'c'}),
iD.osmNode({id: 'd'}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}),
iD.osmWay({id: '|', nodes: ['d', 'b']})
]);
graph = iD.actionDisconnect('b', 'e')(graph);
+15 -15
View File
@@ -1,10 +1,10 @@
describe('iD.actionMerge', function () {
it('merges multiple points to a line', function () {
var graph = iD.Graph([
iD.Node({id: 'a', tags: {a: 'a'}}),
iD.Node({id: 'b', tags: {b: 'b'}}),
iD.Way({id: 'w'}),
iD.Relation({id: 'r', members: [{id: 'a', role: 'r', type: 'node'}]})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', tags: {a: 'a'}}),
iD.osmNode({id: 'b', tags: {b: 'b'}}),
iD.osmWay({id: 'w'}),
iD.osmRelation({id: 'r', members: [{id: 'a', role: 'r', type: 'node'}]})
]),
action = iD.actionMerge(['a', 'b', 'w']);
@@ -19,11 +19,11 @@ describe('iD.actionMerge', function () {
});
it('merges multiple points to an area', function () {
var graph = iD.Graph([
iD.Node({id: 'a', tags: {a: 'a'}}),
iD.Node({id: 'b', tags: {b: 'b'}}),
iD.Way({id: 'w', tags: {area: 'yes'}}),
iD.Relation({id: 'r', members: [{id: 'a', role: 'r', type: 'node'}]})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', tags: {a: 'a'}}),
iD.osmNode({id: 'b', tags: {b: 'b'}}),
iD.osmWay({id: 'w', tags: {area: 'yes'}}),
iD.osmRelation({id: 'r', members: [{id: 'a', role: 'r', type: 'node'}]})
]),
action = iD.actionMerge(['a', 'b', 'w']);
@@ -38,11 +38,11 @@ describe('iD.actionMerge', function () {
});
it('preserves original point if possible', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [1, 0], tags: {a: 'a'}}),
iD.Node({id: 'p', loc: [0, 0], tags: {p: 'p'}}),
iD.Node({id: 'q', loc: [0, 1]}),
iD.Way({id: 'w', nodes: ['p', 'q'], tags: {w: 'w'}})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [1, 0], tags: {a: 'a'}}),
iD.osmNode({id: 'p', loc: [0, 0], tags: {p: 'p'}}),
iD.osmNode({id: 'q', loc: [0, 1]}),
iD.osmWay({id: 'w', nodes: ['p', 'q'], tags: {w: 'w'}})
]),
action = iD.actionMerge(['a', 'w']);
+9 -9
View File
@@ -1,11 +1,11 @@
describe('iD.actionMergePolygon', function () {
function node(id, x, y) {
e.push(iD.Node({ id: id, loc: [x, y] }));
e.push(iD.osmNode({ id: id, loc: [x, y] }));
}
function way(id, nodes) {
e.push(iD.Way({ id: id, nodes: nodes.map(function(n) { return 'n' + n; }) }));
e.push(iD.osmWay({ id: id, nodes: nodes.map(function(n) { return 'n' + n; }) }));
}
var e = [];
@@ -41,7 +41,7 @@ describe('iD.actionMergePolygon', function () {
var graph;
beforeEach(function() {
graph = iD.Graph(e);
graph = iD.coreGraph(e);
});
function find(relation, id) {
@@ -84,9 +84,9 @@ describe('iD.actionMergePolygon', function () {
});
it('merges multipolygon tags', function() {
var graph = iD.Graph([
iD.Relation({id: 'r1', tags: {type: 'multipolygon', a: 'a'}}),
iD.Relation({id: 'r2', tags: {type: 'multipolygon', b: 'b'}})
var graph = iD.coreGraph([
iD.osmRelation({id: 'r1', tags: {type: 'multipolygon', a: 'a'}}),
iD.osmRelation({id: 'r2', tags: {type: 'multipolygon', b: 'b'}})
]);
graph = iD.actionMergePolygon(['r1', 'r2'])(graph);
@@ -105,8 +105,8 @@ describe('iD.actionMergePolygon', function () {
it('merges no tags from unclosed outer ways', function() {
graph = graph.replace(graph.entity('w3').update({ tags: { 'natural': 'water' }}));
var r1 = iD.Relation({id: 'r1', tags: {type: 'multipolygon'}});
var r2 = iD.Relation({id: 'r2', tags: {type: 'multipolygon'},
var r1 = iD.osmRelation({id: 'r1', tags: {type: 'multipolygon'}});
var r2 = iD.osmRelation({id: 'r2', tags: {type: 'multipolygon'},
members: [
{ type: 'way', role: 'outer', id: 'w3' },
{ type: 'way', role: 'outer', id: 'w4' }
@@ -149,7 +149,7 @@ describe('iD.actionMergePolygon', function () {
});
it('extends a multipolygon with multi-way rings', function() {
var r = iD.Relation({ id: 'r', tags: { type: 'multipolygon' }, members: [
var r = iD.osmRelation({ id: 'r', tags: { type: 'multipolygon' }, members: [
{ type: 'way', role: 'outer', id: 'w0' },
{ type: 'way', role: 'inner', id: 'w3' },
{ type: 'way', role: 'inner', id: 'w4' }
+24 -24
View File
@@ -1,30 +1,30 @@
describe('iD.actionMergeRemoteChanges', function () {
var base = iD.Graph([
iD.Node({id: 'a', loc: [1, 1], version: '1', tags: {foo: 'foo'}}),
var base = iD.coreGraph([
iD.osmNode({id: 'a', loc: [1, 1], version: '1', tags: {foo: 'foo'}}),
iD.Node({id: 'p1', loc: [ 10, 10], version: '1'}),
iD.Node({id: 'p2', loc: [ 10, -10], version: '1'}),
iD.Node({id: 'p3', loc: [-10, -10], version: '1'}),
iD.Node({id: 'p4', loc: [-10, 10], version: '1'}),
iD.Way({
iD.osmNode({id: 'p1', loc: [ 10, 10], version: '1'}),
iD.osmNode({id: 'p2', loc: [ 10, -10], version: '1'}),
iD.osmNode({id: 'p3', loc: [-10, -10], version: '1'}),
iD.osmNode({id: 'p4', loc: [-10, 10], version: '1'}),
iD.osmWay({
id: 'w1',
nodes: ['p1', 'p2', 'p3', 'p4', 'p1'],
version: '1',
tags: {foo: 'foo', area: 'yes'}
}),
iD.Node({id: 'q1', loc: [ 5, 5], version: '1'}),
iD.Node({id: 'q2', loc: [ 5, -5], version: '1'}),
iD.Node({id: 'q3', loc: [-5, -5], version: '1'}),
iD.Node({id: 'q4', loc: [-5, 5], version: '1'}),
iD.Way({
iD.osmNode({id: 'q1', loc: [ 5, 5], version: '1'}),
iD.osmNode({id: 'q2', loc: [ 5, -5], version: '1'}),
iD.osmNode({id: 'q3', loc: [-5, -5], version: '1'}),
iD.osmNode({id: 'q4', loc: [-5, 5], version: '1'}),
iD.osmWay({
id: 'w2',
nodes: ['q1', 'q2', 'q3', 'q4', 'q1'],
version: '1',
tags: {foo: 'foo', area: 'yes'}
}),
iD.Relation({
iD.osmRelation({
id: 'r',
members: [{id: 'w1', role: 'outer'}, {id: 'w2', role: 'inner'}],
version: '1',
@@ -33,22 +33,22 @@ describe('iD.actionMergeRemoteChanges', function () {
]),
// some new objects not in the graph yet..
r1 = iD.Node({id: 'r1', loc: [ 12, 12], version: '1'}),
r2 = iD.Node({id: 'r2', loc: [ 12, -12], version: '1'}),
r3 = iD.Node({id: 'r3', loc: [-12, -12], version: '1'}),
r4 = iD.Node({id: 'r4', loc: [-12, 12], version: '1'}),
w3 = iD.Way({
r1 = iD.osmNode({id: 'r1', loc: [ 12, 12], version: '1'}),
r2 = iD.osmNode({id: 'r2', loc: [ 12, -12], version: '1'}),
r3 = iD.osmNode({id: 'r3', loc: [-12, -12], version: '1'}),
r4 = iD.osmNode({id: 'r4', loc: [-12, 12], version: '1'}),
w3 = iD.osmWay({
id: 'w3',
nodes: ['r1', 'r2', 'r3', 'r4', 'r1'],
version: '1',
tags: {foo: 'foo_new', area: 'yes'}
}),
s1 = iD.Node({id: 's1', loc: [ 6, 6], version: '1'}),
s2 = iD.Node({id: 's2', loc: [ 6, -6], version: '1'}),
s3 = iD.Node({id: 's3', loc: [-6, -6], version: '1'}),
s4 = iD.Node({id: 's4', loc: [-6, 6], version: '1'}),
w4 = iD.Way({
s1 = iD.osmNode({id: 's1', loc: [ 6, 6], version: '1'}),
s2 = iD.osmNode({id: 's2', loc: [ 6, -6], version: '1'}),
s3 = iD.osmNode({id: 's3', loc: [-6, -6], version: '1'}),
s4 = iD.osmNode({id: 's4', loc: [-6, 6], version: '1'}),
w4 = iD.osmWay({
id: 'w4',
nodes: ['s1', 's2', 's3', 's4', 's1'],
version: '1',
@@ -59,7 +59,7 @@ describe('iD.actionMergeRemoteChanges', function () {
function makeGraph(entities) {
return entities.reduce(function(graph, entity) {
return graph.replace(entity);
}, iD.Graph(base));
}, iD.coreGraph(base));
}
+22 -22
View File
@@ -4,34 +4,34 @@ describe('iD.actionMove', function() {
// This was moved to operationMove. We should test operations and move this test there.
// describe('#disabled', function() {
// it('returns falsy by default', function() {
// var node = iD.Node({loc: [0, 0]}),
// var node = iD.osmNode({loc: [0, 0]}),
// action = iD.actionMove([node.id], [0, 0], projection),
// graph = iD.Graph([node]);
// graph = iD.coreGraph([node]);
// expect(action.disabled(graph)).not.to.be.ok;
// });
// it('returns \'incomplete_relation\' for an incomplete relation', function() {
// var relation = iD.Relation({members: [{id: 1}]}),
// var relation = iD.osmRelation({members: [{id: 1}]}),
// action = iD.actionMove([relation.id], [0, 0], projection),
// graph = iD.Graph([relation]);
// graph = iD.coreGraph([relation]);
// expect(action.disabled(graph)).to.equal('incomplete_relation');
// });
// it('returns falsy for a complete relation', function() {
// var node = iD.Node({loc: [0, 0]}),
// relation = iD.Relation({members: [{id: node.id}]}),
// var node = iD.osmNode({loc: [0, 0]}),
// relation = iD.osmRelation({members: [{id: node.id}]}),
// action = iD.actionMove([relation.id], [0, 0], projection),
// graph = iD.Graph([node, relation]);
// graph = iD.coreGraph([node, relation]);
// expect(action.disabled(graph)).not.to.be.ok;
// });
// });
it('moves all nodes in a way by the given amount', function() {
var node1 = iD.Node({loc: [0, 0]}),
node2 = iD.Node({loc: [5, 10]}),
way = iD.Way({nodes: [node1.id, node2.id]}),
var node1 = iD.osmNode({loc: [0, 0]}),
node2 = iD.osmNode({loc: [5, 10]}),
way = iD.osmWay({nodes: [node1.id, node2.id]}),
delta = [2, 3],
graph = iD.actionMove([way.id], delta, projection)(iD.Graph([node1, node2, way])),
graph = iD.actionMove([way.id], delta, projection)(iD.coreGraph([node1, node2, way])),
loc1 = graph.entity(node1.id).loc,
loc2 = graph.entity(node2.id).loc;
expect(loc1[0]).to.be.closeTo( 1.440, 0.001);
@@ -41,32 +41,32 @@ describe('iD.actionMove', function() {
});
it('moves repeated nodes only once', function() {
var node = iD.Node({loc: [0, 0]}),
way = iD.Way({nodes: [node.id, node.id]}),
var node = iD.osmNode({loc: [0, 0]}),
way = iD.osmWay({nodes: [node.id, node.id]}),
delta = [2, 3],
graph = iD.actionMove([way.id], delta, projection)(iD.Graph([node, way])),
graph = iD.actionMove([way.id], delta, projection)(iD.coreGraph([node, way])),
loc = graph.entity(node.id).loc;
expect(loc[0]).to.be.closeTo( 1.440, 0.001);
expect(loc[1]).to.be.closeTo(-2.159, 0.001);
});
it('moves multiple ways', function() {
var node = iD.Node({loc: [0, 0]}),
way1 = iD.Way({nodes: [node.id]}),
way2 = iD.Way({nodes: [node.id]}),
var node = iD.osmNode({loc: [0, 0]}),
way1 = iD.osmWay({nodes: [node.id]}),
way2 = iD.osmWay({nodes: [node.id]}),
delta = [2, 3],
graph = iD.actionMove([way1.id, way2.id], delta, projection)(iD.Graph([node, way1, way2])),
graph = iD.actionMove([way1.id, way2.id], delta, projection)(iD.coreGraph([node, way1, way2])),
loc = graph.entity(node.id).loc;
expect(loc[0]).to.be.closeTo( 1.440, 0.001);
expect(loc[1]).to.be.closeTo(-2.159, 0.001);
});
it('moves leaf nodes of a relation', function() {
var node = iD.Node({loc: [0, 0]}),
way = iD.Way({nodes: [node.id]}),
relation = iD.Relation({members: [{id: way.id}]}),
var node = iD.osmNode({loc: [0, 0]}),
way = iD.osmWay({nodes: [node.id]}),
relation = iD.osmRelation({members: [{id: way.id}]}),
delta = [2, 3],
graph = iD.actionMove([relation.id], delta, projection)(iD.Graph([node, way, relation])),
graph = iD.actionMove([relation.id], delta, projection)(iD.coreGraph([node, way, relation])),
loc = graph.entity(node.id).loc;
expect(loc[0]).to.be.closeTo( 1.440, 0.001);
expect(loc[1]).to.be.closeTo(-2.159, 0.001);
+1 -1
View File
@@ -1,6 +1,6 @@
describe('iD.actionNoop', function () {
it('does nothing', function () {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
action = iD.actionNoop(graph);
expect(action(graph)).to.equal(graph);
});
+69 -69
View File
@@ -2,12 +2,12 @@ describe('iD.actionOrthogonalize', function () {
var projection = d3.geoMercator();
it('orthogonalizes a perfect quad', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionOrthogonalize('-', projection)(graph);
@@ -15,12 +15,12 @@ describe('iD.actionOrthogonalize', function () {
});
it('orthogonalizes a quad', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [3, 2]}),
iD.Node({id: 'd', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [3, 2]}),
iD.osmNode({id: 'd', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionOrthogonalize('-', projection)(graph);
@@ -28,11 +28,11 @@ describe('iD.actionOrthogonalize', function () {
});
it('orthogonalizes a triangle', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [3, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [3, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'a']})
]);
graph = iD.actionOrthogonalize('-', projection)(graph);
@@ -40,13 +40,13 @@ describe('iD.actionOrthogonalize', function () {
});
it('deletes empty redundant nodes', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Node({id: 'e', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmNode({id: 'e', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']})
]);
graph = iD.actionOrthogonalize('-', projection)(graph);
@@ -54,13 +54,13 @@ describe('iD.actionOrthogonalize', function () {
});
it('preserves non empty redundant nodes', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [2, 0]}),
iD.Node({id: 'c', loc: [2, 2]}),
iD.Node({id: 'd', loc: [1, 2], tags: {foo: 'bar'}}),
iD.Node({id: 'e', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [2, 0]}),
iD.osmNode({id: 'c', loc: [2, 2]}),
iD.osmNode({id: 'd', loc: [1, 2], tags: {foo: 'bar'}}),
iD.osmNode({id: 'e', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'a']})
]);
graph = iD.actionOrthogonalize('-', projection)(graph);
@@ -85,12 +85,12 @@ describe('iD.actionOrthogonalize', function () {
];
for (var i = 0; i < tests.length; i++) {
var graph = iD.Graph([
iD.Node({id: 'a', loc: tests[i][0]}),
iD.Node({id: 'b', loc: tests[i][1]}),
iD.Node({id: 'c', loc: tests[i][2]}),
iD.Node({id: 'd', loc: tests[i][3]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: tests[i][0]}),
iD.osmNode({id: 'b', loc: tests[i][1]}),
iD.osmNode({id: 'c', loc: tests[i][2]}),
iD.osmNode({id: 'd', loc: tests[i][3]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]),
initialWidth = iD.geoSphericalDistance(graph.entity('a').loc, graph.entity('b').loc),
finalWidth;
@@ -103,14 +103,14 @@ describe('iD.actionOrthogonalize', function () {
});
it('only moves nodes which are near right or near straight', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [3, 0.001]}),
iD.Node({id: 'c', loc: [3, 1]}),
iD.Node({id: 'd', loc: [2, 1]}),
iD.Node({id: 'e', loc: [1, 2]}),
iD.Node({id: 'f', loc: [0, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'f', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [3, 0.001]}),
iD.osmNode({id: 'c', loc: [3, 1]}),
iD.osmNode({id: 'd', loc: [2, 1]}),
iD.osmNode({id: 'e', loc: [1, 2]}),
iD.osmNode({id: 'f', loc: [0, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'f', 'a']})
]),
diff = iD.Difference(graph, iD.actionOrthogonalize('-', projection)(graph));
@@ -124,14 +124,14 @@ describe('iD.actionOrthogonalize', function () {
});
it('orthogonalize at t = 0', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.Node({id: 'c', loc: [2, -0.01]}),
iD.Node({id: 'd', loc: [3, 0]}),
iD.Node({id: 'e', loc: [3, 1]}),
iD.Node({id: 'f', loc: [0, 1]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'f', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.osmNode({id: 'c', loc: [2, -0.01]}),
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmNode({id: 'e', loc: [3, 1]}),
iD.osmNode({id: 'f', loc: [0, 1]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'f', 'a']})
]);
graph = iD.actionOrthogonalize('-', projection)(graph, 0);
@@ -144,14 +144,14 @@ describe('iD.actionOrthogonalize', function () {
});
it('orthogonalize at t = 0.5', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.Node({id: 'c', loc: [2, -0.01]}),
iD.Node({id: 'd', loc: [3, 0]}),
iD.Node({id: 'e', loc: [3, 1]}),
iD.Node({id: 'f', loc: [0, 1]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'f', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.osmNode({id: 'c', loc: [2, -0.01]}),
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmNode({id: 'e', loc: [3, 1]}),
iD.osmNode({id: 'f', loc: [0, 1]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'f', 'a']})
]);
graph = iD.actionOrthogonalize('-', projection)(graph, 0.5);
@@ -163,14 +163,14 @@ describe('iD.actionOrthogonalize', function () {
});
it('orthogonalize at t = 1', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.Node({id: 'c', loc: [2, -0.01]}),
iD.Node({id: 'd', loc: [3, 0]}),
iD.Node({id: 'e', loc: [3, 1]}),
iD.Node({id: 'f', loc: [0, 1]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'f', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.osmNode({id: 'c', loc: [2, -0.01]}),
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmNode({id: 'e', loc: [3, 1]}),
iD.osmNode({id: 'f', loc: [0, 1]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'e', 'f', 'a']})
]);
graph = iD.actionOrthogonalize('-', projection)(graph, 1);
+54 -54
View File
@@ -2,12 +2,12 @@ describe('iD.actionReflect', function() {
var projection = d3.geoMercator();
it('does not create or remove nodes', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [4, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [4, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionReflect(['-'], projection)(graph);
expect(graph.entity('-').nodes).to.have.length(5);
@@ -20,12 +20,12 @@ describe('iD.actionReflect', function() {
// / | -> \ |
// a ---- b d -- c
//
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [4, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [4, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionReflect(['-'], projection)(graph);
expect(graph.entity('a').loc[0]).to.be.closeTo(0, 1e-6);
@@ -45,12 +45,12 @@ describe('iD.actionReflect', function() {
// / | -> | \
// a ---- b b ---- a
//
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [4, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [4, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionReflect(['-'], projection).useLongAxis(false)(graph);
expect(graph.entity('a').loc[0]).to.be.closeTo(4, 1e-6);
@@ -70,12 +70,12 @@ describe('iD.actionReflect', function() {
});
it('reflect long at t = 0', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [4, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [4, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionReflect(['-'], projection)(graph, 0);
expect(graph.entity('a').loc[0]).to.be.closeTo(0, 1e-6);
@@ -89,12 +89,12 @@ describe('iD.actionReflect', function() {
});
it('reflect long at t = 0.5', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [4, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [4, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionReflect(['-'], projection)(graph, 0.5);
expect(graph.entity('a').loc[0]).to.be.closeTo(0, 1e-6);
@@ -108,12 +108,12 @@ describe('iD.actionReflect', function() {
});
it('reflect long at t = 1', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [4, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [4, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionReflect(['-'], projection)(graph, 1);
expect(graph.entity('a').loc[0]).to.be.closeTo(0, 1e-6);
@@ -127,12 +127,12 @@ describe('iD.actionReflect', function() {
});
it('reflect short at t = 0', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [4, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [4, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionReflect(['-'], projection).useLongAxis(false)(graph, 0);
expect(graph.entity('a').loc[0]).to.be.closeTo(0, 1e-6);
@@ -146,12 +146,12 @@ describe('iD.actionReflect', function() {
});
it('reflect short at t = 0.5', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [4, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [4, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionReflect(['-'], projection).useLongAxis(false)(graph, 0.5);
expect(graph.entity('a').loc[0]).to.be.closeTo(2, 1e-6);
@@ -165,12 +165,12 @@ describe('iD.actionReflect', function() {
});
it('reflect short at t = 1', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [4, 0]}),
iD.Node({id: 'c', loc: [4, 2]}),
iD.Node({id: 'd', loc: [1, 2]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [4, 0]}),
iD.osmNode({id: 'c', loc: [4, 2]}),
iD.osmNode({id: 'd', loc: [1, 2]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd', 'a']})
]);
graph = iD.actionReflect(['-'], projection).useLongAxis(false)(graph, 1);
expect(graph.entity('a').loc[0]).to.be.closeTo(4, 1e-6);
+47 -47
View File
@@ -1,25 +1,25 @@
describe('iD.actionRevert', function() {
describe('basic', function () {
it('removes a new entity', function() {
var n1 = iD.Node({id: 'n-1'}),
graph = iD.Graph().replace(n1);
var n1 = iD.osmNode({id: 'n-1'}),
graph = iD.coreGraph().replace(n1);
graph = iD.actionRevert('n-1')(graph);
expect(graph.hasEntity('n-1')).to.be.undefined;
});
it('reverts an updated entity', function() {
var n1 = iD.Node({id: 'n1'}),
var n1 = iD.osmNode({id: 'n1'}),
n1up = n1.update({}),
graph = iD.Graph([n1]).replace(n1up);
graph = iD.coreGraph([n1]).replace(n1up);
graph = iD.actionRevert('n1')(graph);
expect(graph.hasEntity('n1')).to.equal(n1);
});
it('restores a deleted entity', function() {
var n1 = iD.Node({id: 'n1'}),
graph = iD.Graph([n1]).remove(n1);
var n1 = iD.osmNode({id: 'n1'}),
graph = iD.coreGraph([n1]).remove(n1);
graph = iD.actionRevert('n1')(graph);
expect(graph.hasEntity('n1')).to.equal(n1);
@@ -29,12 +29,12 @@ describe('iD.actionRevert', function() {
describe('reverting way child nodes', function () {
it('removes new node, updates parent way nodelist', function() {
// note: test with a 3 node way so w1 doesnt go degenerate..
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n2'}),
n3 = iD.Node({id: 'n-3'}),
w1 = iD.Way({id: 'w1', nodes: ['n1', 'n2']}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n2'}),
n3 = iD.osmNode({id: 'n-3'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n1', 'n2']}),
w1up = w1.addNode('n-3', 2),
graph = iD.Graph([n1, n2, w1]).replace(n3).replace(w1up);
graph = iD.coreGraph([n1, n2, w1]).replace(n3).replace(w1up);
graph = iD.actionRevert('n-3')(graph);
@@ -48,11 +48,11 @@ describe('iD.actionRevert', function() {
});
it('reverts existing node, preserves parent way nodelist', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n2'}),
w1 = iD.Way({id: 'w1', nodes: ['n1', 'n2']}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n2'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n1', 'n2']}),
n1up = n1.update({}),
graph = iD.Graph([n1, n2, w1]).replace(n1up);
graph = iD.coreGraph([n1, n2, w1]).replace(n1up);
graph = iD.actionRevert('n1')(graph);
@@ -67,11 +67,11 @@ describe('iD.actionRevert', function() {
describe('reverting relation members', function () {
it('removes new node, updates parent relation memberlist', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n-2'}),
r1 = iD.Relation({id: 'r1', members: [{id: 'n1'}]}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n-2'}),
r1 = iD.osmRelation({id: 'r1', members: [{id: 'n1'}]}),
r1up = r1.addMember({id: 'n-2'}, 1),
graph = iD.Graph([n1, r1]).replace(n2).replace(r1up);
graph = iD.coreGraph([n1, r1]).replace(n2).replace(r1up);
graph = iD.actionRevert('n-2')(graph);
@@ -83,11 +83,11 @@ describe('iD.actionRevert', function() {
});
it('reverts existing node, preserves parent relation memberlist', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n2'}),
r1 = iD.Relation({id: 'r1', members: [{id: 'n1'}, {id: 'n2'}]}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n2'}),
r1 = iD.osmRelation({id: 'r1', members: [{id: 'n1'}, {id: 'n2'}]}),
n1up = n1.update({}),
graph = iD.Graph([n1, n2, r1]).replace(n1up);
graph = iD.coreGraph([n1, n2, r1]).replace(n1up);
graph = iD.actionRevert('n1')(graph);
@@ -102,10 +102,10 @@ describe('iD.actionRevert', function() {
describe('reverting parent ways', function () {
it('removes new way, preserves new and existing child nodes', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n-2'}),
w1 = iD.Way({id: 'w-1', nodes: ['n1', 'n-2']}),
graph = iD.Graph([n1]).replace(n2).replace(w1);
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n-2'}),
w1 = iD.osmWay({id: 'w-1', nodes: ['n1', 'n-2']}),
graph = iD.coreGraph([n1]).replace(n2).replace(w1);
graph = iD.actionRevert('w-1')(graph);
expect(graph.hasEntity('w-1'), 'w-1 removed').to.be.undefined;
@@ -116,11 +116,11 @@ describe('iD.actionRevert', function() {
});
it('reverts an updated way, preserves new and existing child nodes', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n-2'}),
w1 = iD.Way({id: 'w1', nodes: ['n1']}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n-2'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n1']}),
w1up = w1.addNode('n-2', 1),
graph = iD.Graph([n1, w1]).replace(n2).replace(w1up);
graph = iD.coreGraph([n1, w1]).replace(n2).replace(w1up);
graph = iD.actionRevert('w1')(graph);
expect(graph.hasEntity('w1'), 'w1 reverted').to.equal(w1);
@@ -131,11 +131,11 @@ describe('iD.actionRevert', function() {
});
it('restores a deleted way, preserves new and existing child nodes', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n-2'}),
w1 = iD.Way({id: 'w1', nodes: ['n1']}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n-2'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n1']}),
w1up = w1.addNode('n-2', 1),
graph = iD.Graph([n1, w1]).replace(n2).replace(w1up).remove(w1up);
graph = iD.coreGraph([n1, w1]).replace(n2).replace(w1up).remove(w1up);
graph = iD.actionRevert('w1')(graph);
expect(graph.hasEntity('w1'), 'w1 reverted').to.equal(w1);
@@ -148,10 +148,10 @@ describe('iD.actionRevert', function() {
describe('reverting parent relations', function () {
it('removes new relation, preserves new and existing members', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n-2'}),
r1 = iD.Relation({id: 'r-1', members: [{id: 'n1'}, {id: 'n-2'}]}),
graph = iD.Graph([n1]).replace(n2).replace(r1);
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n-2'}),
r1 = iD.osmRelation({id: 'r-1', members: [{id: 'n1'}, {id: 'n-2'}]}),
graph = iD.coreGraph([n1]).replace(n2).replace(r1);
graph = iD.actionRevert('r-1')(graph);
expect(graph.hasEntity('r-1'), 'r-1 removed').to.be.undefined;
@@ -162,11 +162,11 @@ describe('iD.actionRevert', function() {
});
it('reverts an updated relation, preserves new and existing members', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n-2'}),
r1 = iD.Relation({id: 'r1', members: [{id: 'n1'}]}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n-2'}),
r1 = iD.osmRelation({id: 'r1', members: [{id: 'n1'}]}),
r1up = r1.addMember({id: 'n-2'}, 1),
graph = iD.Graph([n1, r1]).replace(n2).replace(r1up);
graph = iD.coreGraph([n1, r1]).replace(n2).replace(r1up);
graph = iD.actionRevert('r1')(graph);
expect(graph.hasEntity('r1'), 'r1 reverted').to.equal(r1);
@@ -177,11 +177,11 @@ describe('iD.actionRevert', function() {
});
it('restores a deleted relation, preserves new and existing members', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n-2'}),
r1 = iD.Relation({id: 'r1', members: [{id: 'n1'}]}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n-2'}),
r1 = iD.osmRelation({id: 'r1', members: [{id: 'n1'}]}),
r1up = r1.addMember({id: 'n-2'}, 1),
graph = iD.Graph([n1, r1]).replace(n2).replace(r1up).remove(r1up);
graph = iD.coreGraph([n1, r1]).replace(n2).replace(r1up).remove(r1up);
graph = iD.actionRevert('r1')(graph);
expect(graph.hasEntity('r1'), 'r1 reverted').to.equal(r1);
+52 -52
View File
@@ -3,34 +3,34 @@ describe('iD.actionStraighten', function () {
describe('#disabled', function () {
it('returns falsy for ways with internal nodes near centerline', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01]}),
iD.Node({id: 'c', loc: [2, 0]}),
iD.Node({id: 'd', loc: [3, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01]}),
iD.osmNode({id: 'c', loc: [2, 0]}),
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
expect(iD.actionStraighten('-', projection).disabled(graph)).not.to.be.ok;
});
it('returns \'too_bendy\' for ways with internal nodes far off centerline', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 1]}),
iD.Node({id: 'c', loc: [2, 0]}),
iD.Node({id: 'd', loc: [3, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 1]}),
iD.osmNode({id: 'c', loc: [2, 0]}),
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
expect(iD.actionStraighten('-', projection).disabled(graph)).to.equal('too_bendy');
});
it('returns \'too_bendy\' for ways with coincident start/end nodes', function () {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0]}),
iD.Node({id: 'c', loc: [2, 0]}),
iD.Node({id: 'd', loc: [0, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0]}),
iD.osmNode({id: 'c', loc: [2, 0]}),
iD.osmNode({id: 'd', loc: [0, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
expect(iD.actionStraighten('-', projection).disabled(graph)).to.equal('too_bendy');
});
@@ -38,11 +38,11 @@ describe('iD.actionStraighten', function () {
it('deletes empty nodes', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01], tags: {}}),
iD.Node({id: 'c', loc: [2, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01], tags: {}}),
iD.osmNode({id: 'c', loc: [2, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c']})
]);
graph = iD.actionStraighten('-', projection)(graph);
@@ -51,11 +51,11 @@ describe('iD.actionStraighten', function () {
});
it('does not delete tagged nodes', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.Node({id: 'c', loc: [2, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.osmNode({id: 'c', loc: [2, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c']})
]);
graph = iD.actionStraighten('-', projection)(graph);
@@ -65,12 +65,12 @@ describe('iD.actionStraighten', function () {
});
it('does not delete nodes connected to other ways', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01]}),
iD.Node({id: 'c', loc: [2, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c']}),
iD.Way({id: '=', nodes: ['b']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01]}),
iD.osmNode({id: 'c', loc: [2, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c']}),
iD.osmWay({id: '=', nodes: ['b']})
]);
graph = iD.actionStraighten('-', projection)(graph);
@@ -86,12 +86,12 @@ describe('iD.actionStraighten', function () {
});
it('straighten at t = 0', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.Node({id: 'c', loc: [2, -0.01]}),
iD.Node({id: 'd', loc: [3, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.osmNode({id: 'c', loc: [2, -0.01]}),
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
graph = iD.actionStraighten('-', projection)(graph, 0);
@@ -103,12 +103,12 @@ describe('iD.actionStraighten', function () {
});
it('straighten at t = 0.5', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.Node({id: 'c', loc: [2, -0.01]}),
iD.Node({id: 'd', loc: [3, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.osmNode({id: 'c', loc: [2, -0.01]}),
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
graph = iD.actionStraighten('-', projection)(graph, 0.5);
@@ -120,12 +120,12 @@ describe('iD.actionStraighten', function () {
});
it('straighten at t = 1', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.Node({id: 'c', loc: [2, -0.01]}),
iD.Node({id: 'd', loc: [3, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']})
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.osmNode({id: 'c', loc: [2, -0.01]}),
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
graph = iD.actionStraighten('-', projection)(graph, 1);
+1 -1
View File
@@ -4,7 +4,7 @@ describe('iD.behaviorHash', function () {
var hash, context;
beforeEach(function () {
context = iD.Context();
context = iD.coreContext();
var container = d3.select(document.createElement('div'));
context.container(container);
container.call(context.map());
+1 -1
View File
@@ -2,7 +2,7 @@ describe('iD.behaviorLasso', function () {
var context, lasso;
beforeEach(function () {
context = iD.Context();
context = iD.coreContext();
d3.select(document.createElement('div'))
.attr('id', 'map')
.call(context.map());
+3 -3
View File
@@ -3,10 +3,10 @@ describe('iD.behaviorSelect', function() {
beforeEach(function() {
container = d3.select('body').append('div');
context = iD.Context().container(container);
context = iD.coreContext().container(container);
a = iD.Node({loc: [0, 0]});
b = iD.Node({loc: [0, 0]});
a = iD.osmNode({loc: [0, 0]});
b = iD.osmNode({loc: [0, 0]});
context.perform(iD.actionAddEntity(a), iD.actionAddEntity(b));
+6 -6
View File
@@ -1,11 +1,11 @@
describe('iD.Context', function() {
describe('iD.coreContext', function() {
var assets = {
'iD/img/loader.gif': '/assets/iD/img/loader-b66184b5c4afbccc25f.gif'
};
describe('#assetPath', function() {
it('sets and gets assetPath', function() {
var context = iD.Context();
var context = iD.coreContext();
expect(context.assetPath()).to.eql('');
context.assetPath('iD/');
@@ -15,7 +15,7 @@ describe('iD.Context', function() {
describe('#assetMap', function() {
it('sets and gets assetMap', function() {
var context = iD.Context();
var context = iD.coreContext();
expect(context.assetMap()).to.eql({});
context.assetMap(assets);
@@ -26,7 +26,7 @@ describe('iD.Context', function() {
describe('#asset', function() {
var context;
beforeEach(function() {
context = iD.Context().assetPath('iD/').assetMap(assets);
context = iD.coreContext().assetPath('iD/').assetMap(assets);
});
it('looks first in assetMap', function() {
@@ -40,7 +40,7 @@ describe('iD.Context', function() {
describe('#imagePath', function() {
var context;
beforeEach(function() {
context = iD.Context().assetPath('iD/').assetMap(assets);
context = iD.coreContext().assetPath('iD/').assetMap(assets);
});
it('looks first in assetMap', function() {
@@ -53,7 +53,7 @@ describe('iD.Context', function() {
describe('#debug', function() {
it('sets and gets debug flags', function() {
var context = iD.Context(),
var context = iD.coreContext(),
flags = {
tile: false,
collision: false,
+77 -77
View File
@@ -1,92 +1,92 @@
describe('iD.Difference', function () {
describe('#changes', function () {
it('includes created entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph(),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph(),
head = base.replace(node),
diff = iD.Difference(base, head);
expect(diff.changes()).to.eql({n: {base: undefined, head: node}});
});
it('includes undone created entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph(),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph(),
head = base.replace(node),
diff = iD.Difference(head, base);
expect(diff.changes()).to.eql({n: {base: node, head: undefined}});
});
it('includes modified entities', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.update({ tags: { yes: 'no' } }),
base = iD.Graph([n1]),
base = iD.coreGraph([n1]),
head = base.replace(n2),
diff = iD.Difference(base, head);
expect(diff.changes()).to.eql({n: {base: n1, head: n2}});
});
it('includes undone modified entities', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.update({ tags: { yes: 'no' } }),
base = iD.Graph([n1]),
base = iD.coreGraph([n1]),
head = base.replace(n2),
diff = iD.Difference(head, base);
expect(diff.changes()).to.eql({n: {base: n2, head: n1}});
});
it('doesn\'t include updated but identical entities', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.update(),
base = iD.Graph([n1]),
base = iD.coreGraph([n1]),
head = base.replace(n2),
diff = iD.Difference(base, head);
expect(diff.changes()).to.eql({});
});
it('includes deleted entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph([node]),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph([node]),
head = base.remove(node),
diff = iD.Difference(base, head);
expect(diff.changes()).to.eql({n: {base: node, head: undefined}});
});
it('includes undone deleted entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph([node]),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph([node]),
head = base.remove(node),
diff = iD.Difference(head, base);
expect(diff.changes()).to.eql({n: {base: undefined, head: node}});
});
it('doesn\'t include created entities that were subsequently deleted', function () {
var node = iD.Node(),
base = iD.Graph(),
var node = iD.osmNode(),
base = iD.coreGraph(),
head = base.replace(node).remove(node),
diff = iD.Difference(base, head);
expect(diff.changes()).to.eql({});
});
it('doesn\'t include created entities that were subsequently reverted', function () {
var node = iD.Node({id: 'n-1'}),
base = iD.Graph(),
var node = iD.osmNode({id: 'n-1'}),
base = iD.coreGraph(),
head = base.replace(node).revert('n-1'),
diff = iD.Difference(base, head);
expect(diff.changes()).to.eql({});
});
it('doesn\'t include modified entities that were subsequently reverted', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.update({ tags: { yes: 'no' } }),
base = iD.Graph([n1]),
base = iD.coreGraph([n1]),
head = base.replace(n2).revert('n'),
diff = iD.Difference(base, head);
expect(diff.changes()).to.eql({});
});
it('doesn\'t include deleted entities that were subsequently reverted', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph([node]),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph([node]),
head = base.remove(node).revert('n'),
diff = iD.Difference(base, head);
expect(diff.changes()).to.eql({});
@@ -95,25 +95,25 @@ describe('iD.Difference', function () {
describe('#extantIDs', function () {
it('includes the ids of created entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph(),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph(),
head = base.replace(node),
diff = iD.Difference(base, head);
expect(diff.extantIDs()).to.eql(['n']);
});
it('includes the ids of modified entities', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.move([1, 2]),
base = iD.Graph([n1]),
base = iD.coreGraph([n1]),
head = base.replace(n2),
diff = iD.Difference(base, head);
expect(diff.extantIDs()).to.eql(['n']);
});
it('omits the ids of deleted entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph([node]),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph([node]),
head = base.remove(node),
diff = iD.Difference(base, head);
expect(diff.extantIDs()).to.eql([]);
@@ -122,8 +122,8 @@ describe('iD.Difference', function () {
describe('#created', function () {
it('returns an array of created entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph(),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph(),
head = base.replace(node),
diff = iD.Difference(base, head);
expect(diff.created()).to.eql([node]);
@@ -132,9 +132,9 @@ describe('iD.Difference', function () {
describe('#modified', function () {
it('returns an array of modified entities', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.move([1, 2]),
base = iD.Graph([n1]),
base = iD.coreGraph([n1]),
head = base.replace(n2),
diff = iD.Difference(base, head);
expect(diff.modified()).to.eql([n2]);
@@ -143,8 +143,8 @@ describe('iD.Difference', function () {
describe('#deleted', function () {
it('returns an array of deleted entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph([node]),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph([node]),
head = base.remove(node),
diff = iD.Difference(base, head);
expect(diff.deleted()).to.eql([node]);
@@ -152,15 +152,15 @@ describe('iD.Difference', function () {
});
describe('#summary', function () {
var base = iD.Graph([
iD.Node({id: 'a', tags: {crossing: 'marked'}}),
iD.Node({id: 'b'}),
iD.Node({id: 'v'}),
iD.Way({id: '-', nodes: ['a', 'b']})
var base = iD.coreGraph([
iD.osmNode({id: 'a', tags: {crossing: 'marked'}}),
iD.osmNode({id: 'b'}),
iD.osmNode({id: 'v'}),
iD.osmWay({id: '-', nodes: ['a', 'b']})
]);
it('reports a created way as created', function() {
var way = iD.Way({id: '+'}),
var way = iD.osmWay({id: '+'}),
head = base.replace(way),
diff = iD.Difference(base, head);
@@ -208,7 +208,7 @@ describe('iD.Difference', function () {
});
it('reports a way as modified when a member vertex is added', function() {
var vertex = iD.Node({id: 'c'}),
var vertex = iD.osmNode({id: 'c'}),
way = base.entity('-').addNode('c'),
head = base.replace(vertex).replace(way),
diff = iD.Difference(base, head);
@@ -234,7 +234,7 @@ describe('iD.Difference', function () {
it('reports a created way containing a moved vertex as being created', function() {
var vertex = base.entity('b').move([0,3]),
way = iD.Way({id: '+', nodes: ['b']}),
way = iD.osmWay({id: '+', nodes: ['b']}),
head = base.replace(way).replace(vertex),
diff = iD.Difference(base, head);
@@ -250,8 +250,8 @@ describe('iD.Difference', function () {
});
it('reports a created way with a created vertex as being created', function() {
var vertex = iD.Node({id: 'c'}),
way = iD.Way({id: '+', nodes: ['c']}),
var vertex = iD.osmNode({id: 'c'}),
way = iD.osmWay({id: '+', nodes: ['c']}),
head = base.replace(vertex).replace(way),
diff = iD.Difference(base, head);
@@ -315,7 +315,7 @@ describe('iD.Difference', function () {
});
it('reports a vertex as created when it has tags', function() {
var vertex = iD.Node({id: 'c', tags: {crossing: 'marked'}}),
var vertex = iD.osmNode({id: 'c', tags: {crossing: 'marked'}}),
way = base.entity('-').addNode('c'),
head = base.replace(way).replace(vertex),
diff = iD.Difference(base, head);
@@ -334,36 +334,36 @@ describe('iD.Difference', function () {
describe('#complete', function () {
it('includes created entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph(),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph(),
head = base.replace(node),
diff = iD.Difference(base, head);
expect(diff.complete().n).to.equal(node);
});
it('includes modified entities', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.move([1, 2]),
base = iD.Graph([n1]),
base = iD.coreGraph([n1]),
head = base.replace(n2),
diff = iD.Difference(base, head);
expect(diff.complete().n).to.equal(n2);
});
it('includes deleted entities', function () {
var node = iD.Node({id: 'n'}),
base = iD.Graph([node]),
var node = iD.osmNode({id: 'n'}),
base = iD.coreGraph([node]),
head = base.remove(node),
diff = iD.Difference(base, head);
expect(diff.complete()).to.eql({n: undefined});
});
it('includes nodes added to a way', function () {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n2'}),
w1 = iD.Way({id: 'w', nodes: ['n1']}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n2'}),
w1 = iD.osmWay({id: 'w', nodes: ['n1']}),
w2 = w1.addNode('n2'),
base = iD.Graph([n1, n2, w1]),
base = iD.coreGraph([n1, n2, w1]),
head = base.replace(w2),
diff = iD.Difference(base, head);
@@ -371,11 +371,11 @@ describe('iD.Difference', function () {
});
it('includes nodes removed from a way', function () {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n2'}),
w1 = iD.Way({id: 'w', nodes: ['n1', 'n2']}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n2'}),
w1 = iD.osmWay({id: 'w', nodes: ['n1', 'n2']}),
w2 = w1.removeNode('n2'),
base = iD.Graph([n1, n2, w1]),
base = iD.coreGraph([n1, n2, w1]),
head = base.replace(w2),
diff = iD.Difference(base, head);
@@ -383,10 +383,10 @@ describe('iD.Difference', function () {
});
it('includes parent ways of modified nodes', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.move([1, 2]),
way = iD.Way({id: 'w', nodes: ['n']}),
base = iD.Graph([n1, way]),
way = iD.osmWay({id: 'w', nodes: ['n']}),
base = iD.coreGraph([n1, way]),
head = base.replace(n2),
diff = iD.Difference(base, head);
@@ -394,10 +394,10 @@ describe('iD.Difference', function () {
});
it('includes parent relations of modified entities', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.move([1, 2]),
rel = iD.Relation({id: 'r', members: [{id: 'n'}]}),
base = iD.Graph([n1, rel]),
rel = iD.osmRelation({id: 'r', members: [{id: 'n'}]}),
base = iD.coreGraph([n1, rel]),
head = base.replace(n2),
diff = iD.Difference(base, head);
@@ -405,11 +405,11 @@ describe('iD.Difference', function () {
});
it('includes parent relations of modified entities, recursively', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.move([1, 2]),
rel1 = iD.Relation({id: 'r1', members: [{id: 'n'}]}),
rel2 = iD.Relation({id: 'r2', members: [{id: 'r1'}]}),
base = iD.Graph([n1, rel1, rel2]),
rel1 = iD.osmRelation({id: 'r1', members: [{id: 'n'}]}),
rel2 = iD.osmRelation({id: 'r2', members: [{id: 'r1'}]}),
base = iD.coreGraph([n1, rel1, rel2]),
head = base.replace(n2),
diff = iD.Difference(base, head);
@@ -417,11 +417,11 @@ describe('iD.Difference', function () {
});
it('includes parent relations of parent ways of modified nodes', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.move([1, 2]),
way = iD.Way({id: 'w', nodes: ['n']}),
rel = iD.Relation({id: 'r', members: [{id: 'w'}]}),
base = iD.Graph([n1, way, rel]),
way = iD.osmWay({id: 'w', nodes: ['n']}),
rel = iD.osmRelation({id: 'r', members: [{id: 'w'}]}),
base = iD.coreGraph([n1, way, rel]),
head = base.replace(n2),
diff = iD.Difference(base, head);
@@ -429,10 +429,10 @@ describe('iD.Difference', function () {
});
it('copes with recursive relations', function () {
var node = iD.Node({id: 'n'}),
rel1 = iD.Relation({id: 'r1', members: [{id: 'n'}, {id: 'r2'}]}),
rel2 = iD.Relation({id: 'r2', members: [{id: 'r1'}]}),
base = iD.Graph([node, rel1, rel2]),
var node = iD.osmNode({id: 'n'}),
rel1 = iD.osmRelation({id: 'r1', members: [{id: 'n'}, {id: 'r2'}]}),
rel2 = iD.osmRelation({id: 'r2', members: [{id: 'r1'}]}),
base = iD.coreGraph([node, rel1, rel2]),
head = base.replace(node.move([1, 2])),
diff = iD.Difference(base, head);
+158 -158
View File
@@ -1,67 +1,67 @@
describe('iD.Graph', function() {
describe('iD.coreGraph', function() {
describe('constructor', function () {
it('accepts an entities Array', function () {
var entity = iD.Entity(),
graph = iD.Graph([entity]);
graph = iD.coreGraph([entity]);
expect(graph.entity(entity.id)).to.equal(entity);
});
it('accepts a Graph', function () {
var entity = iD.Entity(),
graph = iD.Graph(iD.Graph([entity]));
graph = iD.coreGraph(iD.coreGraph([entity]));
expect(graph.entity(entity.id)).to.equal(entity);
});
it('copies other\'s entities', function () {
var entity = iD.Entity(),
base = iD.Graph([entity]),
graph = iD.Graph(base);
base = iD.coreGraph([entity]),
graph = iD.coreGraph(base);
expect(graph.entities).not.to.equal(base.entities);
});
it('rebases on other\'s base', function () {
var base = iD.Graph(),
graph = iD.Graph(base);
var base = iD.coreGraph(),
graph = iD.coreGraph(base);
expect(graph.base().entities).to.equal(base.base().entities);
});
it('freezes by default', function () {
expect(iD.Graph().frozen).to.be.true;
expect(iD.coreGraph().frozen).to.be.true;
});
it('remains mutable if passed true as second argument', function () {
expect(iD.Graph([], true).frozen).to.be.false;
expect(iD.coreGraph([], true).frozen).to.be.false;
});
});
describe('#hasEntity', function () {
it('returns the entity when present', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
expect(graph.hasEntity(node.id)).to.equal(node);
});
it('returns undefined when the entity is not present', function () {
expect(iD.Graph().hasEntity('1')).to.be.undefined;
expect(iD.coreGraph().hasEntity('1')).to.be.undefined;
});
});
describe('#entity', function () {
it('returns the entity when present', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
expect(graph.entity(node.id)).to.equal(node);
});
it('throws when the entity is not present', function () {
expect(function() { iD.Graph().entity('1'); }).to.throw;
expect(function() { iD.coreGraph().entity('1'); }).to.throw;
});
});
describe('#rebase', function () {
it('preserves existing entities', function () {
var node = iD.Node({id: 'n'}),
graph = iD.Graph([node]);
var node = iD.osmNode({id: 'n'}),
graph = iD.coreGraph([node]);
graph.rebase([], [graph]);
@@ -69,8 +69,8 @@ describe('iD.Graph', function() {
});
it('includes new entities', function () {
var node = iD.Node({id: 'n'}),
graph = iD.Graph();
var node = iD.osmNode({id: 'n'}),
graph = iD.coreGraph();
graph.rebase([node], [graph]);
@@ -78,8 +78,8 @@ describe('iD.Graph', function() {
});
it('doesn\'t rebase deleted entities', function () {
var node = iD.Node({id: 'n', visible: false}),
graph = iD.Graph();
var node = iD.osmNode({id: 'n', visible: false}),
graph = iD.coreGraph();
graph.rebase([node], [graph]);
@@ -87,9 +87,9 @@ describe('iD.Graph', function() {
});
it('gives precedence to existing entities', function () {
var a = iD.Node({id: 'n'}),
b = iD.Node({id: 'n'}),
graph = iD.Graph([a]);
var a = iD.osmNode({id: 'n'}),
b = iD.osmNode({id: 'n'}),
graph = iD.coreGraph([a]);
graph.rebase([b], [graph]);
@@ -97,9 +97,9 @@ describe('iD.Graph', function() {
});
it('gives precedence to new entities when force = true', function () {
var a = iD.Node({id: 'n'}),
b = iD.Node({id: 'n'}),
graph = iD.Graph([a]);
var a = iD.osmNode({id: 'n'}),
b = iD.osmNode({id: 'n'}),
graph = iD.coreGraph([a]);
graph.rebase([b], [graph], true);
@@ -107,18 +107,18 @@ describe('iD.Graph', function() {
});
it('inherits entities from base prototypally', function () {
var graph = iD.Graph();
var graph = iD.coreGraph();
graph.rebase([iD.Node({id: 'n'})], [graph]);
graph.rebase([iD.osmNode({id: 'n'})], [graph]);
expect(graph.entities).not.to.have.ownProperty('n');
});
it('updates parentWays', function () {
var n = iD.Node({id: 'n'}),
w1 = iD.Way({id: 'w1', nodes: ['n']}),
w2 = iD.Way({id: 'w2', nodes: ['n']}),
graph = iD.Graph([n, w1]);
var n = iD.osmNode({id: 'n'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n']}),
w2 = iD.osmWay({id: 'w2', nodes: ['n']}),
graph = iD.coreGraph([n, w1]);
graph.rebase([w2], [graph]);
@@ -127,9 +127,9 @@ describe('iD.Graph', function() {
});
it('avoids adding duplicate parentWays', function () {
var n = iD.Node({id: 'n'}),
w1 = iD.Way({id: 'w1', nodes: ['n']}),
graph = iD.Graph([n, w1]);
var n = iD.osmNode({id: 'n'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n']}),
graph = iD.coreGraph([n, w1]);
graph.rebase([w1], [graph]);
@@ -137,11 +137,11 @@ describe('iD.Graph', function() {
});
it('updates parentWays for nodes with modified parentWays', function () {
var n = iD.Node({id: 'n'}),
w1 = iD.Way({id: 'w1', nodes: ['n']}),
w2 = iD.Way({id: 'w2', nodes: ['n']}),
w3 = iD.Way({id: 'w3', nodes: ['n']}),
graph = iD.Graph([n, w1]),
var n = iD.osmNode({id: 'n'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n']}),
w2 = iD.osmWay({id: 'w2', nodes: ['n']}),
w3 = iD.osmWay({id: 'w3', nodes: ['n']}),
graph = iD.coreGraph([n, w1]),
graph2 = graph.replace(w2);
graph.rebase([w3], [graph, graph2]);
@@ -150,11 +150,11 @@ describe('iD.Graph', function() {
});
it('avoids re-adding a modified way as a parent way', function() {
var n1 = iD.Node({id: 'n1'}),
n2 = iD.Node({id: 'n2'}),
w1 = iD.Way({id: 'w1', nodes: ['n1', 'n2']}),
var n1 = iD.osmNode({id: 'n1'}),
n2 = iD.osmNode({id: 'n2'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n1', 'n2']}),
w2 = w1.removeNode('n2'),
graph = iD.Graph([n1, n2, w1]),
graph = iD.coreGraph([n1, n2, w1]),
graph2 = graph.replace(w2);
graph.rebase([w1], [graph, graph2]);
@@ -163,9 +163,9 @@ describe('iD.Graph', function() {
});
it('avoids re-adding a deleted way as a parent way', function() {
var n = iD.Node({id: 'n'}),
w1 = iD.Way({id: 'w1', nodes: ['n']}),
graph = iD.Graph([n, w1]),
var n = iD.osmNode({id: 'n'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n']}),
graph = iD.coreGraph([n, w1]),
graph2 = graph.remove(w1);
graph.rebase([w1], [graph, graph2]);
@@ -174,10 +174,10 @@ describe('iD.Graph', function() {
});
it('re-adds a deleted node that is discovered to have another parent', function() {
var n = iD.Node({id: 'n'}),
w1 = iD.Way({id: 'w1', nodes: ['n']}),
w2 = iD.Way({id: 'w2', nodes: ['n']}),
graph = iD.Graph([n, w1]),
var n = iD.osmNode({id: 'n'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n']}),
w2 = iD.osmWay({id: 'w2', nodes: ['n']}),
graph = iD.coreGraph([n, w1]),
graph2 = graph.remove(n);
graph.rebase([n, w2], [graph, graph2]);
@@ -186,10 +186,10 @@ describe('iD.Graph', function() {
});
it('updates parentRelations', function () {
var n = iD.Node({id: 'n'}),
r1 = iD.Relation({id: 'r1', members: [{id: 'n'}]}),
r2 = iD.Relation({id: 'r2', members: [{id: 'n'}]}),
graph = iD.Graph([n, r1]);
var n = iD.osmNode({id: 'n'}),
r1 = iD.osmRelation({id: 'r1', members: [{id: 'n'}]}),
r2 = iD.osmRelation({id: 'r2', members: [{id: 'n'}]}),
graph = iD.coreGraph([n, r1]);
graph.rebase([r2], [graph]);
@@ -198,10 +198,10 @@ describe('iD.Graph', function() {
});
it('avoids re-adding a modified relation as a parent relation', function() {
var n = iD.Node({id: 'n'}),
r1 = iD.Relation({id: 'r1', members: [{id: 'n'}]}),
var n = iD.osmNode({id: 'n'}),
r1 = iD.osmRelation({id: 'r1', members: [{id: 'n'}]}),
r2 = r1.removeMembersWithID('n'),
graph = iD.Graph([n, r1]),
graph = iD.coreGraph([n, r1]),
graph2 = graph.replace(r2);
graph.rebase([r1], [graph, graph2]);
@@ -210,9 +210,9 @@ describe('iD.Graph', function() {
});
it('avoids re-adding a deleted relation as a parent relation', function() {
var n = iD.Node({id: 'n'}),
r1 = iD.Relation({id: 'r1', members: [{id: 'n'}]}),
graph = iD.Graph([n, r1]),
var n = iD.osmNode({id: 'n'}),
r1 = iD.osmRelation({id: 'r1', members: [{id: 'n'}]}),
graph = iD.coreGraph([n, r1]),
graph2 = graph.remove(r1);
graph.rebase([r1], [graph, graph2]);
@@ -221,11 +221,11 @@ describe('iD.Graph', function() {
});
it('updates parentRels for nodes with modified parentWays', function () {
var n = iD.Node({id: 'n'}),
r1 = iD.Relation({id: 'r1', members: [{id: 'n'}]}),
r2 = iD.Relation({id: 'r2', members: [{id: 'n'}]}),
r3 = iD.Relation({id: 'r3', members: [{id: 'n'}]}),
graph = iD.Graph([n, r1]),
var n = iD.osmNode({id: 'n'}),
r1 = iD.osmRelation({id: 'r1', members: [{id: 'n'}]}),
r2 = iD.osmRelation({id: 'r2', members: [{id: 'n'}]}),
r3 = iD.osmRelation({id: 'r3', members: [{id: 'n'}]}),
graph = iD.coreGraph([n, r1]),
graph2 = graph.replace(r2);
graph.rebase([r3], [graph, graph2]);
@@ -234,10 +234,10 @@ describe('iD.Graph', function() {
});
it('invalidates transients', function() {
var n = iD.Node({id: 'n'}),
w1 = iD.Way({id: 'w1', nodes: ['n']}),
w2 = iD.Way({id: 'w2', nodes: ['n']}),
graph = iD.Graph([n, w1]);
var n = iD.osmNode({id: 'n'}),
w1 = iD.osmWay({id: 'w1', nodes: ['n']}),
w2 = iD.osmWay({id: 'w2', nodes: ['n']}),
graph = iD.coreGraph([n, w1]);
function numParents(entity) {
return graph.transient(entity, 'numParents', function() {
@@ -253,160 +253,160 @@ describe('iD.Graph', function() {
describe('#remove', function () {
it('returns a new graph', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
expect(graph.remove(node)).not.to.equal(graph);
});
it('doesn\'t modify the receiver', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
graph.remove(node);
expect(graph.entity(node.id)).to.equal(node);
});
it('removes the entity from the result', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
expect(graph.remove(node).hasEntity(node.id)).to.be.undefined;
});
it('removes the entity as a parentWay', function () {
var node = iD.Node({id: 'n' }),
w1 = iD.Way({id: 'w', nodes: ['n']}),
graph = iD.Graph([node, w1]);
var node = iD.osmNode({id: 'n' }),
w1 = iD.osmWay({id: 'w', nodes: ['n']}),
graph = iD.coreGraph([node, w1]);
expect(graph.remove(w1).parentWays(node)).to.eql([]);
});
it('removes the entity as a parentRelation', function () {
var node = iD.Node({id: 'n' }),
r1 = iD.Relation({id: 'w', members: [{id: 'n' }]}),
graph = iD.Graph([node, r1]);
var node = iD.osmNode({id: 'n' }),
r1 = iD.osmRelation({id: 'w', members: [{id: 'n' }]}),
graph = iD.coreGraph([node, r1]);
expect(graph.remove(r1).parentRelations(node)).to.eql([]);
});
});
describe('#replace', function () {
it('is a no-op if the replacement is identical to the existing entity', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
expect(graph.replace(node)).to.equal(graph);
});
it('returns a new graph', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
expect(graph.replace(node.update())).not.to.equal(graph);
});
it('doesn\'t modify the receiver', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
graph.replace(node);
expect(graph.entity(node.id)).to.equal(node);
});
it('replaces the entity in the result', function () {
var node1 = iD.Node(),
var node1 = iD.osmNode(),
node2 = node1.update({}),
graph = iD.Graph([node1]);
graph = iD.coreGraph([node1]);
expect(graph.replace(node2).entity(node2.id)).to.equal(node2);
});
it('adds parentWays', function () {
var node = iD.Node({id: 'n' }),
w1 = iD.Way({id: 'w', nodes: ['n']}),
graph = iD.Graph([node]);
var node = iD.osmNode({id: 'n' }),
w1 = iD.osmWay({id: 'w', nodes: ['n']}),
graph = iD.coreGraph([node]);
expect(graph.replace(w1).parentWays(node)).to.eql([w1]);
});
it('removes parentWays', function () {
var node = iD.Node({id: 'n' }),
w1 = iD.Way({id: 'w', nodes: ['n']}),
graph = iD.Graph([node, w1]);
var node = iD.osmNode({id: 'n' }),
w1 = iD.osmWay({id: 'w', nodes: ['n']}),
graph = iD.coreGraph([node, w1]);
expect(graph.remove(w1).parentWays(node)).to.eql([]);
});
it('doesn\'t add duplicate parentWays', function () {
var node = iD.Node({id: 'n' }),
w1 = iD.Way({id: 'w', nodes: ['n']}),
graph = iD.Graph([node, w1]);
var node = iD.osmNode({id: 'n' }),
w1 = iD.osmWay({id: 'w', nodes: ['n']}),
graph = iD.coreGraph([node, w1]);
expect(graph.replace(w1).parentWays(node)).to.eql([w1]);
});
it('adds parentRelations', function () {
var node = iD.Node({id: 'n' }),
r1 = iD.Relation({id: 'r', members: [{id: 'n'}]}),
graph = iD.Graph([node]);
var node = iD.osmNode({id: 'n' }),
r1 = iD.osmRelation({id: 'r', members: [{id: 'n'}]}),
graph = iD.coreGraph([node]);
expect(graph.replace(r1).parentRelations(node)).to.eql([r1]);
});
it('removes parentRelations', function () {
var node = iD.Node({id: 'n' }),
r1 = iD.Relation({id: 'r', members: [{id: 'n'}]}),
graph = iD.Graph([node, r1]);
var node = iD.osmNode({id: 'n' }),
r1 = iD.osmRelation({id: 'r', members: [{id: 'n'}]}),
graph = iD.coreGraph([node, r1]);
expect(graph.remove(r1).parentRelations(node)).to.eql([]);
});
it('doesn\'t add duplicate parentRelations', function () {
var node = iD.Node({id: 'n' }),
r1 = iD.Relation({id: 'r', members: [{id: 'n'}]}),
graph = iD.Graph([node, r1]);
var node = iD.osmNode({id: 'n' }),
r1 = iD.osmRelation({id: 'r', members: [{id: 'n'}]}),
graph = iD.coreGraph([node, r1]);
expect(graph.replace(r1).parentRelations(node)).to.eql([r1]);
});
});
describe('#revert', function () {
it('is a no-op if the head entity is identical to the base entity', function () {
var n1 = iD.Node({id: 'n'}),
graph = iD.Graph([n1]);
var n1 = iD.osmNode({id: 'n'}),
graph = iD.coreGraph([n1]);
expect(graph.revert('n')).to.equal(graph);
});
it('returns a new graph', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.update({}),
graph = iD.Graph([n1]).replace(n2);
graph = iD.coreGraph([n1]).replace(n2);
expect(graph.revert('n')).not.to.equal(graph);
});
it('doesn\'t modify the receiver', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.update({}),
graph = iD.Graph([n1]).replace(n2);
graph = iD.coreGraph([n1]).replace(n2);
graph.revert('n');
expect(graph.hasEntity('n')).to.equal(n2);
});
it('removes a new entity', function () {
var n1 = iD.Node({id: 'n'}),
graph = iD.Graph().replace(n1);
var n1 = iD.osmNode({id: 'n'}),
graph = iD.coreGraph().replace(n1);
graph = graph.revert('n');
expect(graph.hasEntity('n')).to.be.undefined;
});
it('reverts an updated entity to the base version', function () {
var n1 = iD.Node({id: 'n'}),
var n1 = iD.osmNode({id: 'n'}),
n2 = n1.update({}),
graph = iD.Graph([n1]).replace(n2);
graph = iD.coreGraph([n1]).replace(n2);
graph = graph.revert('n');
expect(graph.hasEntity('n')).to.equal(n1);
});
it('restores a deleted entity', function () {
var n1 = iD.Node({id: 'n'}),
graph = iD.Graph([n1]).remove(n1);
var n1 = iD.osmNode({id: 'n'}),
graph = iD.coreGraph([n1]).remove(n1);
graph = graph.revert('n');
expect(graph.hasEntity('n')).to.equal(n1);
});
it('removes new parentWays', function () {
var n1 = iD.Node({id: 'n'}),
w1 = iD.Way({id: 'w', nodes: ['n']}),
graph = iD.Graph().replace(n1).replace(w1);
var n1 = iD.osmNode({id: 'n'}),
w1 = iD.osmWay({id: 'w', nodes: ['n']}),
graph = iD.coreGraph().replace(n1).replace(w1);
graph = graph.revert('w');
expect(graph.hasEntity('n')).to.equal(n1);
@@ -414,9 +414,9 @@ describe('iD.Graph', function() {
});
it('removes new parentRelations', function () {
var n1 = iD.Node({id: 'n'}),
r1 = iD.Relation({id: 'r', members: [{id: 'n'}]}),
graph = iD.Graph().replace(n1).replace(r1);
var n1 = iD.osmNode({id: 'n'}),
r1 = iD.osmRelation({id: 'r', members: [{id: 'n'}]}),
graph = iD.coreGraph().replace(n1).replace(r1);
graph = graph.revert('r');
expect(graph.hasEntity('n')).to.equal(n1);
@@ -424,10 +424,10 @@ describe('iD.Graph', function() {
});
it('reverts updated parentWays', function () {
var n1 = iD.Node({id: 'n'}),
w1 = iD.Way({id: 'w', nodes: ['n']}),
var n1 = iD.osmNode({id: 'n'}),
w1 = iD.osmWay({id: 'w', nodes: ['n']}),
w2 = w1.removeNode('n'),
graph = iD.Graph([n1, w1]).replace(w2);
graph = iD.coreGraph([n1, w1]).replace(w2);
graph = graph.revert('w');
expect(graph.hasEntity('n')).to.equal(n1);
@@ -435,10 +435,10 @@ describe('iD.Graph', function() {
});
it('reverts updated parentRelations', function () {
var n1 = iD.Node({id: 'n'}),
r1 = iD.Relation({id: 'r', members: [{id: 'n'}]}),
var n1 = iD.osmNode({id: 'n'}),
r1 = iD.osmRelation({id: 'r', members: [{id: 'n'}]}),
r2 = r1.removeMembersWithID('n'),
graph = iD.Graph([n1, r1]).replace(r2);
graph = iD.coreGraph([n1, r1]).replace(r2);
graph = graph.revert('r');
expect(graph.hasEntity('n')).to.equal(n1);
@@ -446,9 +446,9 @@ describe('iD.Graph', function() {
});
it('restores deleted parentWays', function () {
var n1 = iD.Node({id: 'n'}),
w1 = iD.Way({id: 'w', nodes: ['n']}),
graph = iD.Graph([n1, w1]).remove(w1);
var n1 = iD.osmNode({id: 'n'}),
w1 = iD.osmWay({id: 'w', nodes: ['n']}),
graph = iD.coreGraph([n1, w1]).remove(w1);
graph = graph.revert('w');
expect(graph.hasEntity('n')).to.equal(n1);
@@ -456,9 +456,9 @@ describe('iD.Graph', function() {
});
it('restores deleted parentRelations', function () {
var n1 = iD.Node({id: 'n'}),
r1 = iD.Relation({id: 'r', members: [{id: 'n'}]}),
graph = iD.Graph([n1, r1]).remove(r1);
var n1 = iD.osmNode({id: 'n'}),
r1 = iD.osmRelation({id: 'r', members: [{id: 'n'}]}),
graph = iD.coreGraph([n1, r1]).remove(r1);
graph = graph.revert('r');
expect(graph.hasEntity('n')).to.equal(n1);
@@ -468,18 +468,18 @@ describe('iD.Graph', function() {
describe('#update', function () {
it('returns a new graph if self is frozen', function () {
var graph = iD.Graph();
var graph = iD.coreGraph();
expect(graph.update()).not.to.equal(graph);
});
it('returns self if self is not frozen', function () {
var graph = iD.Graph([], true);
var graph = iD.coreGraph([], true);
expect(graph.update()).to.equal(graph);
});
it('doesn\'t modify self is self is frozen', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
graph.update(function (graph) { graph.remove(node); });
@@ -487,8 +487,8 @@ describe('iD.Graph', function() {
});
it('modifies self is self is not frozen', function () {
var node = iD.Node(),
graph = iD.Graph([node], true);
var node = iD.osmNode(),
graph = iD.coreGraph([node], true);
graph.update(function (graph) { graph.remove(node); });
@@ -496,9 +496,9 @@ describe('iD.Graph', function() {
});
it('executes all of the given functions', function () {
var a = iD.Node(),
b = iD.Node(),
graph = iD.Graph([a]);
var a = iD.osmNode(),
b = iD.osmNode(),
graph = iD.coreGraph([a]);
graph = graph.update(
function (graph) { graph.remove(a); },
@@ -512,9 +512,9 @@ describe('iD.Graph', function() {
describe('#parentWays', function() {
it('returns an array of ways that contain the given node id', function () {
var node = iD.Node({id: 'n1'}),
way = iD.Way({id: 'w1', nodes: ['n1']}),
graph = iD.Graph([node, way]);
var node = iD.osmNode({id: 'n1'}),
way = iD.osmWay({id: 'w1', nodes: ['n1']}),
graph = iD.coreGraph([node, way]);
expect(graph.parentWays(node)).to.eql([way]);
expect(graph.parentWays(way)).to.eql([]);
});
@@ -522,10 +522,10 @@ describe('iD.Graph', function() {
describe('#parentRelations', function() {
it('returns an array of relations that contain the given entity id', function () {
var node = iD.Node({id: 'n1'}),
nonnode = iD.Node({id: 'n2'}),
relation = iD.Relation({id: 'r1', members: [{ id: 'n1', role: 'from' }]}),
graph = iD.Graph([node, relation]);
var node = iD.osmNode({id: 'n1'}),
nonnode = iD.osmNode({id: 'n2'}),
relation = iD.osmRelation({id: 'r1', members: [{ id: 'n1', role: 'from' }]}),
graph = iD.coreGraph([node, relation]);
expect(graph.parentRelations(node)).to.eql([relation]);
expect(graph.parentRelations(nonnode)).to.eql([]);
});
@@ -533,9 +533,9 @@ describe('iD.Graph', function() {
describe('#childNodes', function () {
it('returns an array of child nodes', function () {
var node = iD.Node({id: 'n1'}),
way = iD.Way({id: 'w1', nodes: ['n1']}),
graph = iD.Graph([node, way]);
var node = iD.osmNode({id: 'n1'}),
way = iD.osmWay({id: 'w1', nodes: ['n1']}),
graph = iD.coreGraph([node, way]);
expect(graph.childNodes(way)).to.eql([node]);
});
});
+32 -32
View File
@@ -1,9 +1,9 @@
describe('iD.History', function () {
var context, history, spy,
action = function() { return iD.Graph(); };
action = function() { return iD.coreGraph(); };
beforeEach(function () {
context = iD.Context();
context = iD.coreContext();
history = context.history();
spy = sinon.spy();
// clear lock
@@ -12,13 +12,13 @@ describe('iD.History', function () {
describe('#graph', function () {
it('returns the current graph', function () {
expect(history.graph()).to.be.an.instanceOf(iD.Graph);
expect(history.graph()).to.be.an.instanceOf(iD.coreGraph);
});
});
describe('#merge', function () {
it('merges the entities into all graph versions', function () {
var n = iD.Node({id: 'n'});
var n = iD.osmNode({id: 'n'});
history.merge([n]);
expect(history.graph().entity('n')).to.equal(n);
});
@@ -37,7 +37,7 @@ describe('iD.History', function () {
});
it('updates the graph', function () {
var node = iD.Node();
var node = iD.osmNode();
history.perform(function (graph) { return graph.replace(node); });
expect(history.graph().entity(node.id)).to.equal(node);
});
@@ -55,8 +55,8 @@ describe('iD.History', function () {
});
it('performs multiple actions', function () {
var action1 = sinon.stub().returns(iD.Graph()),
action2 = sinon.stub().returns(iD.Graph());
var action1 = sinon.stub().returns(iD.coreGraph()),
action2 = sinon.stub().returns(iD.coreGraph());
history.perform(action1, action2, 'annotation');
expect(action1).to.have.been.called;
expect(action2).to.have.been.called;
@@ -64,7 +64,7 @@ describe('iD.History', function () {
});
it('performs transitionable actions in a transition', function (done) {
var action1 = function() { return iD.Graph(); };
var action1 = function() { return iD.coreGraph(); };
action1.transitionable = true;
history.on('change', spy);
history.perform(action1);
@@ -81,7 +81,7 @@ describe('iD.History', function () {
});
it('updates the graph', function () {
var node = iD.Node();
var node = iD.osmNode();
history.replace(function (graph) { return graph.replace(node); });
expect(history.graph().entity(node.id)).to.equal(node);
});
@@ -99,8 +99,8 @@ describe('iD.History', function () {
});
it('performs multiple actions', function () {
var action1 = sinon.stub().returns(iD.Graph()),
action2 = sinon.stub().returns(iD.Graph());
var action1 = sinon.stub().returns(iD.coreGraph()),
action2 = sinon.stub().returns(iD.coreGraph());
history.replace(action1, action2, 'annotation');
expect(action1).to.have.been.called;
expect(action2).to.have.been.called;
@@ -168,7 +168,7 @@ describe('iD.History', function () {
it('updates the graph', function () {
history.perform(action, 'annotation');
var node = iD.Node();
var node = iD.osmNode();
history.overwrite(function (graph) { return graph.replace(node); });
expect(history.graph().entity(node.id)).to.equal(node);
});
@@ -193,8 +193,8 @@ describe('iD.History', function () {
});
it('performs multiple actions', function () {
var action1 = sinon.stub().returns(iD.Graph()),
action2 = sinon.stub().returns(iD.Graph());
var action1 = sinon.stub().returns(iD.coreGraph()),
action2 = sinon.stub().returns(iD.coreGraph());
history.perform(action, 'annotation');
history.overwrite(action1, action2, 'annotation2');
expect(action1).to.have.been.called;
@@ -268,13 +268,13 @@ describe('iD.History', function () {
describe('#changes', function () {
it('includes created entities', function () {
var node = iD.Node();
var node = iD.osmNode();
history.perform(function (graph) { return graph.replace(node); });
expect(history.changes().created).to.eql([node]);
});
it('includes modified entities', function () {
var node1 = iD.Node({id: 'n1'}),
var node1 = iD.osmNode({id: 'n1'}),
node2 = node1.update({ tags: { yes: 'no' } });
history.merge([node1]);
history.perform(function (graph) { return graph.replace(node2); });
@@ -282,7 +282,7 @@ describe('iD.History', function () {
});
it('includes deleted entities', function () {
var node = iD.Node({id: 'n1'});
var node = iD.osmNode({id: 'n1'});
history.merge([node]);
history.perform(function (graph) { return graph.remove(node); });
expect(history.changes().deleted).to.eql([node]);
@@ -291,7 +291,7 @@ describe('iD.History', function () {
describe('#hasChanges', function() {
it('is true when any of change\'s values are nonempty', function() {
var node = iD.Node();
var node = iD.osmNode();
history.perform(function (graph) { return graph.replace(node); });
expect(history.hasChanges()).to.eql(true);
});
@@ -350,17 +350,17 @@ describe('iD.History', function () {
describe('#toJSON', function() {
it('doesn\'t generate unsaveable changes', function() {
var node_1 = iD.Node({id: 'n-1'});
var node_1 = iD.osmNode({id: 'n-1'});
history.perform(iD.actionAddEntity(node_1));
history.perform(iD.actionDeleteNode('n-1'));
expect(history.toJSON()).to.be.not.ok;
});
it('generates v3 JSON', function() {
var node_1 = iD.Node({id: 'n-1'}),
node1 = iD.Node({id: 'n1'}),
node2 = iD.Node({id: 'n2'}),
node3 = iD.Node({id: 'n3'});
var node_1 = iD.osmNode({id: 'n-1'}),
node1 = iD.osmNode({id: 'n1'}),
node2 = iD.osmNode({id: 'n2'}),
node3 = iD.osmNode({id: 'n3'});
history.merge([node1, node2, node3]);
history.perform(iD.actionAddEntity(node_1)); // addition
history.perform(iD.actionChangeTags('n2', {k: 'v'})); // modification
@@ -397,7 +397,7 @@ describe('iD.History', function () {
'index': 1
};
history.fromJSON(JSON.stringify(json));
expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [1, 2]}));
expect(history.graph().entity('n-1')).to.eql(iD.osmNode({id: 'n-1', loc: [1, 2]}));
expect(history.undoAnnotation()).to.eql('Added a point.');
expect(history.imageryUsed()).to.eql(['Bing']);
expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1});
@@ -414,7 +414,7 @@ describe('iD.History', function () {
'index': 2
};
history.fromJSON(JSON.stringify(json));
expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [2, 3], v: 1}));
expect(history.graph().entity('n-1')).to.eql(iD.osmNode({id: 'n-1', loc: [2, 3], v: 1}));
expect(history.undoAnnotation()).to.eql('Moved a point.');
expect(history.imageryUsed()).to.eql(['Bing']);
expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1});
@@ -430,7 +430,7 @@ describe('iD.History', function () {
'index': 1
};
history.fromJSON(JSON.stringify(json));
history.merge([iD.Node({id: 'n1'})]);
history.merge([iD.osmNode({id: 'n1'})]);
expect(history.graph().hasEntity('n1')).to.be.undefined;
expect(history.undoAnnotation()).to.eql('Deleted a point.');
expect(history.imageryUsed()).to.eql(['Bing']);
@@ -451,7 +451,7 @@ describe('iD.History', function () {
'index': 1
};
history.fromJSON(JSON.stringify(json));
expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [1, 2]}));
expect(history.graph().entity('n-1')).to.eql(iD.osmNode({id: 'n-1', loc: [1, 2]}));
expect(history.undoAnnotation()).to.eql('Added a point.');
expect(history.imageryUsed()).to.eql(['Bing']);
expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1});
@@ -472,8 +472,8 @@ describe('iD.History', function () {
'index': 1
};
history.fromJSON(JSON.stringify(json));
history.merge([iD.Node({id: 'n1'})]); // Shouldn't be necessary; flaw in v2 format (see #2135)
expect(history.graph().entity('n1')).to.eql(iD.Node({id: 'n1', loc: [2, 3], v: 1}));
history.merge([iD.osmNode({id: 'n1'})]); // Shouldn't be necessary; flaw in v2 format (see #2135)
expect(history.graph().entity('n1')).to.eql(iD.osmNode({id: 'n1', loc: [2, 3], v: 1}));
expect(history.undoAnnotation()).to.eql('Moved a point.');
expect(history.imageryUsed()).to.eql(['Bing']);
expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1});
@@ -492,7 +492,7 @@ describe('iD.History', function () {
'index': 1
};
history.fromJSON(JSON.stringify(json));
history.merge([iD.Node({id: 'n1'})]); // Shouldn't be necessary; flaw in v2 format (see #2135)
history.merge([iD.osmNode({id: 'n1'})]); // Shouldn't be necessary; flaw in v2 format (see #2135)
expect(history.graph().hasEntity('n1')).to.be.undefined;
expect(history.undoAnnotation()).to.eql('Deleted a point.');
expect(history.imageryUsed()).to.eql(['Bing']);
@@ -515,7 +515,7 @@ describe('iD.History', function () {
'index': 1
};
history.fromJSON(JSON.stringify(json));
expect(history.graph().entity('n-1')).to.eql(iD.Node({id: 'n-1', loc: [1, 2]}));
expect(history.graph().entity('n-1')).to.eql(iD.osmNode({id: 'n-1', loc: [1, 2]}));
expect(history.undoAnnotation()).to.eql('Added a point.');
expect(history.imageryUsed()).to.eql(['Bing']);
expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1});
@@ -537,7 +537,7 @@ describe('iD.History', function () {
'index': 1
};
history.fromJSON(JSON.stringify(json));
expect(history.graph().entity('n1')).to.eql(iD.Node({id: 'n1', loc: [2, 3], v: 1}));
expect(history.graph().entity('n1')).to.eql(iD.osmNode({id: 'n1', loc: [2, 3], v: 1}));
expect(history.undoAnnotation()).to.eql('Moved a point.');
expect(history.imageryUsed()).to.eql(['Bing']);
expect(iD.Entity.id.next).to.eql({node: -2, way: -1, relation: -1});
+47 -47
View File
@@ -1,9 +1,9 @@
describe('iD.Tree', function() {
describe('#rebase', function() {
it('adds entities to the tree', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
node = iD.Node({id: 'n', loc: [1, 1]});
node = iD.osmNode({id: 'n', loc: [1, 1]});
graph.rebase([node], [graph]);
tree.rebase([node]);
@@ -12,9 +12,9 @@ describe('iD.Tree', function() {
});
it('is idempotent', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
node = iD.Node({id: 'n', loc: [1, 1]}),
node = iD.osmNode({id: 'n', loc: [1, 1]}),
extent = iD.geoExtent([0, 0], [2, 2]);
graph.rebase([node], [graph]);
@@ -27,9 +27,9 @@ describe('iD.Tree', function() {
});
it('does not insert if entity has a modified version', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
node = iD.Node({id: 'n', loc: [1, 1]}),
node = iD.osmNode({id: 'n', loc: [1, 1]}),
node_ = node.update({loc: [10, 10]}),
g = graph.replace(node_);
@@ -43,10 +43,10 @@ describe('iD.Tree', function() {
});
it('does not error on self-referencing relations', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
node = iD.Node({id: 'n', loc: [1, 1]}),
relation = iD.Relation();
node = iD.osmNode({id: 'n', loc: [1, 1]}),
relation = iD.osmRelation();
relation = relation.addMember({id: node.id});
relation = relation.addMember({id: relation.id});
@@ -58,9 +58,9 @@ describe('iD.Tree', function() {
});
it('adjusts entities that are force-rebased', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
node = iD.Node({id: 'n', loc: [1, 1]});
node = iD.osmNode({id: 'n', loc: [1, 1]});
graph.rebase([node], [graph]);
tree.rebase([node]);
@@ -75,10 +75,10 @@ describe('iD.Tree', function() {
describe('#intersects', function() {
it('includes entities within extent, excludes those without', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
n1 = iD.Node({loc: [1, 1]}),
n2 = iD.Node({loc: [3, 3]}),
n1 = iD.osmNode({loc: [1, 1]}),
n2 = iD.osmNode({loc: [3, 3]}),
extent = iD.geoExtent([0, 0], [2, 2]);
graph = graph.replace(n1).replace(n2);
@@ -86,11 +86,11 @@ describe('iD.Tree', function() {
});
it('includes intersecting relations after incomplete members are loaded', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
n1 = iD.Node({id: 'n1', loc: [0, 0]}),
n2 = iD.Node({id: 'n2', loc: [1, 1]}),
relation = iD.Relation({id: 'r', members: [{id: 'n1'}, {id: 'n2'}]}),
n1 = iD.osmNode({id: 'n1', loc: [0, 0]}),
n2 = iD.osmNode({id: 'n2', loc: [1, 1]}),
relation = iD.osmRelation({id: 'r', members: [{id: 'n1'}, {id: 'n2'}]}),
extent = iD.geoExtent([0.5, 0.5], [1.5, 1.5]);
graph.rebase([relation, n1], [graph]);
@@ -104,10 +104,10 @@ describe('iD.Tree', function() {
// This happens when local storage includes a changed way but not its nodes.
it('includes intersecting ways after missing nodes are loaded', function() {
var base = iD.Graph(),
var base = iD.coreGraph(),
tree = iD.Tree(base),
node = iD.Node({id: 'n', loc: [0.5, 0.5]}),
way = iD.Way({nodes: ['n']}),
node = iD.osmNode({id: 'n', loc: [0.5, 0.5]}),
way = iD.osmWay({nodes: ['n']}),
graph = base.replace(way),
extent = iD.geoExtent([0, 0], [1, 1]);
@@ -119,10 +119,10 @@ describe('iD.Tree', function() {
});
it('adjusts parent ways when a member node is moved', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
node = iD.Node({id: 'n', loc: [1, 1]}),
way = iD.Way({nodes: ['n']}),
node = iD.osmNode({id: 'n', loc: [1, 1]}),
way = iD.osmWay({nodes: ['n']}),
extent = iD.geoExtent([0, 0], [2, 2]);
graph = graph.replace(node).replace(way);
@@ -133,10 +133,10 @@ describe('iD.Tree', function() {
});
it('adjusts parent relations when a member node is moved', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
node = iD.Node({id: 'n', loc: [1, 1]}),
relation = iD.Relation({members: [{type: 'node', id: 'n'}]}),
node = iD.osmNode({id: 'n', loc: [1, 1]}),
relation = iD.osmRelation({members: [{type: 'node', id: 'n'}]}),
extent = iD.geoExtent([0, 0], [2, 2]);
graph = graph.replace(node).replace(relation);
@@ -147,11 +147,11 @@ describe('iD.Tree', function() {
});
it('adjusts parent relations of parent ways when a member node is moved', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
node = iD.Node({id: 'n', loc: [1, 1]}),
way = iD.Way({id: 'w', nodes: ['n']}),
relation = iD.Relation({members: [{type: 'multipolygon', id: 'w'}]}),
node = iD.osmNode({id: 'n', loc: [1, 1]}),
way = iD.osmWay({id: 'w', nodes: ['n']}),
relation = iD.osmRelation({members: [{type: 'multipolygon', id: 'w'}]}),
extent = iD.geoExtent([0, 0], [2, 2]);
graph = graph.replace(node).replace(way).replace(relation);
@@ -162,11 +162,11 @@ describe('iD.Tree', function() {
});
it('adjusts parent ways when a member node is removed', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
n1 = iD.Node({id: 'n1', loc: [1, 1]}),
n2 = iD.Node({id: 'n2', loc: [3, 3]}),
way = iD.Way({nodes: ['n1', 'n2']}),
n1 = iD.osmNode({id: 'n1', loc: [1, 1]}),
n2 = iD.osmNode({id: 'n2', loc: [3, 3]}),
way = iD.osmWay({nodes: ['n1', 'n2']}),
extent = iD.geoExtent([0, 0], [2, 2]);
graph = graph.replace(n1).replace(n2).replace(way);
@@ -178,11 +178,11 @@ describe('iD.Tree', function() {
it('don\'t include parent way multiple times when multiple child nodes are moved', function() {
// checks against the following regression: https://github.com/openstreetmap/iD/issues/1978
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
n1 = iD.Node({id: 'n1', loc: [1, 1]}),
n2 = iD.Node({id: 'n2', loc: [3, 3]}),
way = iD.Way({id: 'w1', nodes: ['n1', 'n2']}),
n1 = iD.osmNode({id: 'n1', loc: [1, 1]}),
n2 = iD.osmNode({id: 'n2', loc: [3, 3]}),
way = iD.osmWay({id: 'w1', nodes: ['n1', 'n2']}),
extent = iD.geoExtent([0, 0], [4, 4]);
graph = graph.replace(n1).replace(n2).replace(way);
@@ -194,9 +194,9 @@ describe('iD.Tree', function() {
});
it('doesn\'t include removed entities', function() {
var graph = iD.Graph(),
var graph = iD.coreGraph(),
tree = iD.Tree(graph),
node = iD.Node({loc: [1, 1]}),
node = iD.osmNode({loc: [1, 1]}),
extent = iD.geoExtent([0, 0], [2, 2]);
graph = graph.replace(node);
@@ -207,9 +207,9 @@ describe('iD.Tree', function() {
});
it('doesn\'t include removed entities after rebase', function() {
var base = iD.Graph(),
var base = iD.coreGraph(),
tree = iD.Tree(base),
node = iD.Node({id: 'n', loc: [1, 1]}),
node = iD.osmNode({id: 'n', loc: [1, 1]}),
extent = iD.geoExtent([0, 0], [2, 2]);
var graph = base.replace(node).remove(node);
@@ -221,11 +221,11 @@ describe('iD.Tree', function() {
});
it('handles recursive relations', function() {
var base = iD.Graph(),
var base = iD.coreGraph(),
tree = iD.Tree(base),
node = iD.Node({id: 'n', loc: [1, 1]}),
r1 = iD.Relation({id: 'r1', members: [{id: 'n'}]}),
r2 = iD.Relation({id: 'r2', members: [{id: 'r1'}]}),
node = iD.osmNode({id: 'n', loc: [1, 1]}),
r1 = iD.osmRelation({id: 'r1', members: [{id: 'n'}]}),
r2 = iD.osmRelation({id: 'r2', members: [{id: 'r1'}]}),
extent = iD.geoExtent([0, 0], [2, 2]);
var graph = base.replace(r1).replace(r2);
+1 -1
View File
@@ -4,7 +4,7 @@ describe.skip('iD.modeAddPoint', function() {
beforeEach(function() {
var container = d3.select(document.createElement('div'));
context = iD.Context()
context = iD.coreContext()
.container(container);
context.loadTiles = function () {};
+20 -20
View File
@@ -1,11 +1,11 @@
describe('iD.osmEntity', function () {
it('returns a subclass of the appropriate type', function () {
expect(iD.Entity({type: 'node'})).be.an.instanceOf(iD.Node);
expect(iD.Entity({type: 'way'})).be.an.instanceOf(iD.Way);
expect(iD.Entity({type: 'relation'})).be.an.instanceOf(iD.Relation);
expect(iD.Entity({id: 'n1'})).be.an.instanceOf(iD.Node);
expect(iD.Entity({id: 'w1'})).be.an.instanceOf(iD.Way);
expect(iD.Entity({id: 'r1'})).be.an.instanceOf(iD.Relation);
expect(iD.Entity({type: 'node'})).be.an.instanceOf(iD.osmNode);
expect(iD.Entity({type: 'way'})).be.an.instanceOf(iD.osmWay);
expect(iD.Entity({type: 'relation'})).be.an.instanceOf(iD.osmRelation);
expect(iD.Entity({id: 'n1'})).be.an.instanceOf(iD.osmNode);
expect(iD.Entity({id: 'w1'})).be.an.instanceOf(iD.osmWay);
expect(iD.Entity({id: 'r1'})).be.an.instanceOf(iD.osmRelation);
});
if (iD.debug) {
@@ -175,48 +175,48 @@ describe('iD.osmEntity', function () {
describe('#intersects', function () {
it('returns true for a way with a node within the given extent', function () {
var node = iD.Node({loc: [0, 0]}),
way = iD.Way({nodes: [node.id]}),
graph = iD.Graph([node, way]);
var node = iD.osmNode({loc: [0, 0]}),
way = iD.osmWay({nodes: [node.id]}),
graph = iD.coreGraph([node, way]);
expect(way.intersects([[-5, -5], [5, 5]], graph)).to.equal(true);
});
it('returns false for way with no nodes within the given extent', function () {
var node = iD.Node({loc: [6, 6]}),
way = iD.Way({nodes: [node.id]}),
graph = iD.Graph([node, way]);
var node = iD.osmNode({loc: [6, 6]}),
way = iD.osmWay({nodes: [node.id]}),
graph = iD.coreGraph([node, way]);
expect(way.intersects([[-5, -5], [5, 5]], graph)).to.equal(false);
});
});
describe('#hasNonGeometryTags', function () {
it('returns false for an entity without tags', function () {
var node = iD.Node();
var node = iD.osmNode();
expect(node.hasNonGeometryTags()).to.equal(false);
});
it('returns true for an entity with tags', function () {
var node = iD.Node({tags: {foo: 'bar'}});
var node = iD.osmNode({tags: {foo: 'bar'}});
expect(node.hasNonGeometryTags()).to.equal(true);
});
it('returns false for an entity with only an area=yes tag', function () {
var node = iD.Node({tags: {area: 'yes'}});
var node = iD.osmNode({tags: {area: 'yes'}});
expect(node.hasNonGeometryTags()).to.equal(false);
});
});
describe('#hasParentRelations', function () {
it('returns true for an entity that is a relation member', function () {
var node = iD.Node(),
relation = iD.Relation({members: [{id: node.id}]}),
graph = iD.Graph([node, relation]);
var node = iD.osmNode(),
relation = iD.osmRelation({members: [{id: node.id}]}),
graph = iD.coreGraph([node, relation]);
expect(node.hasParentRelations(graph)).to.equal(true);
});
it('returns false for an entity that is not a relation member', function () {
var node = iD.Node(),
graph = iD.Graph([node]);
var node = iD.osmNode(),
graph = iD.coreGraph([node]);
expect(node.hasParentRelations(graph)).to.equal(false);
});
});
+112 -112
View File
@@ -5,26 +5,26 @@ describe('iD.Lanes', function() {
describe('motorway', function() {
it('returns 2 lanes for highway=motorway', function() {
expect(iD.Way({tags: { highway: 'motorway' }}).lanes().metadata.count, 'motorway lanes')
expect(iD.osmWay({tags: { highway: 'motorway' }}).lanes().metadata.count, 'motorway lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'motorway', oneway: 'yes' }}).lanes().metadata.count, 'motorway lanes')
expect(iD.osmWay({tags: { highway: 'motorway', oneway: 'yes' }}).lanes().metadata.count, 'motorway lanes')
.to.eql(2);
});
it('returns 4 lanes for highway=motorway and oneway=no', function() {
expect(iD.Way({tags: { highway: 'motorway', oneway: 'no' }}).lanes().metadata.count, 'motorway lanes')
expect(iD.osmWay({tags: { highway: 'motorway', oneway: 'no' }}).lanes().metadata.count, 'motorway lanes')
.to.eql(4);
});
it('returns 2 lanes for highway=motorway_link', function() {
expect(iD.Way({tags: { highway: 'motorway_link' }}).lanes().metadata.count, 'motorway_link lanes')
expect(iD.osmWay({tags: { highway: 'motorway_link' }}).lanes().metadata.count, 'motorway_link lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'motorway_link', oneway: 'no' }}).lanes().metadata.count, 'motorway_link lanes')
expect(iD.osmWay({tags: { highway: 'motorway_link', oneway: 'no' }}).lanes().metadata.count, 'motorway_link lanes')
.to.eql(2);
});
it('returns 1 lane for highway=motorway_link and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'motorway_link', oneway: 'yes' }}).lanes().metadata.count, 'motorway_link lanes')
expect(iD.osmWay({tags: { highway: 'motorway_link', oneway: 'yes' }}).lanes().metadata.count, 'motorway_link lanes')
.to.eql(1);
});
});
@@ -32,26 +32,26 @@ describe('iD.Lanes', function() {
describe('trunk', function() {
it('returns 4 lanes for highway=trunk', function() {
expect(iD.Way({tags: { highway: 'trunk' }}).lanes().metadata.count, 'trunk lanes')
expect(iD.osmWay({tags: { highway: 'trunk' }}).lanes().metadata.count, 'trunk lanes')
.to.eql(4);
expect(iD.Way({tags: { highway: 'trunk', oneway: 'no' }}).lanes().metadata.count, 'trunk lanes')
expect(iD.osmWay({tags: { highway: 'trunk', oneway: 'no' }}).lanes().metadata.count, 'trunk lanes')
.to.eql(4);
});
it('returns 2 lanes for highway=trunk and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'trunk', oneway: 'yes' }}).lanes().metadata.count, 'trunk lanes')
expect(iD.osmWay({tags: { highway: 'trunk', oneway: 'yes' }}).lanes().metadata.count, 'trunk lanes')
.to.eql(2);
});
it('returns 2 lanes for highway=trunk_link', function() {
expect(iD.Way({tags: { highway: 'trunk_link' }}).lanes().metadata.count, 'trunk_link lanes')
expect(iD.osmWay({tags: { highway: 'trunk_link' }}).lanes().metadata.count, 'trunk_link lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'trunk_link', oneway: 'no' }}).lanes().metadata.count, 'trunk_link lanes')
expect(iD.osmWay({tags: { highway: 'trunk_link', oneway: 'no' }}).lanes().metadata.count, 'trunk_link lanes')
.to.eql(2);
});
it('returns 1 lane for highway=trunk_link and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'trunk_link', oneway: 'yes' }}).lanes().metadata.count, 'trunk_link lanes')
expect(iD.osmWay({tags: { highway: 'trunk_link', oneway: 'yes' }}).lanes().metadata.count, 'trunk_link lanes')
.to.eql(1);
});
});
@@ -59,26 +59,26 @@ describe('iD.Lanes', function() {
describe('primary', function() {
it('returns 2 lanes for highway=primary', function() {
expect(iD.Way({tags: { highway: 'primary' }}).lanes().metadata.count, 'primary lanes')
expect(iD.osmWay({tags: { highway: 'primary' }}).lanes().metadata.count, 'primary lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'primary', oneway: 'no' }}).lanes().metadata.count, 'primary lanes')
expect(iD.osmWay({tags: { highway: 'primary', oneway: 'no' }}).lanes().metadata.count, 'primary lanes')
.to.eql(2);
});
it('returns 1 lane for highway=primary and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'primary', oneway: 'yes' }}).lanes().metadata.count, 'primary lanes')
expect(iD.osmWay({tags: { highway: 'primary', oneway: 'yes' }}).lanes().metadata.count, 'primary lanes')
.to.eql(1);
});
it('returns 2 lanes for highway=primary_link', function() {
expect(iD.Way({tags: { highway: 'primary_link' }}).lanes().metadata.count, 'primary lanes')
expect(iD.osmWay({tags: { highway: 'primary_link' }}).lanes().metadata.count, 'primary lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'primary_link', oneway: 'no' }}).lanes().metadata.count, 'primary lanes')
expect(iD.osmWay({tags: { highway: 'primary_link', oneway: 'no' }}).lanes().metadata.count, 'primary lanes')
.to.eql(2);
});
it('returns 1 lane for highway=primary_link and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'primary_link', oneway: 'yes' }}).lanes().metadata.count, 'primary lanes')
expect(iD.osmWay({tags: { highway: 'primary_link', oneway: 'yes' }}).lanes().metadata.count, 'primary lanes')
.to.eql(1);
});
});
@@ -86,26 +86,26 @@ describe('iD.Lanes', function() {
describe('seconday', function() {
it('returns 2 lanes for highway=secondary', function() {
expect(iD.Way({tags: { highway: 'secondary' }}).lanes().metadata.count, 'secondary lanes')
expect(iD.osmWay({tags: { highway: 'secondary' }}).lanes().metadata.count, 'secondary lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'secondary', oneway: 'no' }}).lanes().metadata.count, 'secondary lanes')
expect(iD.osmWay({tags: { highway: 'secondary', oneway: 'no' }}).lanes().metadata.count, 'secondary lanes')
.to.eql(2);
});
it('returns 1 lane for highway=secondary and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'secondary', oneway: 'yes' }}).lanes().metadata.count, 'secondary lanes')
expect(iD.osmWay({tags: { highway: 'secondary', oneway: 'yes' }}).lanes().metadata.count, 'secondary lanes')
.to.eql(1);
});
it('returns 2 lane for highway=secondary_link', function() {
expect(iD.Way({tags: { highway: 'secondary_link' }}).lanes().metadata.count, 'secondary_link lanes')
expect(iD.osmWay({tags: { highway: 'secondary_link' }}).lanes().metadata.count, 'secondary_link lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'secondary_link', oneway: 'no' }}).lanes().metadata.count, 'secondary_link lanes')
expect(iD.osmWay({tags: { highway: 'secondary_link', oneway: 'no' }}).lanes().metadata.count, 'secondary_link lanes')
.to.eql(2);
});
it('returns 1 lane for highway=secondary_link and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'secondary_link', oneway: 'yes' }}).lanes().metadata.count, 'secondary_link lanes')
expect(iD.osmWay({tags: { highway: 'secondary_link', oneway: 'yes' }}).lanes().metadata.count, 'secondary_link lanes')
.to.eql(1);
});
});
@@ -113,26 +113,26 @@ describe('iD.Lanes', function() {
describe('tertiary', function() {
it('returns 2 lanes for highway=tertiary', function() {
expect(iD.Way({tags: { highway: 'tertiary' }}).lanes().metadata.count, 'tertiary lanes')
expect(iD.osmWay({tags: { highway: 'tertiary' }}).lanes().metadata.count, 'tertiary lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'tertiary', oneway: 'no' }}).lanes().metadata.count, 'tertiary lanes')
expect(iD.osmWay({tags: { highway: 'tertiary', oneway: 'no' }}).lanes().metadata.count, 'tertiary lanes')
.to.eql(2);
});
it('returns 1 lane for highway=tertiary and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'tertiary', oneway: 'yes' }}).lanes().metadata.count, 'tertiary lanes')
expect(iD.osmWay({tags: { highway: 'tertiary', oneway: 'yes' }}).lanes().metadata.count, 'tertiary lanes')
.to.eql(1);
});
it('returns 2 lane for highway=tertiary_link', function() {
expect(iD.Way({tags: { highway: 'tertiary_link' }}).lanes().metadata.count, 'tertiary_link lanes')
expect(iD.osmWay({tags: { highway: 'tertiary_link' }}).lanes().metadata.count, 'tertiary_link lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'tertiary_link', oneway: 'no' }}).lanes().metadata.count, 'tertiary_link lanes')
expect(iD.osmWay({tags: { highway: 'tertiary_link', oneway: 'no' }}).lanes().metadata.count, 'tertiary_link lanes')
.to.eql(2);
});
it('returns 1 lane for highway=tertiary_link and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'tertiary_link', oneway: 'yes' }}).lanes().metadata.count, 'tertiary_link lanes')
expect(iD.osmWay({tags: { highway: 'tertiary_link', oneway: 'yes' }}).lanes().metadata.count, 'tertiary_link lanes')
.to.eql(1);
});
});
@@ -140,14 +140,14 @@ describe('iD.Lanes', function() {
describe('residential', function() {
it('returns 2 lanes for highway=residential', function() {
expect(iD.Way({tags: { highway: 'residential' }}).lanes().metadata.count, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential' }}).lanes().metadata.count, 'residential lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'residential', oneway: 'no' }}).lanes().metadata.count, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', oneway: 'no' }}).lanes().metadata.count, 'residential lanes')
.to.eql(2);
});
it('returns 1 lane for highway=residential and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'residential', oneway: 'yes' }}).lanes().metadata.count, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', oneway: 'yes' }}).lanes().metadata.count, 'residential lanes')
.to.eql(1);
});
});
@@ -155,14 +155,14 @@ describe('iD.Lanes', function() {
describe('service', function() {
it('returns 2 lanes for highway=service', function() {
expect(iD.Way({tags: { highway: 'service' }}).lanes().metadata.count, 'service lanes')
expect(iD.osmWay({tags: { highway: 'service' }}).lanes().metadata.count, 'service lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'service', oneway: 'no' }}).lanes().metadata.count, 'service lanes')
expect(iD.osmWay({tags: { highway: 'service', oneway: 'no' }}).lanes().metadata.count, 'service lanes')
.to.eql(2);
});
it('returns 1 lane for highway=service and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'service', oneway: 'yes' }}).lanes().metadata.count, 'service lanes')
expect(iD.osmWay({tags: { highway: 'service', oneway: 'yes' }}).lanes().metadata.count, 'service lanes')
.to.eql(1);
});
});
@@ -170,14 +170,14 @@ describe('iD.Lanes', function() {
describe('track', function() {
it('returns 2 lanes for highway=track', function() {
expect(iD.Way({tags: { highway: 'track' }}).lanes().metadata.count, 'track lanes')
expect(iD.osmWay({tags: { highway: 'track' }}).lanes().metadata.count, 'track lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'track', oneway: 'no' }}).lanes().metadata.count, 'track lanes')
expect(iD.osmWay({tags: { highway: 'track', oneway: 'no' }}).lanes().metadata.count, 'track lanes')
.to.eql(2);
});
it('returns 1 lane for highway=track and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'track', oneway: 'yes' }}).lanes().metadata.count, 'track lanes')
expect(iD.osmWay({tags: { highway: 'track', oneway: 'yes' }}).lanes().metadata.count, 'track lanes')
.to.eql(1);
});
});
@@ -185,14 +185,14 @@ describe('iD.Lanes', function() {
describe('path', function() {
it('returns 2 lanes for highway=path', function() {
expect(iD.Way({tags: { highway: 'path' }}).lanes().metadata.count, 'path lanes')
expect(iD.osmWay({tags: { highway: 'path' }}).lanes().metadata.count, 'path lanes')
.to.eql(2);
expect(iD.Way({tags: { highway: 'path', oneway: 'no' }}).lanes().metadata.count, 'path lanes')
expect(iD.osmWay({tags: { highway: 'path', oneway: 'no' }}).lanes().metadata.count, 'path lanes')
.to.eql(2);
});
it('returns 1 lane for highway=path and oneway=yes', function() {
expect(iD.Way({tags: { highway: 'path', oneway: 'yes' }}).lanes().metadata.count, 'path lanes')
expect(iD.osmWay({tags: { highway: 'path', oneway: 'yes' }}).lanes().metadata.count, 'path lanes')
.to.eql(1);
});
});
@@ -200,9 +200,9 @@ describe('iD.Lanes', function() {
describe('oneway tags', function() {
it('returns correctly oneway when tagged as oneway', function() {
expect(iD.Way({tags: { highway: 'residential', oneway: 'yes' }}).lanes().metadata.oneway, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', oneway: 'yes' }}).lanes().metadata.oneway, 'residential lanes')
.to.be.true;
expect(iD.Way({tags: { highway: 'residential', oneway: 'no' }}).lanes().metadata.oneway, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', oneway: 'no' }}).lanes().metadata.oneway, 'residential lanes')
.to.be.false;
});
});
@@ -210,7 +210,7 @@ describe('iD.Lanes', function() {
describe('lane direction', function() {
it('returns correctly the lane:forward and lane:backward count', function() {
expect(iD.Way({tags: { highway: 'residential', lanes: 2, 'lanes:forward': 1, 'lanes:backward': 1 }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 2, 'lanes:forward': 1, 'lanes:backward': 1 }}).lanes().metadata, 'residential lanes')
.to.include({
count: 2,
oneway: false,
@@ -218,7 +218,7 @@ describe('iD.Lanes', function() {
backward: 1,
bothways: 0
});
expect(iD.Way({tags: { highway: 'residential', lanes: 4, 'lanes:forward': 3, 'lanes:backward': 1 }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 4, 'lanes:forward': 3, 'lanes:backward': 1 }}).lanes().metadata, 'residential lanes')
.to.include({
count: 4,
oneway: false,
@@ -229,7 +229,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly the count if erroneous values are supplied', function() {
expect(iD.Way({tags: { highway: 'trunk', lanes: 2, 'lanes:forward': 3 }}).lanes().metadata, 'trunk lanes')
expect(iD.osmWay({tags: { highway: 'trunk', lanes: 2, 'lanes:forward': 3 }}).lanes().metadata, 'trunk lanes')
.to.include({
count: 2,
oneway: false,
@@ -240,7 +240,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly forward count when oneway=yes', function() {
expect(iD.Way({tags: { highway: 'trunk', lanes: 2, oneway: 'yes' }}).lanes().metadata, 'trunk lanes')
expect(iD.osmWay({tags: { highway: 'trunk', lanes: 2, oneway: 'yes' }}).lanes().metadata, 'trunk lanes')
.to.include({
count: 2,
oneway: true,
@@ -251,7 +251,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly backward count the when oneway=-1', function() {
expect(iD.Way({tags: { highway: 'primary', lanes: 4, oneway: '-1' }}).lanes().metadata, 'primary lanes')
expect(iD.osmWay({tags: { highway: 'primary', lanes: 4, oneway: '-1' }}).lanes().metadata, 'primary lanes')
.to.include({
count: 4,
oneway: true,
@@ -262,7 +262,7 @@ describe('iD.Lanes', function() {
});
it('skips provided lanes:forward value when oneway=yes', function() {
expect(iD.Way({tags: { highway: 'trunk', lanes: 2, oneway: 'yes', 'lanes:forward': 1 }}).lanes().metadata, 'trunk lanes')
expect(iD.osmWay({tags: { highway: 'trunk', lanes: 2, oneway: 'yes', 'lanes:forward': 1 }}).lanes().metadata, 'trunk lanes')
.to.include({
count: 2,
oneway: true,
@@ -273,7 +273,7 @@ describe('iD.Lanes', function() {
});
it('skips provided lanes:backward value when oneway=yes', function() {
expect(iD.Way({tags: { highway: 'trunk', lanes: 2, oneway: 'yes', 'lanes:backward': 1 }}).lanes().metadata, 'trunk lanes')
expect(iD.osmWay({tags: { highway: 'trunk', lanes: 2, oneway: 'yes', 'lanes:backward': 1 }}).lanes().metadata, 'trunk lanes')
.to.include({
count: 2,
oneway: true,
@@ -284,7 +284,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly forward count if only backward is supplied', function() {
expect(iD.Way({tags: { highway: 'residential', lanes: 3, 'lanes:backward': 1, }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 3, 'lanes:backward': 1, }}).lanes().metadata, 'residential lanes')
.to.include({
count: 3,
oneway: false,
@@ -292,7 +292,7 @@ describe('iD.Lanes', function() {
backward: 1,
bothways: 0
});
expect(iD.Way({tags: { highway: 'residential', lanes: 4, 'lanes:backward': 3, }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 4, 'lanes:backward': 3, }}).lanes().metadata, 'residential lanes')
.to.include({
count: 4,
oneway: false,
@@ -303,7 +303,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly backward count if only forward is supplied', function() {
expect(iD.Way({tags: { highway: 'residential', lanes: 3, 'lanes:forward': 1, }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 3, 'lanes:forward': 1, }}).lanes().metadata, 'residential lanes')
.to.include({
count: 3,
oneway: false,
@@ -311,7 +311,7 @@ describe('iD.Lanes', function() {
backward: 2,
bothways: 0
});
expect(iD.Way({tags: { highway: 'residential', lanes: 2, 'lanes:forward': 1, }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 2, 'lanes:forward': 1, }}).lanes().metadata, 'residential lanes')
.to.include({
count: 2,
oneway: false,
@@ -322,7 +322,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly backward count if forward and both_ways are supplied', function() {
expect(iD.Way({tags: { highway: 'residential', lanes: 3, 'lanes:forward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 3, 'lanes:forward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
.to.include({
count: 3,
oneway: false,
@@ -330,7 +330,7 @@ describe('iD.Lanes', function() {
backward: 1,
bothways: 1
});
expect(iD.Way({tags: { highway: 'residential', lanes: 5, 'lanes:forward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 5, 'lanes:forward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
.to.include({
count: 5,
oneway: false,
@@ -341,7 +341,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly forward count if backward and both_ways are supplied', function() {
expect(iD.Way({tags: { highway: 'residential', lanes: 3, 'lanes:backward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 3, 'lanes:backward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
.to.include({
count: 3,
oneway: false,
@@ -349,7 +349,7 @@ describe('iD.Lanes', function() {
backward: 1,
bothways: 1
});
expect(iD.Way({tags: { highway: 'residential', lanes: 5, 'lanes:backward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 5, 'lanes:backward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
.to.include({
count: 5,
oneway: false,
@@ -360,7 +360,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly the lane:both_ways count as 1', function() {
expect(iD.Way({tags: { highway: 'residential', lanes: 2, 'lanes:forward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 2, 'lanes:forward': 1, 'lanes:both_ways': 1 }}).lanes().metadata, 'residential lanes')
.to.include({
count: 2,
oneway: false,
@@ -371,7 +371,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly when lane:both_ways>1', function() {
expect(iD.Way({tags: { highway: 'residential', lanes: 5, 'lanes:forward': 2, 'lanes:both_ways': 2, 'lanes:backward': 2 }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 5, 'lanes:forward': 2, 'lanes:both_ways': 2, 'lanes:backward': 2 }}).lanes().metadata, 'residential lanes')
.to.include({
count: 5,
oneway: false,
@@ -382,7 +382,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly when lane:both_ways is 0 or Not a Number', function() {
expect(iD.Way({tags: { highway: 'residential', lanes: 5, 'lanes:forward': 2, 'lanes:both_ways': 0, 'lanes:backward': 3 }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 5, 'lanes:forward': 2, 'lanes:both_ways': 0, 'lanes:backward': 3 }}).lanes().metadata, 'residential lanes')
.to.include({
count: 5,
oneway: false,
@@ -390,7 +390,7 @@ describe('iD.Lanes', function() {
backward: 3,
bothways: 0
});
expect(iD.Way({tags: { highway: 'residential', lanes: 2, 'lanes:forward': 1, 'lanes:both_ways': 'none' }}).lanes().metadata, 'residential lanes')
expect(iD.osmWay({tags: { highway: 'residential', lanes: 2, 'lanes:forward': 1, 'lanes:both_ways': 'none' }}).lanes().metadata, 'residential lanes')
.to.include({
count: 2,
oneway: false,
@@ -404,7 +404,7 @@ describe('iD.Lanes', function() {
describe.skip('lanes array', function() {
it('should have correct number of direction elements', function() {
var lanes = iD.Way({tags: { highway: 'residential', lanes: 5, 'lanes:forward': 2, 'lanes:both_ways': 0, 'lanes:backward': 3 }}).lanes().lanes;
var lanes = iD.osmWay({tags: { highway: 'residential', lanes: 5, 'lanes:forward': 2, 'lanes:both_ways': 0, 'lanes:backward': 3 }}).lanes().lanes;
var forward = lanes.filter(function(l) {
return l.direction === 'forward';
});
@@ -420,7 +420,7 @@ describe('iD.Lanes', function() {
});
it('should have corrent number of direction elements', function() {
var lanes = iD.Way({tags: { highway: 'residential', lanes: 5, 'lanes:backward': 1, 'lanes:both_ways': 1 }}).lanes().lanes;
var lanes = iD.osmWay({tags: { highway: 'residential', lanes: 5, 'lanes:backward': 1, 'lanes:both_ways': 1 }}).lanes().lanes;
var forward = lanes.filter(function(l) {
return l.direction === 'forward';
});
@@ -438,7 +438,7 @@ describe('iD.Lanes', function() {
describe('turn lanes', function() {
it('returns correctly when oneway=yes', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'trunk',
oneway: 'yes',
@@ -452,7 +452,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly when oneway=yes and lanes=2', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
oneway: 'yes',
@@ -468,7 +468,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly when lanes=5 and both_ways=1', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -489,7 +489,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly when multiple values are present in a lane and oneway=yes', function() {
var lanesData = iD.Way({
var lanesData = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -509,7 +509,7 @@ describe('iD.Lanes', function() {
});
it('returns correctly when multiple values are present in a lane and oneway=no', function() {
var lanesData = iD.Way({
var lanesData = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -534,7 +534,7 @@ describe('iD.Lanes', function() {
});
it('returns unknown for every invalid value in turn:lanes', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 3,
@@ -549,7 +549,7 @@ describe('iD.Lanes', function() {
});
it('returns unknown for every invalid value in turn:lanes:forward & turn:lanes:backward', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -570,7 +570,7 @@ describe('iD.Lanes', function() {
});
it.skip('fills with [\'unknown\'] when given turn:lanes are less than lanes count', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -586,7 +586,7 @@ describe('iD.Lanes', function() {
});
it.skip('fills with [\'unknown\'] when given turn:lanes:forward are less than lanes forward count', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -608,7 +608,7 @@ describe('iD.Lanes', function() {
});
it.skip('clips when turn lane information is more than lane count', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 2,
@@ -624,7 +624,7 @@ describe('iD.Lanes', function() {
});
it('turnLanes is undefined when not present', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 2,
@@ -641,7 +641,7 @@ describe('iD.Lanes', function() {
});
it('turnLanes.forward and turnLanes.backward are both undefined when both are not provided', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 2,
@@ -659,7 +659,7 @@ describe('iD.Lanes', function() {
});
it('parses turnLane correctly when lanes:both_ways=1', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -678,7 +678,7 @@ describe('iD.Lanes', function() {
});
it('parses turnLane correctly when lanes:both_ways=1 & lanes:forward < lanes:backward', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -697,7 +697,7 @@ describe('iD.Lanes', function() {
});
it('parses correctly when turn:lanes= ||x', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 3,
@@ -711,7 +711,7 @@ describe('iD.Lanes', function() {
});
it('parses correctly when turn:lanes= |x|', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -724,7 +724,7 @@ describe('iD.Lanes', function() {
});
it('parses correctly when turn:lanes:forward= ||x', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 4,
@@ -743,7 +743,7 @@ describe('iD.Lanes', function() {
});
it('parses correctly when turn:lanes:backward= |', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -762,7 +762,7 @@ describe('iD.Lanes', function() {
});
it('fills lanes.unspecified with key \'turnLane\' correctly', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -779,7 +779,7 @@ describe('iD.Lanes', function() {
});
it('fills lanes.forward & lanes.backward with key \'turnLane\' correctly', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'tertiary',
lanes: 5,
@@ -803,7 +803,7 @@ describe('iD.Lanes', function() {
describe('maxspeed', function() {
it('should parse maxspeed without any units correctly', function() {
var maxspeed = iD.Way({
var maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -811,7 +811,7 @@ describe('iD.Lanes', function() {
}
}).lanes().metadata.maxspeed;
expect(maxspeed).to.equal(70);
maxspeed = iD.Way({
maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -822,7 +822,7 @@ describe('iD.Lanes', function() {
});
it('should parse maxspeed with km/h correctly', function() {
var maxspeed = iD.Way({
var maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -833,7 +833,7 @@ describe('iD.Lanes', function() {
});
it('should parse maxspeed with kmh correctly', function() {
var maxspeed = iD.Way({
var maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -844,7 +844,7 @@ describe('iD.Lanes', function() {
});
it('should parse maxspeed with kph correctly', function() {
var maxspeed = iD.Way({
var maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -855,7 +855,7 @@ describe('iD.Lanes', function() {
});
it('should parse maxspeed with mph correctly', function() {
var maxspeed = iD.Way({
var maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -866,7 +866,7 @@ describe('iD.Lanes', function() {
});
it('should parse maxspeed with knots correctly', function() {
var maxspeed = iD.Way({
var maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -877,7 +877,7 @@ describe('iD.Lanes', function() {
});
it('should return undefined when incorrect maxspeed unit provided ', function() {
var maxspeed = iD.Way({
var maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -888,7 +888,7 @@ describe('iD.Lanes', function() {
});
it('should return undefined when incorrect maxspeed value provided ', function() {
var maxspeed = iD.Way({
var maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -899,7 +899,7 @@ describe('iD.Lanes', function() {
});
it('should return undefined when maxspeed not provided ', function() {
var maxspeed = iD.Way({
var maxspeed = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -912,7 +912,7 @@ describe('iD.Lanes', function() {
describe('maxspeed:lanes', function() {
it('should parse correctly', function() {
var maxspeedLanes = iD.Way({
var maxspeedLanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -925,7 +925,7 @@ describe('iD.Lanes', function() {
});
it('should parse maxspeed:lanes:forward/backward correctly', function() {
var metadata = iD.Way({
var metadata = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -945,7 +945,7 @@ describe('iD.Lanes', function() {
});
it('should parse correctly when some values maxspeed:lanes are implied by x||y notation', function() {
var maxspeedLanes = iD.Way({
var maxspeedLanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 4,
@@ -959,7 +959,7 @@ describe('iD.Lanes', function() {
});
it('should parse correctly when some values maxspeed:lanes are implied by x||| notation', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -977,7 +977,7 @@ describe('iD.Lanes', function() {
});
it('should return none for each maxspeed:lanes which equals maxspeed', function() {
var maxspeedLanes = iD.Way({
var maxspeedLanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -988,7 +988,7 @@ describe('iD.Lanes', function() {
expect(maxspeedLanes.unspecified).to.deep.equal([
30, null, null, null, null
]);
maxspeedLanes = iD.Way({
maxspeedLanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -999,7 +999,7 @@ describe('iD.Lanes', function() {
expect(maxspeedLanes.unspecified).to.deep.equal([
30, 40, 40, 40, 40
]);
maxspeedLanes = iD.Way({
maxspeedLanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -1013,7 +1013,7 @@ describe('iD.Lanes', function() {
});
it('should return \'unknown\' for every invalid maxspeed:lane value', function() {
var maxspeedLanes = iD.Way({
var maxspeedLanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -1024,7 +1024,7 @@ describe('iD.Lanes', function() {
expect(maxspeedLanes.unspecified).to.deep.equal([
null, 40, 'unknown', 40, 40
]);
maxspeedLanes = iD.Way({
maxspeedLanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -1039,7 +1039,7 @@ describe('iD.Lanes', function() {
});
it('should parse maxspeed when none', function() {
var maxspeedLanes = iD.Way({
var maxspeedLanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -1052,7 +1052,7 @@ describe('iD.Lanes', function() {
});
it('fills lanes.unspecified with key \'maxspeed\' correctly', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -1071,7 +1071,7 @@ describe('iD.Lanes', function() {
describe('bicycle lanes', function() {
it('should parse bicycle:lanes correctly', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 3,
@@ -1093,7 +1093,7 @@ describe('iD.Lanes', function() {
});
it('should parse bicycle:lanes:forward/backward correctly', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'residential',
'lanes:forward': 4,
@@ -1124,7 +1124,7 @@ describe('iD.Lanes', function() {
});
it('should replace any invalid value with unknown', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 3,
@@ -1147,7 +1147,7 @@ describe('iD.Lanes', function() {
describe('miscellaneous lanes', function() {
it('should parse psv:lanes correctly', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -1166,7 +1166,7 @@ describe('iD.Lanes', function() {
]);
});
it('should parse psv:lanes:forward/backward correctly', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 5,
@@ -1195,7 +1195,7 @@ describe('iD.Lanes', function() {
]);
});
it('should replace any invalid value with unknown', function() {
var lanes = iD.Way({
var lanes = iD.osmWay({
tags: {
highway: 'residential',
lanes: 3,
+374 -374
View File
File diff suppressed because it is too large Load Diff
+6 -6
View File
@@ -149,12 +149,12 @@ describe('iD.presetCollection', function() {
it('excludes presets with searchable: false', function() {
var excluded = iD.presetPreset('__test/excluded', {
name: 'excluded',
tags: { amenity: 'excluded' },
geometry: ['point'],
searchable: false
}),
collection = iD.presetCollection([excluded, p.point]);
name: 'excluded',
tags: { amenity: 'excluded' },
geometry: ['point'],
searchable: false
});
var collection = iD.presetCollection([excluded, p.point]);
expect(collection.search('excluded', 'point').collection).not.to.include(excluded);
});
});
+145 -289
View File
@@ -1,55 +1,42 @@
describe('iD.presetIndex', function () {
var savedPresets, server;
var savedPresets, savedAreaKeys, server;
before(function () {
savedPresets = iD.data.presets;
savedAreaKeys = iD.areaKeys;
});
after(function () {
iD.data.presets = savedPresets;
iD.setAreaKeys(savedAreaKeys);
});
describe('#match', function () {
var testPresets = {
presets: {
point: {
tags: {},
geometry: ['point']
},
line: {
tags: {},
geometry: ['line']
},
vertex: {
tags: {},
geometry: ['vertex']
},
residential: {
tags: { highway: 'residential' },
geometry: ['line']
},
park: {
tags: { leisure: 'park' },
geometry: ['point', 'area']
}
point: { tags: {}, geometry: ['point'] },
line: { tags: {}, geometry: ['line'] },
vertex: { tags: {}, geometry: ['vertex'] },
residential: { tags: { highway: 'residential' }, geometry: ['line'] },
park: { tags: { leisure: 'park' }, geometry: ['point', 'area'] }
}
};
it('returns a collection containing presets matching a geometry and tags', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets(),
way = iD.Way({ tags: { highway: 'residential' } }),
graph = iD.Graph([way]);
var presets = iD.coreContext().presets();
var way = iD.osmWay({ tags: { highway: 'residential' } });
var graph = iD.coreGraph([way]);
expect(presets.match(way, graph).id).to.eql('residential');
});
it('returns the appropriate fallback preset when no tags match', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets(),
point = iD.Node(),
line = iD.Way({ tags: { foo: 'bar' } }),
graph = iD.Graph([point, line]);
var presets = iD.coreContext().presets();
var point = iD.osmNode();
var line = iD.osmWay({ tags: { foo: 'bar' } });
var graph = iD.coreGraph([point, line]);
expect(presets.match(point, graph).id).to.eql('point');
expect(presets.match(line, graph).id).to.eql('line');
@@ -57,20 +44,20 @@ describe('iD.presetIndex', function () {
it('matches vertices on a line as vertices', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets(),
point = iD.Node({ tags: { leisure: 'park' } }),
line = iD.Way({ nodes: [point.id], tags: { 'highway': 'residential' } }),
graph = iD.Graph([point, line]);
var presets = iD.coreContext().presets();
var point = iD.osmNode({ tags: { leisure: 'park' } });
var line = iD.osmWay({ nodes: [point.id], tags: { 'highway': 'residential' } });
var graph = iD.coreGraph([point, line]);
expect(presets.match(point, graph).id).to.eql('vertex');
});
it('matches vertices on an addr:interpolation line as points', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets(),
point = iD.Node({ tags: { leisure: 'park' } }),
line = iD.Way({ nodes: [point.id], tags: { 'addr:interpolation': 'even' } }),
graph = iD.Graph([point, line]);
var presets = iD.coreContext().presets();
var point = iD.osmNode({ tags: { leisure: 'park' } });
var line = iD.osmWay({ nodes: [point.id], tags: { 'addr:interpolation': 'even' } });
var graph = iD.coreGraph([point, line]);
expect(presets.match(point, graph).id).to.eql('park');
});
@@ -80,119 +67,97 @@ describe('iD.presetIndex', function () {
describe('#areaKeys', function () {
var testPresets = {
presets: {
'amenity/fuel/shell': {
tags: { 'amenity': 'fuel' },
geometry: ['point', 'area'],
suggestion: true
},
'highway/foo': {
tags: { 'highway': 'foo' },
geometry: ['area']
},
'leisure/track': {
tags: { 'leisure': 'track' },
geometry: ['line', 'area']
},
'natural': {
tags: { 'natural': '*' },
geometry: ['point', 'vertex', 'area']
},
'natural/peak': {
tags: { 'natural': 'peak' },
geometry: ['point', 'vertex']
},
'natural/tree_row': {
tags: { 'natural': 'tree_row' },
geometry: ['line']
},
'natural/wood': {
tags: { 'natural': 'wood' },
geometry: ['point', 'area']
}
'amenity/fuel/shell': { tags: { 'amenity': 'fuel' }, geometry: ['point', 'area'], suggestion: true },
'highway/foo': { tags: { 'highway': 'foo' }, geometry: ['area'] },
'leisure/track': { tags: { 'leisure': 'track' }, geometry: ['line', 'area'] },
'natural': { tags: { 'natural': '*' }, geometry: ['point', 'vertex', 'area'] },
'natural/peak': { tags: { 'natural': 'peak' }, geometry: ['point', 'vertex'] },
'natural/tree_row': { tags: { 'natural': 'tree_row' }, geometry: ['line'] },
'natural/wood': { tags: { 'natural': 'wood' }, geometry: ['point', 'area'] }
}
};
it('whitelists keys for presets with area geometry', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets();
var presets = iD.coreContext().presets();
expect(presets.areaKeys()).to.include.keys('natural');
});
it('blacklists key-values for presets with a line geometry', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets();
var presets = iD.coreContext().presets();
expect(presets.areaKeys().natural).to.include.keys('tree_row');
expect(presets.areaKeys().natural.tree_row).to.be.true;
});
it('blacklists key-values for presets with both area and line geometry', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets();
var presets = iD.coreContext().presets();
expect(presets.areaKeys().leisure).to.include.keys('track');
});
it('does not blacklist key-values for presets with neither area nor line geometry', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets();
var presets = iD.coreContext().presets();
expect(presets.areaKeys().natural).not.to.include.keys('peak');
});
it('does not blacklist generic \'*\' key-values', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets();
var presets = iD.coreContext().presets();
expect(presets.areaKeys().natural).not.to.include.keys('natural');
});
it('ignores keys like \'highway\' that are assumed to be lines', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets();
var presets = iD.coreContext().presets();
expect(presets.areaKeys()).not.to.include.keys('highway');
});
it('ignores suggestion presets', function () {
iD.data.presets = testPresets;
var presets = iD.Context().presets();
var presets = iD.coreContext().presets();
expect(presets.areaKeys()).not.to.include.keys('amenity');
});
});
describe('#build', function () {
it('builds presets from provided', function () {
var surfShop = iD.Node({ tags: { amenity: 'shop', 'shop:type': 'surf' } }),
graph = iD.Graph([surfShop]),
presets = iD.Context().presets(),
morePresets = {
presets: {
'amenity/shop/surf': {
tags: { amenity: 'shop', 'shop:type': 'surf' },
geometry: ['point', 'area']
}
var surfShop = iD.osmNode({ tags: { amenity: 'shop', 'shop:type': 'surf' } });
var graph = iD.coreGraph([surfShop]);
var presets = iD.coreContext().presets();
var morePresets = {
presets: {
'amenity/shop/surf': {
tags: { amenity: 'shop', 'shop:type': 'surf' },
geometry: ['point', 'area']
}
};
}
};
expect(presets.match(surfShop, graph)).to.eql(undefined); // no surfshop preset yet...
presets.build(morePresets, true);
expect(presets.match(surfShop, graph).addTags).to.eql({ amenity: 'shop', 'shop:type': 'surf' });
});
it('configures presets\' initial visibility', function () {
var surfShop = iD.Node({ tags: { amenity: 'shop', 'shop:type': 'surf' } }),
firstStreetJetty = iD.Node({ tags: { man_made: 'jetty' } }),
entities = [surfShop, firstStreetJetty],
graph = iD.Graph(entities),
presets = iD.Context().presets(),
morePresets = {
presets: {
'amenity/shop/surf': {
tags: { amenity: 'shop', 'shop:type': 'surf' },
geometry: ['point', 'area']
},
'man_made/jetty': {
tags: { man_made: 'jetty' },
geometry: ['point']
}
var surfShop = iD.osmNode({ tags: { amenity: 'shop', 'shop:type': 'surf' } });
var firstStreetJetty = iD.osmNode({ tags: { man_made: 'jetty' } });
var entities = [surfShop, firstStreetJetty];
var graph = iD.coreGraph(entities);
var presets = iD.coreContext().presets();
var morePresets = {
presets: {
'amenity/shop/surf': {
tags: { amenity: 'shop', 'shop:type': 'surf' },
geometry: ['point', 'area']
},
'man_made/jetty': {
tags: { man_made: 'jetty' },
geometry: ['point']
}
};
}
};
presets.build(morePresets, false);
entities.forEach(function (entity) {
@@ -203,241 +168,132 @@ describe('iD.presetIndex', function () {
});
describe('expected matches', function () {
var testPresets = {
presets: {
area: { name: 'Area', tags: {}, geometry: ['area'] },
line: { name: 'Line', tags: {}, geometry: ['line'] },
point: { name: 'Point', tags: {}, geometry: ['point'] },
vertex: { name: 'Vertex', tags: {}, geometry: ['vertex'] },
relation: { name: 'Relation', tags: {}, geometry: ['relation'] },
building: { name: 'Building', tags: { building: 'yes' }, geometry: ['area'] },
'type/multipolygon': {
name: 'Multipolygon',
geometry: ['area', 'relation'],
tags: { 'type': 'multipolygon' },
searchable: false,
matchScore: 0.1
},
address: {
name: 'Address',
geometry: ['point', 'vertex', 'area'],
tags: { 'addr:*': '*' },
matchScore: 0.15
},
'highway/pedestrian_area': {
name: 'Pedestrian Area',
geometry: ['area'],
tags: { highway: 'pedestrian', area: 'yes' }
}
}
};
it('prefers building to multipolygon', function () {
iD.data.presets = savedPresets;
var presets = iD.Context().presets(),
relation = iD.Relation({ tags: { type: 'multipolygon', building: 'yes' } }),
graph = iD.Graph([relation]);
iD.data.presets = testPresets;
var presets = iD.coreContext().presets();
var relation = iD.osmRelation({ tags: { type: 'multipolygon', building: 'yes' } });
var graph = iD.coreGraph([relation]);
expect(presets.match(relation, graph).id).to.eql('building');
});
it('prefers building to address', function () {
iD.data.presets = savedPresets;
var presets = iD.Context().presets(),
way = iD.Way({ tags: { area: 'yes', building: 'yes', 'addr:housenumber': '1234' } }),
graph = iD.Graph([way]);
iD.data.presets = testPresets;
var presets = iD.coreContext().presets();
var way = iD.osmWay({ tags: { area: 'yes', building: 'yes', 'addr:housenumber': '1234' } });
var graph = iD.coreGraph([way]);
expect(presets.match(way, graph).id).to.eql('building');
});
it('prefers pedestrian to area', function () {
iD.data.presets = savedPresets;
var presets = iD.Context().presets(),
way = iD.Way({ tags: { area: 'yes', highway: 'pedestrian' } }),
graph = iD.Graph([way]);
iD.data.presets = testPresets;
var presets = iD.coreContext().presets();
var way = iD.osmWay({ tags: { area: 'yes', highway: 'pedestrian' } });
var graph = iD.coreGraph([way]);
expect(presets.match(way, graph).id).to.eql('highway/pedestrian_area');
});
});
describe('#fromExternal', function () {
var morePresets;
before(function () {
morePresets = {
'categories': {
'category-area': {
'icon': 'maki-natural',
'geometry': 'area',
'name': 'MapRules area Features',
'members': [
'8bc64d6d-1dbb-44a8-a2f9-80d41d067d78',
'a9b78746-ca8a-4380-b340-157414f1464d'
]
},
'category-point': {
'icon': 'maki-natural',
'geometry': 'point',
'name': 'MapRules point Features',
'members': [
'8bc64d6d-1dbb-44a8-a2f9-80d41d067d78',
'8f83ed0b-6514-4772-a644-f04aad9d2308'
]
}
},
'presets': {
'8bc64d6d-1dbb-44a8-a2f9-80d41d067d78': {
'geometry': ['area', 'point'],
'tags': { 'amenity': 'shop', 'shop:type': 'surf' },
'icon': 'maki-natural',
'name': 'Surf Shop',
'fields': ['358f404a-c7d5-4267-94ed-41f789b16228'],
'matchScore': 0.99
},
'a9b78746-ca8a-4380-b340-157414f1464d': {
'geometry': ['area'],
'tags': { 'amenity': 'marketplace' },
'icon': 'maki-natural',
'name': 'Market',
'fields': [
'name',
'source',
'2161a712-f67f-4759-92fa-f5d9488ba969',
'368ecbdf-bc02-4de2-a82e-d51c250602da',
'1887834c-0cdd-4d40-852b-d29b8df94567'
],
'matchScore': 0.99
},
'8f83ed0b-6514-4772-a644-f04aad9d2308': {
'geometry': ['point'],
'tags': {
'amenity': 'drinking_water',
'man_made': 'water_tap'
},
'icon': 'maki-natural',
'name': 'Water Tap',
'fields': ['name'],
'matchScore': 0.99
}
},
'fields': {
'358f404a-c7d5-4267-94ed-41f789b16228': {
'key': 'healthcare',
'label': 'Healthcare',
'overrideLabel': 'Healthcare',
'placeholder': '...',
'type': 'text'
},
'name': {
'key': 'name',
'type': 'localized',
'label': 'Name',
'universal': true,
'placeholder': 'Common name (if any)'
},
'source': {
'key': 'source',
'type': 'semiCombo',
'icon': 'source',
'universal': true,
'label': 'Sources',
'snake_case': false,
'caseSensitive': true,
'options': [
'survey',
'local knowledge',
'gps',
'aerial imagery',
'streetlevel imagery'
]
},
'2161a712-f67f-4759-92fa-f5d9488ba969': {
'key': 'building',
'label': 'Building',
'overrideLabel': 'Building',
'placeholder': '...',
'type': 'text'
},
'368ecbdf-bc02-4de2-a82e-d51c250602da': {
'key': 'opening_hours',
'label': 'Opening Hours',
'overrideLabel': 'Opening Hours',
'placeholder': '24/7, sunrise to sunset...',
'strings': {
'options': {
'24/7': '24/7',
'sunrise to sunset': 'sunrise to sunset'
}
},
'type': 'combo'
},
'1887834c-0cdd-4d40-852b-d29b8df94567': {
'key': 'height',
'label': 'Height',
'overrideLabel': 'Height',
'placeholder': '...',
'minValue': 1, 'type': 'number'
},
'relation': {
'key': 'type',
'type': 'combo',
'label': 'Type'
},
'comment': {
'key': 'comment',
'type': 'textarea',
'label': 'Changeset Comment',
'placeholder': 'Brief description of your contributions (required)'
},
'hashtags': {
'key': 'hashtags',
'type': 'semiCombo',
'label': 'Suggested Hashtags',
'placeholder': '#example'
}
},
'defaults': {
'point': [
'point',
'8bc64d6d-1dbb-44a8-a2f9-80d41d067d78',
'8f83ed0b-6514-4772-a644-f04aad9d2308'
],
'line': ['line'],
'area': [
'area',
'8bc64d6d-1dbb-44a8-a2f9-80d41d067d78',
'a9b78746-ca8a-4380-b340-157414f1464d'
],
'vertex': ['vertex'],
'relation': ['relation']
var morePresets = {
presets: {
'8bc64d6d': {
'name': 'Surf Shop',
'geometry': ['area', 'point'],
'fields': ['2161a712'],
'tags': { 'amenity': 'shop', 'shop:type': 'surf' },
'matchScore': 0.99
}
};
},
'fields': {
'2161a712': {
'key': 'building',
'label': 'Building',
'overrideLabel': 'Building',
'type': 'text'
}
}
};
});
beforeEach(function () {
server = sinon.fakeServer.create();
});
afterEach(function () {
server.restore();
});
it('builds presets w/external sources set to visible', function () {
var surfShop = iD.Node({ tags: { amenity: 'shop', 'shop:type': 'surf' } }),
graph = iD.Graph([surfShop]),
maprules = 'https://fakemaprules.io',
presetLocation = '/config/dfcfac13-ba7c-4223-8880-c856180e5c5b/presets/iD/',
match = new RegExp(presetLocation),
external = maprules + presetLocation;
// no exernal presets yet
expect(iD.Context().presets().match(surfShop, graph).id).to.eql('amenity');
var surfShop = iD.osmNode({ tags: { amenity: 'shop', 'shop:type': 'surf' } });
var graph = iD.coreGraph([surfShop]);
var url = 'https://fakemaprules.io/fake.json';
// no exernal presets yet
expect(iD.coreContext().presets().match(surfShop, graph).id).to.eql('point');
// reset graph...
graph = iD.Graph([surfShop]);
graph = iD.coreGraph([surfShop]);
// add the validations query param...
iD.Context().presets().fromExternal(external, function (externalPresets) {
// includes newer presets...
expect(externalPresets.match(surfShop, graph).id).to.eql('8bc64d6d-1dbb-44a8-a2f9-80d41d067d78');
iD.coreContext().presets().fromExternal(url, function (externalPresets) {
expect(externalPresets.match(surfShop, graph).id).to.eql('8bc64d6d');
});
server.respondWith('GET', match,
server.respondWith('GET', /fake\.json/,
[200, { 'Content-Type': 'application/json' }, JSON.stringify(morePresets)]
);
server.respond();
});
it('makes only the external presets initially visible', function () {
var maprules = 'https://fakemaprules.io',
presetLocation = '/config/dfcfac13-ba7c-4223-8880-c856180e5c5b/presets/iD/',
match = new RegExp(presetLocation),
external = maprules + presetLocation;
iD.Context().presets().fromExternal(external, function(externalPresets) {
var external = externalPresets.collection.reduce(function(presets, preset) {
it('makes only the external presets initially visible', function () {
var url = 'https://fakemaprules.io/fake.json';
iD.coreContext().presets().fromExternal(url, function(externalPresets) {
var external = externalPresets.collection.reduce(function(presets, preset) {
if (!preset.hasOwnProperty('members') && preset.visible()) {
presets.push(preset.id);
}
return presets;
}, []);
var morePresetKeys = Object.keys(morePresets.presets);
var morePresetKeys = Object.keys(morePresets.presets);
expect(morePresetKeys.length).to.eql(external.length);
morePresetKeys.forEach(function(presetId) {
expect(external.indexOf(presetId)).to.be.at.least(0);
morePresetKeys.forEach(function(presetID) {
expect(external.indexOf(presetID)).to.be.at.least(0);
});
});
server.respondWith('GET', match,
server.respondWith('GET', /fake\.json/,
[200, { 'Content-Type': 'application/json' }, JSON.stringify(morePresets)]
);
server.respond();
+29 -18
View File
@@ -1,4 +1,3 @@
/* globals context: true */
describe('iD.presetPreset', function() {
it('has optional fields', function() {
var preset = iD.presetPreset('test', {});
@@ -19,30 +18,30 @@ describe('iD.presetPreset', function() {
describe('#matchScore', function() {
it('returns -1 if preset does not match tags', function() {
var preset = iD.presetPreset('test', {tags: {foo: 'bar'}}),
entity = iD.Way({tags: {highway: 'motorway'}});
var preset = iD.presetPreset('test', {tags: {foo: 'bar'}});
var entity = iD.osmWay({tags: {highway: 'motorway'}});
expect(preset.matchScore(entity)).to.equal(-1);
});
it('returns the value of the matchScore property when matched', function() {
var preset = iD.presetPreset('test', {tags: {highway: 'motorway'}, matchScore: 0.2}),
entity = iD.Way({tags: {highway: 'motorway'}});
var preset = iD.presetPreset('test', {tags: {highway: 'motorway'}, matchScore: 0.2});
var entity = iD.osmWay({tags: {highway: 'motorway'}});
expect(preset.matchScore(entity)).to.equal(0.2);
});
it('defaults to the number of matched tags', function() {
var preset = iD.presetPreset('test', {tags: {highway: 'residential'}}),
entity = iD.Way({tags: {highway: 'residential'}});
var preset = iD.presetPreset('test', {tags: {highway: 'residential'}});
var entity = iD.osmWay({tags: {highway: 'residential'}});
expect(preset.matchScore(entity)).to.equal(1);
preset = iD.presetPreset('test', {tags: {highway: 'service', service: 'alley'}});
entity = iD.Way({tags: {highway: 'service', service: 'alley'}});
entity = iD.osmWay({tags: {highway: 'service', service: 'alley'}});
expect(preset.matchScore(entity)).to.equal(2);
});
it('counts * as a match for any value with score 0.5', function() {
var preset = iD.presetPreset('test', {tags: {building: '*'}}),
entity = iD.Way({tags: {building: 'yep'}});
var preset = iD.presetPreset('test', {tags: {building: '*'}});
var entity = iD.osmWay({tags: {building: 'yep'}});
expect(preset.matchScore(entity)).to.equal(0.5);
});
});
@@ -70,14 +69,25 @@ describe('iD.presetPreset', function() {
});
describe('#setTags', function() {
var savedAreaKeys;
before(function () {
savedAreaKeys = iD.areaKeys;
iD.setAreaKeys({ building: {}, natural: {} });
});
after(function () {
iD.setAreaKeys(savedAreaKeys);
});
it('adds match tags', function() {
var preset = iD.presetPreset('test', {tags: {highway: 'residential'}});
expect(preset.setTags({}, 'line')).to.eql({highway: 'residential'});
});
it('adds wildcard tags with value \'yes\'', function() {
var preset = iD.presetPreset('test', {tags: {building: '*'}});
expect(preset.setTags({}, 'area')).to.eql({building: 'yes'});
var preset = iD.presetPreset('test', {tags: {natural: '*'}});
expect(preset.setTags({}, 'area')).to.eql({natural: 'yes'});
});
it('prefers to add tags of addTags property', function() {
@@ -86,14 +96,14 @@ describe('iD.presetPreset', function() {
});
it('adds default tags of fields with matching geometry', function() {
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'}),
preset = iD.presetPreset('test', {fields: ['field']}, {field: field});
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'});
var preset = iD.presetPreset('test', {fields: ['field']}, {field: field});
expect(preset.setTags({}, 'area')).to.eql({area: 'yes', building: 'yes'});
});
it('adds no default tags of fields with non-matching geometry', function() {
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'}),
preset = iD.presetPreset('test', {fields: ['field']}, {field: field});
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'});
var preset = iD.presetPreset('test', {fields: ['field']}, {field: field});
expect(preset.setTags({}, 'point')).to.eql({});
});
@@ -111,9 +121,10 @@ describe('iD.presetPreset', function() {
describe('for a preset with a tag in areaKeys', function() {
it('doesn\'t add area=yes automatically', function() {
var preset = iD.presetPreset('test', {geometry: ['area'], tags: {name: 'testname', natural: 'water'}});
expect(preset.setTags({}, 'area')).to.eql({name: 'testname', natural: 'water'});
var preset = iD.presetPreset('test', {geometry: ['area'], tags: {name: 'testname', building: 'yes'}});
expect(preset.setTags({}, 'area')).to.eql({name: 'testname', building: 'yes'});
});
it('does add area=yes if asked to', function() {
var preset = iD.presetPreset('test', {geometry: ['area'], tags: {name: 'testname', area: 'yes'}});
expect(preset.setTags({}, 'area')).to.eql({name: 'testname', area: 'yes'});
+97 -97
View File
@@ -13,7 +13,7 @@ describe('iD.Features', function() {
}
beforeEach(function() {
context = iD.Context();
context = iD.coreContext();
d3.select(document.createElement('div'))
.attr('id', 'map')
.call(context.map());
@@ -63,16 +63,16 @@ describe('iD.Features', function() {
describe('#gatherStats', function() {
it('counts features', function() {
var graph = iD.Graph([
iD.Node({id: 'point_bar', tags: {amenity: 'bar'}, version: 1}),
iD.Node({id: 'point_dock', tags: {waterway: 'dock'}, version: 1}),
iD.Node({id: 'point_rail_station', tags: {railway: 'station'}, version: 1}),
iD.Node({id: 'point_generator', tags: {power: 'generator'}, version: 1}),
iD.Node({id: 'point_old_rail_station', tags: {railway: 'station', disused: 'yes'}, version: 1}),
iD.Way({id: 'motorway', tags: {highway: 'motorway'}, version: 1}),
iD.Way({id: 'building_yes', tags: {area: 'yes', amenity: 'school', building: 'yes'}, version: 1}),
iD.Way({id: 'boundary', tags: {boundary: 'administrative'}, version: 1}),
iD.Way({id: 'fence', tags: {barrier: 'fence'}, version: 1})
var graph = iD.coreGraph([
iD.osmNode({id: 'point_bar', tags: {amenity: 'bar'}, version: 1}),
iD.osmNode({id: 'point_dock', tags: {waterway: 'dock'}, version: 1}),
iD.osmNode({id: 'point_rail_station', tags: {railway: 'station'}, version: 1}),
iD.osmNode({id: 'point_generator', tags: {power: 'generator'}, version: 1}),
iD.osmNode({id: 'point_old_rail_station', tags: {railway: 'station', disused: 'yes'}, version: 1}),
iD.osmWay({id: 'motorway', tags: {highway: 'motorway'}, version: 1}),
iD.osmWay({id: 'building_yes', tags: {area: 'yes', amenity: 'school', building: 'yes'}, version: 1}),
iD.osmWay({id: 'boundary', tags: {boundary: 'administrative'}, version: 1}),
iD.osmWay({id: 'fence', tags: {barrier: 'fence'}, version: 1})
]),
all = _values(graph.base().entities),
stats;
@@ -96,64 +96,64 @@ describe('iD.Features', function() {
});
describe('matching', function() {
var graph = iD.Graph([
var graph = iD.coreGraph([
// Points
iD.Node({id: 'point_bar', tags: {amenity: 'bar'}, version: 1}),
iD.Node({id: 'point_dock', tags: {waterway: 'dock'}, version: 1}),
iD.Node({id: 'point_rail_station', tags: {railway: 'station'}, version: 1}),
iD.Node({id: 'point_generator', tags: {power: 'generator'}, version: 1}),
iD.Node({id: 'point_old_rail_station', tags: {railway: 'station', disused: 'yes'}, version: 1}),
iD.osmNode({id: 'point_bar', tags: {amenity: 'bar'}, version: 1}),
iD.osmNode({id: 'point_dock', tags: {waterway: 'dock'}, version: 1}),
iD.osmNode({id: 'point_rail_station', tags: {railway: 'station'}, version: 1}),
iD.osmNode({id: 'point_generator', tags: {power: 'generator'}, version: 1}),
iD.osmNode({id: 'point_old_rail_station', tags: {railway: 'station', disused: 'yes'}, version: 1}),
// Traffic Roads
iD.Way({id: 'motorway', tags: {highway: 'motorway'}, version: 1}),
iD.Way({id: 'motorway_link', tags: {highway: 'motorway_link'}, version: 1}),
iD.Way({id: 'trunk', tags: {highway: 'trunk'}, version: 1}),
iD.Way({id: 'trunk_link', tags: {highway: 'trunk_link'}, version: 1}),
iD.Way({id: 'primary', tags: {highway: 'primary'}, version: 1}),
iD.Way({id: 'primary_link', tags: {highway: 'primary_link'}, version: 1}),
iD.Way({id: 'secondary', tags: {highway: 'secondary'}, version: 1}),
iD.Way({id: 'secondary_link', tags: {highway: 'secondary_link'}, version: 1}),
iD.Way({id: 'tertiary', tags: {highway: 'tertiary'}, version: 1}),
iD.Way({id: 'tertiary_link', tags: {highway: 'tertiary_link'}, version: 1}),
iD.Way({id: 'residential', tags: {highway: 'residential'}, version: 1}),
iD.Way({id: 'unclassified', tags: {highway: 'unclassified'}, version: 1}),
iD.Way({id: 'living_street', tags: {highway: 'living_street'}, version: 1}),
iD.osmWay({id: 'motorway', tags: {highway: 'motorway'}, version: 1}),
iD.osmWay({id: 'motorway_link', tags: {highway: 'motorway_link'}, version: 1}),
iD.osmWay({id: 'trunk', tags: {highway: 'trunk'}, version: 1}),
iD.osmWay({id: 'trunk_link', tags: {highway: 'trunk_link'}, version: 1}),
iD.osmWay({id: 'primary', tags: {highway: 'primary'}, version: 1}),
iD.osmWay({id: 'primary_link', tags: {highway: 'primary_link'}, version: 1}),
iD.osmWay({id: 'secondary', tags: {highway: 'secondary'}, version: 1}),
iD.osmWay({id: 'secondary_link', tags: {highway: 'secondary_link'}, version: 1}),
iD.osmWay({id: 'tertiary', tags: {highway: 'tertiary'}, version: 1}),
iD.osmWay({id: 'tertiary_link', tags: {highway: 'tertiary_link'}, version: 1}),
iD.osmWay({id: 'residential', tags: {highway: 'residential'}, version: 1}),
iD.osmWay({id: 'unclassified', tags: {highway: 'unclassified'}, version: 1}),
iD.osmWay({id: 'living_street', tags: {highway: 'living_street'}, version: 1}),
// Service Roads
iD.Way({id: 'service', tags: {highway: 'service'}, version: 1}),
iD.Way({id: 'road', tags: {highway: 'road'}, version: 1}),
iD.Way({id: 'track', tags: {highway: 'track'}, version: 1}),
iD.osmWay({id: 'service', tags: {highway: 'service'}, version: 1}),
iD.osmWay({id: 'road', tags: {highway: 'road'}, version: 1}),
iD.osmWay({id: 'track', tags: {highway: 'track'}, version: 1}),
// Paths
iD.Way({id: 'path', tags: {highway: 'path'}, version: 1}),
iD.Way({id: 'footway', tags: {highway: 'footway'}, version: 1}),
iD.Way({id: 'cycleway', tags: {highway: 'cycleway'}, version: 1}),
iD.Way({id: 'bridleway', tags: {highway: 'bridleway'}, version: 1}),
iD.Way({id: 'steps', tags: {highway: 'steps'}, version: 1}),
iD.Way({id: 'pedestrian', tags: {highway: 'pedestrian'}, version: 1}),
iD.Way({id: 'corridor', tags: {highway: 'corridor'}, version: 1}),
iD.osmWay({id: 'path', tags: {highway: 'path'}, version: 1}),
iD.osmWay({id: 'footway', tags: {highway: 'footway'}, version: 1}),
iD.osmWay({id: 'cycleway', tags: {highway: 'cycleway'}, version: 1}),
iD.osmWay({id: 'bridleway', tags: {highway: 'bridleway'}, version: 1}),
iD.osmWay({id: 'steps', tags: {highway: 'steps'}, version: 1}),
iD.osmWay({id: 'pedestrian', tags: {highway: 'pedestrian'}, version: 1}),
iD.osmWay({id: 'corridor', tags: {highway: 'corridor'}, version: 1}),
// Buildings
iD.Way({id: 'building_yes', tags: {area: 'yes', amenity: 'school', building: 'yes'}, version: 1}),
iD.Way({id: 'building_no', tags: {area: 'yes', amenity: 'school', building: 'no'}, version: 1}),
iD.Way({id: 'building_part', tags: { 'building:part': 'yes'}, version: 1}),
iD.Way({id: 'garage1', tags: {area: 'yes', amenity: 'parking', parking: 'multi-storey'}, version: 1}),
iD.Way({id: 'garage2', tags: {area: 'yes', amenity: 'parking', parking: 'sheds'}, version: 1}),
iD.Way({id: 'garage3', tags: {area: 'yes', amenity: 'parking', parking: 'carports'}, version: 1}),
iD.Way({id: 'garage4', tags: {area: 'yes', amenity: 'parking', parking: 'garage_boxes'}, version: 1}),
iD.osmWay({id: 'building_yes', tags: {area: 'yes', amenity: 'school', building: 'yes'}, version: 1}),
iD.osmWay({id: 'building_no', tags: {area: 'yes', amenity: 'school', building: 'no'}, version: 1}),
iD.osmWay({id: 'building_part', tags: { 'building:part': 'yes'}, version: 1}),
iD.osmWay({id: 'garage1', tags: {area: 'yes', amenity: 'parking', parking: 'multi-storey'}, version: 1}),
iD.osmWay({id: 'garage2', tags: {area: 'yes', amenity: 'parking', parking: 'sheds'}, version: 1}),
iD.osmWay({id: 'garage3', tags: {area: 'yes', amenity: 'parking', parking: 'carports'}, version: 1}),
iD.osmWay({id: 'garage4', tags: {area: 'yes', amenity: 'parking', parking: 'garage_boxes'}, version: 1}),
// Landuse
iD.Way({id: 'forest', tags: {area: 'yes', landuse: 'forest'}, version: 1}),
iD.Way({id: 'scrub', tags: {area: 'yes', natural: 'scrub'}, version: 1}),
iD.Way({id: 'industrial', tags: {area: 'yes', landuse: 'industrial'}, version: 1}),
iD.Way({id: 'parkinglot', tags: {area: 'yes', amenity: 'parking', parking: 'surface'}, version: 1}),
iD.osmWay({id: 'forest', tags: {area: 'yes', landuse: 'forest'}, version: 1}),
iD.osmWay({id: 'scrub', tags: {area: 'yes', natural: 'scrub'}, version: 1}),
iD.osmWay({id: 'industrial', tags: {area: 'yes', landuse: 'industrial'}, version: 1}),
iD.osmWay({id: 'parkinglot', tags: {area: 'yes', amenity: 'parking', parking: 'surface'}, version: 1}),
// Landuse Multipolygon
iD.Way({id: 'outer', version: 1}),
iD.Way({id: 'inner1', version: 1}),
iD.Way({id: 'inner2', tags: {barrier: 'fence'}, version: 1}),
iD.Way({id: 'inner3', tags: {highway: 'residential'}, version: 1}),
iD.Relation({id: 'retail', tags: {landuse: 'retail', type: 'multipolygon'},
iD.osmWay({id: 'outer', version: 1}),
iD.osmWay({id: 'inner1', version: 1}),
iD.osmWay({id: 'inner2', tags: {barrier: 'fence'}, version: 1}),
iD.osmWay({id: 'inner3', tags: {highway: 'residential'}, version: 1}),
iD.osmRelation({id: 'retail', tags: {landuse: 'retail', type: 'multipolygon'},
members: [
{id: 'outer', role: 'outer', type: 'way'},
{id: 'inner1', role: 'inner', type: 'way'},
@@ -164,40 +164,40 @@ describe('iD.Features', function() {
}),
// Boundaries
iD.Way({id: 'boundary', tags: {boundary: 'administrative'}, version: 1}),
iD.Way({id: 'boundary_road', tags: {boundary: 'administrative', highway: 'primary'}, version: 1}),
iD.osmWay({id: 'boundary', tags: {boundary: 'administrative'}, version: 1}),
iD.osmWay({id: 'boundary_road', tags: {boundary: 'administrative', highway: 'primary'}, version: 1}),
// Water
iD.Way({id: 'water', tags: {area: 'yes', natural: 'water'}, version: 1}),
iD.Way({id: 'coastline', tags: {natural: 'coastline'}, version: 1}),
iD.Way({id: 'bay', tags: {area: 'yes', natural: 'bay'}, version: 1}),
iD.Way({id: 'pond', tags: {area: 'yes', landuse: 'pond'}, version: 1}),
iD.Way({id: 'basin', tags: {area: 'yes', landuse: 'basin'}, version: 1}),
iD.Way({id: 'reservoir', tags: {area: 'yes', landuse: 'reservoir'}, version: 1}),
iD.Way({id: 'salt_pond', tags: {area: 'yes', landuse: 'salt_pond'}, version: 1}),
iD.Way({id: 'river', tags: {waterway: 'river'}, version: 1}),
iD.osmWay({id: 'water', tags: {area: 'yes', natural: 'water'}, version: 1}),
iD.osmWay({id: 'coastline', tags: {natural: 'coastline'}, version: 1}),
iD.osmWay({id: 'bay', tags: {area: 'yes', natural: 'bay'}, version: 1}),
iD.osmWay({id: 'pond', tags: {area: 'yes', landuse: 'pond'}, version: 1}),
iD.osmWay({id: 'basin', tags: {area: 'yes', landuse: 'basin'}, version: 1}),
iD.osmWay({id: 'reservoir', tags: {area: 'yes', landuse: 'reservoir'}, version: 1}),
iD.osmWay({id: 'salt_pond', tags: {area: 'yes', landuse: 'salt_pond'}, version: 1}),
iD.osmWay({id: 'river', tags: {waterway: 'river'}, version: 1}),
// Rail
iD.Way({id: 'railway', tags: {railway: 'rail'}, version: 1}),
iD.Way({id: 'rail_landuse', tags: {area: 'yes', landuse: 'railway'}, version: 1}),
iD.Way({id: 'rail_disused', tags: {railway: 'disused'}, version: 1}),
iD.Way({id: 'rail_streetcar', tags: {railway: 'tram', highway: 'residential'}, version: 1}),
iD.Way({id: 'rail_trail', tags: {railway: 'disused', highway: 'cycleway'}, version: 1}),
iD.osmWay({id: 'railway', tags: {railway: 'rail'}, version: 1}),
iD.osmWay({id: 'rail_landuse', tags: {area: 'yes', landuse: 'railway'}, version: 1}),
iD.osmWay({id: 'rail_disused', tags: {railway: 'disused'}, version: 1}),
iD.osmWay({id: 'rail_streetcar', tags: {railway: 'tram', highway: 'residential'}, version: 1}),
iD.osmWay({id: 'rail_trail', tags: {railway: 'disused', highway: 'cycleway'}, version: 1}),
// Power
iD.Way({id: 'power_line', tags: {power: 'line'}, version: 1}),
iD.osmWay({id: 'power_line', tags: {power: 'line'}, version: 1}),
// Past/Future
iD.Way({id: 'motorway_construction', tags: {highway: 'construction', construction: 'motorway'}, version: 1}),
iD.Way({id: 'cycleway_proposed', tags: {highway: 'proposed', proposed: 'cycleway'}, version: 1}),
iD.Way({id: 'landuse_construction', tags: {area: 'yes', landuse: 'construction'}, version: 1}),
iD.osmWay({id: 'motorway_construction', tags: {highway: 'construction', construction: 'motorway'}, version: 1}),
iD.osmWay({id: 'cycleway_proposed', tags: {highway: 'proposed', proposed: 'cycleway'}, version: 1}),
iD.osmWay({id: 'landuse_construction', tags: {area: 'yes', landuse: 'construction'}, version: 1}),
// Others
iD.Way({id: 'fence', tags: {barrier: 'fence'}, version: 1}),
iD.Way({id: 'pipeline', tags: {man_made: 'pipeline'}, version: 1}),
iD.osmWay({id: 'fence', tags: {barrier: 'fence'}, version: 1}),
iD.osmWay({id: 'pipeline', tags: {man_made: 'pipeline'}, version: 1}),
// Site relation
iD.Relation({id: 'site', tags: {type: 'site'},
iD.osmRelation({id: 'site', tags: {type: 'site'},
members: [
{id: 'fence', role: 'perimeter'},
{id: 'building_yes'}
@@ -435,10 +435,10 @@ describe('iD.Features', function() {
describe('hiding', function() {
it('hides child vertices on a hidden way', function() {
var a = iD.Node({id: 'a', version: 1}),
b = iD.Node({id: 'b', version: 1}),
w = iD.Way({id: 'w', nodes: [a.id, b.id], tags: {highway: 'path'}, version: 1}),
graph = iD.Graph([a, b, w]),
var a = iD.osmNode({id: 'a', version: 1}),
b = iD.osmNode({id: 'b', version: 1}),
w = iD.osmWay({id: 'w', nodes: [a.id, b.id], tags: {highway: 'path'}, version: 1}),
graph = iD.coreGraph([a, b, w]),
geometry = a.geometry(graph),
all = _values(graph.base().entities);
@@ -452,11 +452,11 @@ describe('iD.Features', function() {
});
it('hides uninteresting (e.g. untagged or "other") member ways on a hidden multipolygon relation', function() {
var outer = iD.Way({id: 'outer', tags: {area: 'yes', natural: 'wood'}, version: 1}),
inner1 = iD.Way({id: 'inner1', tags: {barrier: 'fence'}, version: 1}),
inner2 = iD.Way({id: 'inner2', version: 1}),
inner3 = iD.Way({id: 'inner3', tags: {highway: 'residential'}, version: 1}),
r = iD.Relation({
var outer = iD.osmWay({id: 'outer', tags: {area: 'yes', natural: 'wood'}, version: 1}),
inner1 = iD.osmWay({id: 'inner1', tags: {barrier: 'fence'}, version: 1}),
inner2 = iD.osmWay({id: 'inner2', version: 1}),
inner3 = iD.osmWay({id: 'inner3', tags: {highway: 'residential'}, version: 1}),
r = iD.osmRelation({
id: 'r',
tags: {type: 'multipolygon'},
members: [
@@ -467,7 +467,7 @@ describe('iD.Features', function() {
],
version: 1
}),
graph = iD.Graph([outer, inner1, inner2, inner3, r]),
graph = iD.coreGraph([outer, inner1, inner2, inner3, r]),
all = _values(graph.base().entities);
features.disable('landuse');
@@ -480,9 +480,9 @@ describe('iD.Features', function() {
});
it('hides only versioned entities', function() {
var a = iD.Node({id: 'a', version: 1}),
b = iD.Node({id: 'b'}),
graph = iD.Graph([a, b]),
var a = iD.osmNode({id: 'a', version: 1}),
b = iD.osmNode({id: 'b'}),
graph = iD.coreGraph([a, b]),
ageo = a.geometry(graph),
bgeo = b.geometry(graph),
all = _values(graph.base().entities);
@@ -495,12 +495,12 @@ describe('iD.Features', function() {
});
it('auto-hides features', function() {
var graph = iD.Graph([]),
var graph = iD.coreGraph([]),
maxPoints = 200,
all, hidden, autoHidden, i, msg;
for (i = 0; i < maxPoints; i++) {
graph.rebase([iD.Node({version: 1})], [graph]);
graph.rebase([iD.osmNode({version: 1})], [graph]);
}
all = _values(graph.base().entities);
@@ -512,7 +512,7 @@ describe('iD.Features', function() {
expect(hidden, msg).to.not.include('points');
expect(autoHidden, msg).to.not.include('points');
graph.rebase([iD.Node({version: 1})], [graph]);
graph.rebase([iD.osmNode({version: 1})], [graph]);
all = _values(graph.base().entities);
features.gatherStats(all, graph, dimensions);
@@ -525,13 +525,13 @@ describe('iD.Features', function() {
});
it('doubles auto-hide threshold when doubling viewport size', function() {
var graph = iD.Graph([]),
var graph = iD.coreGraph([]),
maxPoints = 400,
dimensions = [2000, 1000],
all, hidden, autoHidden, i, msg;
for (i = 0; i < maxPoints; i++) {
graph.rebase([iD.Node({version: 1})], [graph]);
graph.rebase([iD.osmNode({version: 1})], [graph]);
}
all = _values(graph.base().entities);
@@ -543,7 +543,7 @@ describe('iD.Features', function() {
expect(hidden, msg).to.not.include('points');
expect(autoHidden, msg).to.not.include('points');
graph.rebase([iD.Node({version: 1})], [graph]);
graph.rebase([iD.osmNode({version: 1})], [graph]);
all = _values(graph.base().entities);
features.gatherStats(all, graph, dimensions);
+1 -1
View File
@@ -3,7 +3,7 @@ describe('iD.Map', function() {
beforeEach(function() {
content = d3.select('body').append('div');
context = iD.Context();
context = iD.coreContext();
map = context.map();
content.call(map);
});
+1 -1
View File
@@ -2,7 +2,7 @@ describe('iD.TileLayer', function() {
var context, d, c;
beforeEach(function() {
context = iD.Context();
context = iD.coreContext();
d = d3.select(document.createElement('div'));
c = iD.TileLayer(context).projection(d3.geoMercator());
});
+1 -1
View File
@@ -12,7 +12,7 @@ describe('iD.serviceMapillary', function() {
});
beforeEach(function() {
context = iD.Context().assetPath('../dist/');
context = iD.coreContext().assetPath('../dist/');
context.projection
.scale(667544.214430109) // z14
.translate([-116508, 0]) // 10,0
+33 -30
View File
@@ -1,14 +1,17 @@
describe('maprules', function() {
var _ruleChecks, validationRules;
var _ruleChecks, savedAreaKeys, validationRules;
before(function() {
savedAreaKeys = iD.areaKeys;
iD.setAreaKeys({ building: {}, amenity: {} });
iD.services.maprules = iD.serviceMapRules;
var areaKeys = iD.Context().presets().areaKeys();
iD.serviceMapRules.init(areaKeys);
iD.serviceMapRules.init();
_ruleChecks = iD.serviceMapRules.ruleChecks();
});
after(function() {
iD.setAreaKeys(savedAreaKeys);
delete iD.services.maprules;
});
@@ -23,7 +26,7 @@ describe('maprules', function() {
var filteredChecks = iD.serviceMapRules.filterRuleChecks(selector);
var equalsCheck = filteredChecks[0];
var absenceCheck = filteredChecks[1];
var entityTags = {amenity: 'marketplace'};
var entityTags = { amenity: 'marketplace' };
expect(filteredChecks.length).eql(2);
expect(equalsCheck(entityTags)).to.be.true;
@@ -146,7 +149,7 @@ describe('maprules', function() {
});
describe('#addRule', function() {
it ('builds a rule from provided selector and adds it to _validationRules', function () {
it('builds a rule from provided selector and adds it to _validationRules', function () {
var selector = {
geometry:'node',
equals: {amenity:'marketplace'},
@@ -159,7 +162,7 @@ describe('maprules', function() {
});
});
describe('#clearRules', function() {
it ('clears _validationRules array', function() {
it('clears _validationRules array', function() {
expect(iD.serviceMapRules.validationRules().length).to.eql(1);
iD.serviceMapRules.clearRules();
expect(iD.serviceMapRules.validationRules()).to.be.empty;
@@ -184,19 +187,19 @@ describe('maprules', function() {
describe('_ruleChecks', function () {
describe('#equals', function() {
it('is true when two tag maps intersect', function() {
var a = { amenity: 'school'};
var a = { amenity: 'school' };
var b = { amenity: 'school' };
expect(_ruleChecks.equals(a)(b)).to.be.true;
});
it('is false when two tag maps intersect', function() {
var a = { man_made: 'water_tap'};
var b = { amenity: 'school'};
var a = { man_made: 'water_tap' };
var b = { amenity: 'school' };
expect(_ruleChecks.equals(a)(b)).to.be.false;
});
});
describe('#notEquals', function() {
it('is true when two tag maps do not intersect', function() {
var a = { man_made: 'water_tap'};
var a = { man_made: 'water_tap' };
var b = { amenity: 'school' };
expect(_ruleChecks.notEquals(a)(b)).to.be.true;
});
@@ -427,15 +430,15 @@ describe('maprules', function() {
}
];
entities = [
iD.Entity({ type: 'node', tags: { amenity: 'marketplace' }}),
iD.Way({ tags: { building: 'house', amenity: 'clinic' }, nodes: [ 'a', 'b', 'c', 'a' ]}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', 'tower:type': 'communication', height: 5 }}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', height: 6 }}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', height: 9 }}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', height: 5 }}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', height: 10 }}),
iD.Way({ tags: { amenity: 'clinic', emergency: 'definitely' }, nodes: [ 'd', 'e', 'f', 'd' ]}),
iD.Way({ tags: { highway: 'residential', structure: 'bridge' }}),
iD.osmEntity({ type: 'node', tags: { amenity: 'marketplace' }}),
iD.osmWay({ tags: { building: 'house', amenity: 'clinic' }, nodes: [ 'a', 'b', 'c', 'a' ]}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', 'tower:type': 'communication', height: 5 }}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', height: 6 }}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', height: 9 }}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', height: 5 }}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', height: 10 }}),
iD.osmWay({ tags: { amenity: 'clinic', emergency: 'definitely' }, nodes: [ 'd', 'e', 'f', 'd' ]}),
iD.osmWay({ tags: { highway: 'residential', structure: 'bridge' }}),
];
iD.serviceMapRules.clearRules();
@@ -454,7 +457,7 @@ describe('maprules', function() {
positiveRegex: { structure: ['embarkment', 'bridge'] },
error: '\'suburban road\' structure tag cannot be \'bridge\' or \'tunnel\''
};
var entity = iD.Way({ tags: { highway: 'residential', structure: 'tunnel' }});
var entity = iD.osmWay({ tags: { highway: 'residential', structure: 'tunnel' }});
iD.serviceMapRules.clearRules();
iD.serviceMapRules.addRule(selector);
var rule = iD.serviceMapRules.validationRules()[0];
@@ -522,15 +525,15 @@ describe('maprules', function() {
}
];
entities = [
iD.Entity({ type: 'node', tags: { amenity: 'marketplace' }}),
iD.Way({ tags: { building: 'house', amenity: 'clinic' }, nodes: [ 'a', 'b', 'c', 'a' ]}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', 'tower:type': 'communication', height: 5 }}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', height: 6 }}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', height: 9 }}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', height: 5 }}),
iD.Entity({ type: 'node', tags: { man_made: 'tower', height: 10 }}),
iD.Way({ tags: { amenity: 'clinic', emergency: 'definitely' }, nodes: [ 'd', 'e', 'f', 'd' ]}),
iD.Way({ tags: { highway: 'residential', structure: 'bridge' }}),
iD.osmEntity({ type: 'node', tags: { amenity: 'marketplace' }}),
iD.osmWay({ tags: { building: 'house', amenity: 'clinic' }, nodes: [ 'a', 'b', 'c', 'a' ]}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', 'tower:type': 'communication', height: 5 }}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', height: 6 }}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', height: 9 }}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', height: 5 }}),
iD.osmEntity({ type: 'node', tags: { man_made: 'tower', height: 10 }}),
iD.osmWay({ tags: { amenity: 'clinic', emergency: 'definitely' }, nodes: [ 'd', 'e', 'f', 'd' ]}),
iD.osmWay({ tags: { highway: 'residential', structure: 'bridge' }}),
];
var wayNodes = [
@@ -541,7 +544,7 @@ describe('maprules', function() {
iD.osmNode({ id: 'e' }),
iD.osmNode({ id: 'f' }),
];
_graph = iD.Graph(entities.concat(wayNodes));
_graph = iD.coreGraph(entities.concat(wayNodes));
iD.serviceMapRules.clearRules();
selectors.forEach(function(selector) { iD.serviceMapRules.addRule(selector); });
validationRules = iD.serviceMapRules.validationRules();
+1 -1
View File
@@ -11,7 +11,7 @@ describe('iD.serviceOpenstreetcam', function() {
});
beforeEach(function() {
context = iD.Context().assetPath('../dist/');
context = iD.coreContext().assetPath('../dist/');
context.projection
.scale(667544.214430109) // z14
.translate([-116508, 0]) // 10,0
+15 -15
View File
@@ -27,7 +27,7 @@ describe('iD.serviceOsm', function () {
beforeEach(function () {
server = sinon.fakeServer.create();
context = iD.Context();
context = iD.coreContext();
connection = context.connection();
connection.switch({ urlroot: 'http://www.openstreetmap.org' });
connection.reset();
@@ -83,30 +83,30 @@ describe('iD.serviceOsm', function () {
describe('#entityURL', function() {
it('provides an entity url for a node', function() {
var e = iD.Node({id: 'n1'});
var e = iD.osmNode({id: 'n1'});
expect(connection.entityURL(e)).to.eql('http://www.openstreetmap.org/node/1');
});
it('provides an entity url for a way', function() {
var e = iD.Way({id: 'w1'});
var e = iD.osmWay({id: 'w1'});
expect(connection.entityURL(e)).to.eql('http://www.openstreetmap.org/way/1');
});
it('provides an entity url for a relation', function() {
var e = iD.Relation({id: 'r1'});
var e = iD.osmRelation({id: 'r1'});
expect(connection.entityURL(e)).to.eql('http://www.openstreetmap.org/relation/1');
});
});
describe('#historyURL', function() {
it('provides a history url for a node', function() {
var e = iD.Node({id: 'n1'});
var e = iD.osmNode({id: 'n1'});
expect(connection.historyURL(e)).to.eql('http://www.openstreetmap.org/node/1/history');
});
it('provides a history url for a way', function() {
var e = iD.Way({id: 'w1'});
var e = iD.osmWay({id: 'w1'});
expect(connection.historyURL(e)).to.eql('http://www.openstreetmap.org/way/1/history');
});
it('provides a history url for a relation', function() {
var e = iD.Relation({id: 'r1'});
var e = iD.osmRelation({id: 'r1'});
expect(connection.historyURL(e)).to.eql('http://www.openstreetmap.org/relation/1/history');
});
});
@@ -314,7 +314,7 @@ describe('iD.serviceOsm', function () {
var id = 'n1';
connection.loadEntity(id, function(err, result) {
var entity = result.data.find(function(e) { return e.id === id; });
expect(entity).to.be.an.instanceOf(iD.Node);
expect(entity).to.be.an.instanceOf(iD.osmNode);
done();
});
@@ -327,7 +327,7 @@ describe('iD.serviceOsm', function () {
var id = 'w1';
connection.loadEntity(id, function(err, result) {
var entity = result.data.find(function(e) { return e.id === id; });
expect(entity).to.be.an.instanceOf(iD.Way);
expect(entity).to.be.an.instanceOf(iD.osmWay);
done();
});
@@ -340,10 +340,10 @@ describe('iD.serviceOsm', function () {
var id = 'n1';
connection.loadEntity(id, function(err1, result1) {
var entity1 = result1.data.find(function(e1) { return e1.id === id; });
expect(entity1).to.be.an.instanceOf(iD.Node);
expect(entity1).to.be.an.instanceOf(iD.osmNode);
connection.loadEntity(id, function(err2, result2) {
var entity2 = result2.data.find(function(e2) { return e2.id === id; });
expect(entity2).to.be.an.instanceOf(iD.Node);
expect(entity2).to.be.an.instanceOf(iD.osmNode);
done();
});
server.respond();
@@ -376,7 +376,7 @@ describe('iD.serviceOsm', function () {
var id = 'n1';
connection.loadEntityVersion(id, 1, function(err, result) {
var entity = result.data.find(function(e) { return e.id === id; });
expect(entity).to.be.an.instanceOf(iD.Node);
expect(entity).to.be.an.instanceOf(iD.osmNode);
done();
});
@@ -389,7 +389,7 @@ describe('iD.serviceOsm', function () {
var id = 'w1';
connection.loadEntityVersion(id, 1, function(err, result) {
var entity = result.data.find(function(e) { return e.id === id; });
expect(entity).to.be.an.instanceOf(iD.Way);
expect(entity).to.be.an.instanceOf(iD.osmWay);
done();
});
@@ -402,10 +402,10 @@ describe('iD.serviceOsm', function () {
var id = 'n1';
connection.loadEntityVersion(id, 1, function(err1, result1) {
var entity1 = result1.data.find(function(e1) { return e1.id === id; });
expect(entity1).to.be.an.instanceOf(iD.Node);
expect(entity1).to.be.an.instanceOf(iD.osmNode);
connection.loadEntityVersion(id, 1, function(err2, result2) {
var entity2 = result2.data.find(function(e2) { return e2.id === id; });
expect(entity2).to.be.an.instanceOf(iD.Node);
expect(entity2).to.be.an.instanceOf(iD.osmNode);
done();
});
server.respond();
+1 -1
View File
@@ -11,7 +11,7 @@ describe('iD.serviceStreetside', function() {
});
beforeEach(function() {
context = iD.Context().assetPath('../dist/');
context = iD.coreContext().assetPath('../dist/');
context.projection
.scale(667544.214430109) // z14
.translate([-116508, 0]) // 10,0
+14
View File
@@ -6,6 +6,20 @@ iD.debug = true;
iD.data.imagery = [];
for (var k in iD.services) { delete iD.services[k]; }
// run with a minimal set of presets for speed
iD.data.presets = {
presets: {
area: { name: 'Area', tags: {}, geometry: ['area'] },
line: { name: 'Line', tags: {}, geometry: ['line'] },
point: { name: 'Point', tags: {}, geometry: ['point'] },
vertex: { name: 'Vertex', tags: {}, geometry: ['vertex'] },
relation: { name: 'Relation', tags: {}, geometry: ['relation'] },
// for tests related to areaKeys:
building: { name: 'Building', tags: { building: 'yes' }, geometry: ['area'] }
}
};
mocha.setup({
ui: 'bdd',
globals: [
+8 -6
View File
@@ -1,5 +1,5 @@
describe('iD.svgAreas', function () {
var context, surface;
var context, surface, savedAreaKeys;
var all = function() { return true; };
var none = function() { return false; };
var projection = d3.geoProjection(function(x, y) { return [x, -y]; })
@@ -15,13 +15,15 @@ describe('iD.svgAreas', function () {
.call(context.map().centerZoom([0, 0], 17));
surface = context.surface();
iD.setAreaKeys({
building: {},
landuse: {},
natural: {}
});
savedAreaKeys = iD.areaKeys;
iD.setAreaKeys({ building: {}, landuse: {}, natural: {} });
});
afterEach(function () {
iD.setAreaKeys(savedAreaKeys);
});
it('adds way and area classes', function () {
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
+6 -6
View File
@@ -1,8 +1,8 @@
describe('iD.svgRelationMemberTags', function() {
it('includes tags from parent multipolygon relations', function() {
var graph = iD.Graph([
iD.Way({id: 'w'}),
iD.Relation({id: 'r', members: [{id: 'w'}], tags: {type: 'multipolygon'}})
var graph = iD.coreGraph([
iD.osmWay({id: 'w'}),
iD.osmRelation({id: 'r', members: [{id: 'w'}], tags: {type: 'multipolygon'}})
]);
expect(iD.svgRelationMemberTags(graph)(graph.entity('w')))
@@ -10,9 +10,9 @@ describe('iD.svgRelationMemberTags', function() {
});
it('includes tags from parent boundary relations', function() {
var graph = iD.Graph([
iD.Way({id: 'w'}),
iD.Relation({id: 'r', members: [{id: 'w'}], tags: {type: 'boundary'}})
var graph = iD.coreGraph([
iD.osmWay({id: 'w'}),
iD.osmRelation({id: 'r', members: [{id: 'w'}], tags: {type: 'boundary'}})
]);
expect(iD.svgRelationMemberTags(graph)(graph.entity('w')))
+5 -2
View File
@@ -2,9 +2,12 @@ describe('iD.uiFieldAccess', function() {
var context, selection, field;
beforeEach(function() {
context = iD.Context();
context = iD.coreContext();
selection = d3.select(document.createElement('div'));
field = context.presets().field('access');
field = iD.presetField('access', {
keys: ['access', 'foot', 'motor_vehicle', 'bicycle', 'horse'],
type: 'access'
});
});
it('creates inputs for a variety of modes of access', function() {
+2 -2
View File
@@ -2,9 +2,9 @@ describe('iD.uiFieldLocalized', function() {
var context, selection, field;
beforeEach(function() {
context = iD.Context();
context = iD.coreContext();
selection = d3.select(document.createElement('div'));
field = iD.presetField('test', {key: 'name'});
field = iD.presetField('name', { key: 'name', type: 'localized' });
});
it('adds a blank set of fields when the + button is clicked', function() {
+11 -7
View File
@@ -2,10 +2,10 @@ describe('iD.uiFieldWikipedia', function() {
var entity, context, selection, field, server;
function changeTags(changed) {
var e = context.entity(entity.id),
annotation = 'Changed tags.',
tags = JSON.parse(JSON.stringify(e.tags)), // deep copy
didChange = false;
var e = context.entity(entity.id);
var annotation = 'Changed tags.';
var tags = JSON.parse(JSON.stringify(e.tags)); // deep copy
var didChange = false;
for (var k in changed) {
if (changed.hasOwnProperty(k)) {
@@ -43,11 +43,15 @@ describe('iD.uiFieldWikipedia', function() {
});
beforeEach(function() {
entity = iD.Node({id: 'n12345'});
context = iD.Context();
entity = iD.osmNode({id: 'n12345'});
context = iD.coreContext();
context.history().merge([entity]);
selection = d3.select(document.createElement('div'));
field = context.presets().field('wikipedia');
field = iD.presetField('wikipedia', {
key: 'wikipedia',
keys: ['wikipedia', 'wikidata'],
type: 'wikipedia'
});
server = createServer({ respondImmediately: true });
});
+2 -2
View File
@@ -15,8 +15,8 @@ describe('iD.uiRawTagEditor', function() {
}
beforeEach(function () {
entity = iD.Node({id: 'n12345'});
context = iD.Context();
entity = iD.osmNode({id: 'n12345'});
context = iD.coreContext();
context.history().merge([entity]);
render({highway: 'residential'});
});
+23 -23
View File
@@ -2,10 +2,10 @@ describe('iD.util', function() {
describe('utilGetAllNodes', function() {
it('gets all descendant nodes of a way', function() {
var a = iD.Node({ id: 'a' }),
b = iD.Node({ id: 'b' }),
w = iD.Way({ id: 'w', nodes: ['a','b','a'] }),
graph = iD.Graph([a, b, w]),
var a = iD.osmNode({ id: 'a' }),
b = iD.osmNode({ id: 'b' }),
w = iD.osmWay({ id: 'w', nodes: ['a','b','a'] }),
graph = iD.coreGraph([a, b, w]),
result = iD.utilGetAllNodes(['w'], graph);
expect(result).to.have.members([a, b]);
@@ -13,12 +13,12 @@ describe('iD.util', function() {
});
it('gets all descendant nodes of a relation', function() {
var a = iD.Node({ id: 'a' }),
b = iD.Node({ id: 'b' }),
c = iD.Node({ id: 'c' }),
w = iD.Way({ id: 'w', nodes: ['a','b','a'] }),
r = iD.Relation({ id: 'r', members: [{id: 'w'}, {id: 'c'}] }),
graph = iD.Graph([a, b, c, w, r]),
var a = iD.osmNode({ id: 'a' }),
b = iD.osmNode({ id: 'b' }),
c = iD.osmNode({ id: 'c' }),
w = iD.osmWay({ id: 'w', nodes: ['a','b','a'] }),
r = iD.osmRelation({ id: 'r', members: [{id: 'w'}, {id: 'c'}] }),
graph = iD.coreGraph([a, b, c, w, r]),
result = iD.utilGetAllNodes(['r'], graph);
expect(result).to.have.members([a, b, c]);
@@ -26,15 +26,15 @@ describe('iD.util', function() {
});
it('gets all descendant nodes of multiple ids', function() {
var a = iD.Node({ id: 'a' }),
b = iD.Node({ id: 'b' }),
c = iD.Node({ id: 'c' }),
d = iD.Node({ id: 'd' }),
e = iD.Node({ id: 'e' }),
w1 = iD.Way({ id: 'w1', nodes: ['a','b','a'] }),
w2 = iD.Way({ id: 'w2', nodes: ['c','b','a','c'] }),
r = iD.Relation({ id: 'r', members: [{id: 'w1'}, {id: 'd'}] }),
graph = iD.Graph([a, b, c, d, e, w1, w2, r]),
var a = iD.osmNode({ id: 'a' }),
b = iD.osmNode({ id: 'b' }),
c = iD.osmNode({ id: 'c' }),
d = iD.osmNode({ id: 'd' }),
e = iD.osmNode({ id: 'e' }),
w1 = iD.osmWay({ id: 'w1', nodes: ['a','b','a'] }),
w2 = iD.osmWay({ id: 'w2', nodes: ['c','b','a','c'] }),
r = iD.osmRelation({ id: 'r', members: [{id: 'w1'}, {id: 'd'}] }),
graph = iD.coreGraph([a, b, c, d, e, w1, w2, r]),
result = iD.utilGetAllNodes(['r', 'w2', 'e'], graph);
expect(result).to.have.members([a, b, c, d, e]);
@@ -42,10 +42,10 @@ describe('iD.util', function() {
});
it('handles recursive relations', function() {
var a = iD.Node({ id: 'a' }),
r1 = iD.Relation({ id: 'r1', members: [{id: 'r2'}] }),
r2 = iD.Relation({ id: 'r2', members: [{id: 'r1'}, {id: 'a'}] }),
graph = iD.Graph([a, r1, r2]),
var a = iD.osmNode({ id: 'a' }),
r1 = iD.osmRelation({ id: 'r1', members: [{id: 'r2'}] }),
r2 = iD.osmRelation({ id: 'r2', members: [{id: 'r1'}, {id: 'a'}] }),
graph = iD.coreGraph([a, r1, r2]),
result = iD.utilGetAllNodes(['r1'], graph);
expect(result).to.have.members([a]);