From 659a291e8982e48868398d780379e4dee9bbd8d0 Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Tue, 17 Jul 2018 16:43:00 -0400 Subject: [PATCH] add core overwrite for external preset source ref #remote-presets --- modules/core/context.js | 2 +- modules/presets/index.js | 14 +++++++++---- test/spec/presets/index.js | 42 +++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/modules/core/context.js b/modules/core/context.js index 4d758066e..00e9103d0 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -306,7 +306,7 @@ export function coreContext() { /* Presets */ var presets; context.presets = function() { return presets; }; - + context.overwritePresets = function(newPresets) { presets.overwrite(newPresets); }; /* Map */ var map; diff --git a/modules/presets/index.js b/modules/presets/index.js index 789c3cb9c..6edeb6f55 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -118,10 +118,7 @@ export function presetIndex() { return areaKeys; }; - - all.init = function() { - var d = data.presets; - + all.build = function (d) { all.collection = []; _recent.collection = []; _fields = {}; @@ -172,6 +169,15 @@ export function presetIndex() { } } + }; + + all.overwrite = function (d) { + all.build(d); + return all; + }; + + all.init = function() { + all.build(data.presets); return all; }; diff --git a/test/spec/presets/index.js b/test/spec/presets/index.js index 9178a4519..248c4e132 100644 --- a/test/spec/presets/index.js +++ b/test/spec/presets/index.js @@ -156,7 +156,47 @@ describe('iD.presetIndex', function() { }); }); - + describe('#overwrite', function() { + it('overwrites iD presets with provided list of presets', 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'] + } + } + }; + var currentPresets = iD.Context().presets(); + var overwrittenPresets = iD.Context().overwritePresets(testPresets); + expect(currentPresets).to.not.eql(overwrittenPresets); + }); + }); + describe('expected matches', function() { it('prefers building to multipolygon', function() {