From 191f52d634f683753c10f01ecedea3c71a1a7cb8 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 28 Oct 2013 17:39:34 -0700 Subject: [PATCH] Use assumed values for access placeholders (fixes #1924) --- js/id/ui/preset/access.js | 79 +++++++++++++++++++++++++++++++---- test/spec/ui/preset/access.js | 53 ++++++++++++++++++++++- 2 files changed, 123 insertions(+), 9 deletions(-) diff --git a/js/id/ui/preset/access.js b/js/id/ui/preset/access.js index a875150a8..7b1346717 100644 --- a/js/id/ui/preset/access.js +++ b/js/id/ui/preset/access.js @@ -1,6 +1,5 @@ iD.ui.preset.access = function(field) { var event = d3.dispatch('change'), - entity, items; function access(selection) { @@ -64,18 +63,84 @@ iD.ui.preset.access = function(field) { }); }; - access.entity = function(_) { - if (!arguments.length) return entity; - entity = _; - return access; + var placeholders = { + footway: { + foot: 'yes', + motor_vehicle: 'no' + }, + steps: { + foot: 'yes', + motor_vehicle: 'no' + }, + pedestrian: { + foot: 'yes', + motor_vehicle: 'no' + }, + cycleway: { + bicycle: 'yes', + motor_vehicle: 'no' + }, + bridleway: { + horse: 'yes' + }, + path: { + motor_vehicle: 'no' + }, + motorway: { + motor_vehicle: 'yes' + }, + trunk: { + motor_vehicle: 'yes' + }, + primary: { + motor_vehicle: 'yes' + }, + secondary: { + motor_vehicle: 'yes' + }, + tertiary: { + motor_vehicle: 'yes' + }, + residential: { + motor_vehicle: 'yes' + }, + unclassified: { + motor_vehicle: 'yes' + }, + service: { + motor_vehicle: 'yes' + }, + motorway_link: { + motor_vehicle: 'yes' + }, + trunk_link: { + motor_vehicle: 'yes' + }, + primary_link: { + motor_vehicle: 'yes' + }, + secondary_link: { + motor_vehicle: 'yes' + }, + tertiary_link: { + motor_vehicle: 'yes' + } }; access.tags = function(tags) { items.selectAll('.preset-input-access') .value(function(d) { return tags[d] || ''; }) - .attr('placeholder', function(d) { - return d !== 'access' && tags.access ? tags.access : field.placeholder(); + .attr('placeholder', function() { + return tags.access ? tags.access : field.placeholder(); }); + + items.selectAll('#preset-input-access-access') + .attr('placeholder', 'yes'); + + _.forEach(placeholders[tags.highway], function(value, key) { + items.selectAll('#preset-input-access-' + key) + .attr('placeholder', value); + }); }; access.focus = function() { diff --git a/test/spec/ui/preset/access.js b/test/spec/ui/preset/access.js index ecfc30754..90b9ca6c5 100644 --- a/test/spec/ui/preset/access.js +++ b/test/spec/ui/preset/access.js @@ -7,7 +7,7 @@ describe('iD.ui.preset.access', function() { }); it('creates inputs for a variety of modes of access', function() { - var access = iD.ui.preset.access(field, {}); + var access = iD.ui.preset.access(field); selection.call(access); expect(selection.selectAll('.preset-access-access')[0].length).to.equal(1); expect(selection.selectAll('.preset-access-foot')[0].length).to.equal(1); @@ -17,7 +17,56 @@ describe('iD.ui.preset.access', function() { }); it('does not include a "yes" option for general access (#934)', function() { - var access = iD.ui.preset.access(field, {}); + var access = iD.ui.preset.access(field); expect(_.pluck(access.options('access'), 'value')).not.to.include('yes'); }); + + it('sets foot placeholder to "yes" for footways, steps, and pedestrian', function() { + var access = iD.ui.preset.access(field); + selection.call(access); + + access.tags({highway: 'footway'}); + expect(selection.selectAll('#preset-input-access-foot').attr('placeholder')).to.equal('yes'); + + access.tags({highway: 'steps'}); + expect(selection.selectAll('#preset-input-access-foot').attr('placeholder')).to.equal('yes'); + + access.tags({highway: 'pedestrian'}); + expect(selection.selectAll('#preset-input-access-foot').attr('placeholder')).to.equal('yes'); + }); + + it('sets bicycle placeholder to "yes" for cycleways', function() { + var access = iD.ui.preset.access(field); + selection.call(access); + + access.tags({highway: 'cycleway'}); + expect(selection.selectAll('#preset-input-access-bicycle').attr('placeholder')).to.equal('yes'); + }); + + it('sets horse placeholder to "yes" for bridleways', function() { + var access = iD.ui.preset.access(field); + selection.call(access); + + access.tags({highway: 'bridleway'}); + expect(selection.selectAll('#preset-input-access-horse').attr('placeholder')).to.equal('yes'); + }); + + it('sets motor_vehicle placeholder to "no" for footways, steps, pedestrian, cycleway, and path', function() { + var access = iD.ui.preset.access(field); + selection.call(access); + ['footway', 'steps', 'pedestrian', 'cycleway', 'path'].forEach(function(value) { + access.tags({highway: value}); + expect(selection.selectAll('#preset-input-access-motor_vehicle').attr('placeholder')).to.equal('no'); + }); + }); + + it('sets motor_vehicle placeholder to "yes" for various other highway tags', function() { + var access = iD.ui.preset.access(field); + selection.call(access); + ['residential', 'motorway', 'trunk', 'primary', 'secondary', 'tertiary', 'service', + 'unclassified', 'motorway_link', 'trunk_link', 'primary_link', 'secondary_link', 'tertiary_link'].forEach(function(value) { + access.tags({highway: value}); + expect(selection.selectAll('#preset-input-access-motor_vehicle').attr('placeholder')).to.equal('yes'); + }); + }); });