diff --git a/js/id/presets.js b/js/id/presets.js
index 284b0488f..ab7fa52de 100644
--- a/js/id/presets.js
+++ b/js/id/presets.js
@@ -5,7 +5,6 @@ iD.presets = function(context) {
var other = {
name: 'other',
- title: 'Other',
icon: 'marker-stroked',
match: {
tags: {},
diff --git a/js/id/presets/preset.js b/js/id/presets/preset.js
index 3d4d063e0..f7cf8ba6c 100644
--- a/js/id/presets/preset.js
+++ b/js/id/presets/preset.js
@@ -45,6 +45,7 @@ iD.presets.Preset = function(preset, forms) {
tags[f.key] = f['default'][geometry];
}
}
+ return tags;
};
return preset;
diff --git a/test/index.html b/test/index.html
index ccee7e85c..b64c2f2f2 100644
--- a/test/index.html
+++ b/test/index.html
@@ -252,6 +252,8 @@
+
+
diff --git a/test/spec/presets/preset.js b/test/spec/presets/preset.js
new file mode 100644
index 000000000..0e6b15652
--- /dev/null
+++ b/test/spec/presets/preset.js
@@ -0,0 +1,140 @@
+describe('iD.presets.Preset', function() {
+
+ var forms = {
+ "building_area": {
+ "key": "building",
+ "type": "check",
+ "default": { "area": "yes" }
+ }
+ };
+
+ var p = {
+ other: iD.presets.Preset({
+ name: 'other',
+ match: {
+ tags: {},
+ type: ['point', 'vertex', 'line', 'area']
+ }
+ }),
+ residential: iD.presets.Preset({
+ name: 'residential',
+ match: {
+ tags: {
+ highway: 'residential'
+ },
+ type: ['line']
+ }
+ }),
+ tennis: iD.presets.Preset({
+ name: 'tennis',
+ match: {
+ tags: {
+ leisure: 'pitch',
+ sport: 'tennis'
+ },
+ type: ['area']
+ }
+ }),
+ building: iD.presets.Preset({
+ name: 'building',
+ match: {
+ tags: {
+ building: '*'
+ },
+ type: ['area']
+ }
+ }),
+ cafe: iD.presets.Preset({
+ name: 'cafe',
+ match: {
+ tags: {
+ amenity: 'cafe'
+ },
+ type: ['point', 'area']
+ },
+ form: ['building_area']
+ }, forms)
+ };
+ var w1 = iD.Way({ tags: {
+ highway: 'motorway'
+ }}),
+ w2 = iD.Way({ tags: {
+ leisure: 'pitch',
+ sport: 'tennis'
+ }}),
+ w3 = iD.Way({ tags: {
+ highway: 'residential'
+ }}),
+ w4 = iD.Way({ tags: {
+ building: 'yep'
+ }}),
+ w5 = iD.Way(),
+ g = iD.Graph().replace(w1).replace(w2);
+
+
+ it("has an optional form field", function() {
+ expect(p.other.form).to.eql([]);
+ });
+
+ describe('#matchType', function() {
+ var n = iD.Node();
+ var g = iD.Graph().replace(p);
+ it("returns false if it doesn't match the entity type", function() {
+ expect(p.residential.matchType(n, g)).to.equal(false);
+ });
+
+ it("returns true if it does match the entity type", function() {
+ expect(p.other.matchType(n, g)).to.equal(true);
+ });
+ });
+
+ describe('#matchTags', function() {
+ it("returns -1 if preset does not match tags", function() {
+ expect(p.residential.matchTags(w1)).to.equal(-1);
+ });
+
+ it("returns 0 for other preset (no match tags)", function() {
+ expect(p.other.matchTags(w1)).to.equal(0);
+ });
+
+ it("returns the number of matched tags", function() {
+ expect(p.residential.matchTags(w3)).to.equal(1);
+ expect(p.tennis.matchTags(w2)).to.equal(2);
+ });
+
+ it("counts * as a match for any value", function() {
+ expect(p.building.matchTags(w4)).to.equal(1);
+ expect(p.building.matchTags(w5)).to.equal(-1);
+ });
+
+ });
+
+ describe('#applyTags', function() {
+
+ it("adds match tags", function() {
+ expect(p.residential.applyTags({}, 'area')).to.eql({ highway: 'residential' });
+ });
+
+ it("does not add wildcard tags", function() {
+ expect(p.building.applyTags({}, 'area')).to.eql({});
+ });
+
+ it("adds default tags", function() {
+ expect(p.cafe.applyTags({}, 'area')).to.eql({ amenity: 'cafe', building: 'yes'});
+ expect(p.cafe.applyTags({}, 'point')).to.eql({ amenity: 'cafe' });
+ });
+ });
+
+ describe('#removeTags', function() {
+
+ it('removes match tags', function() {
+ expect(p.residential.removeTags({ highway: 'residential' }, 'area')).to.eql({});
+ });
+
+ it('removes default tags', function() {
+ expect(p.cafe.removeTags({ amenity: 'cafe', building: 'yes'}, 'area')).to.eql({});
+ expect(p.cafe.removeTags({ amenity: 'cafe', building: 'yep'}, 'area')).to.eql({ building: 'yep'});
+ });
+ });
+
+});