Merge pull request #6389 from openstreetmap/wikidata-style

Support special styling for Wikidata-tagged features
This commit is contained in:
Bryan Housel
2019-05-20 18:05:29 -04:00
committed by GitHub
13 changed files with 239 additions and 161 deletions
+1
View File
@@ -55,6 +55,7 @@ module.exports = function buildData() {
// Font Awesome icons used
var faIcons = {
'fas-i-cursor': {},
'fas-lock': {},
'fas-long-arrow-alt-right': {},
'fas-th-list': {}
};
+10
View File
@@ -105,6 +105,7 @@ g.point .stroke {
fill: #fff;
}
g.qa_error .shadow,
g.point .shadow,
g.note .shadow {
@@ -282,6 +283,15 @@ text.point {
opacity: 0.8;
}
/* Wikidata-tagged */
g.point.tag-wikidata path.stroke {
stroke-width: 3px;
stroke: #777;
fill: #ddd;
}
/* Highlighting */
g.point.highlighted .shadow,
path.shadow.highlighted {
+14 -3
View File
@@ -1528,6 +1528,15 @@ button.preset-favorite-button.active .icon {
padding: 5px 10px 5px 0;
}
.label-text .label-textannotation svg.icon {
margin: 0 10px;
color: #333;
opacity: 0.5;
width: 14px;
height: 14px;
vertical-align: text-top;
}
.field-label button {
flex: 0 0 32px;
border-left: 1px solid #ccc;
@@ -1548,11 +1557,13 @@ button.preset-favorite-button.active .icon {
}
.field-label .modified-icon,
.field-label .remove-icon {
.field-label .remove-icon,
.field-label .remove-icon-multilingual {
display: none;
}
.modified .field-label .modified-icon,
.present .field-label .remove-icon {
.modified:not(.locked) .field-label .modified-icon,
.present:not(.locked) .field-label .remove-icon,
.present:not(.locked) .field-label .remove-icon-multilingual {
display: inline-block;
}
+3
View File
@@ -174,6 +174,9 @@ osmEntity.prototype = {
return Object.keys(this.tags).some(osmIsInterestingTag);
},
hasWikidata: function() {
return !!this.tags.wikidata || !!this.tags['brand:wikidata'];
},
isHighwayIntersection: function() {
return false;
+3 -5
View File
@@ -127,11 +127,9 @@ export function svgPoints(projection, context) {
.attr('transform', svgPointTransform(projection))
.call(svgTagClasses());
// Selecting the following implicitly
// sets the data (point entity) on the element
groups.select('.shadow');
groups.select('.stroke');
groups.select('.icon')
groups.select('.shadow'); // propagate bound data
groups.select('.stroke'); // propagate bound data
groups.select('.icon') // propagate bound data
.attr('xlink:href', function(entity) {
var preset = context.presets().match(entity, graph);
var picon = preset && preset.icon;
+5
View File
@@ -139,6 +139,11 @@ export function svgTagClasses() {
}
}
// If this is a wikidata-tagged item, add a class for that..
if (t.wikidata || t['brand:wikidata']) {
classes.push('tag-wikidata');
}
return classes.join(' ').trim();
};
+58 -17
View File
@@ -1,13 +1,10 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import {
event as d3_event,
select as d3_select
} from 'd3-selection';
import { event as d3_event, select as d3_select } from 'd3-selection';
import { t } from '../util/locale';
import { textDirection } from '../util/locale';
import { svgIcon } from '../svg/icon';
import { tooltip } from '../util/tooltip';
import { uiFieldHelp } from './field_help';
import { uiFields } from './fields';
import { uiTagReference } from './tag_reference';
@@ -29,6 +26,12 @@ export function uiField(context, presetField, entity, options) {
var _state = '';
var _tags = {};
var _locked = false;
var _lockedTip = tooltip()
.title(t('inspector.lock.suggestion', { label: field.label }))
.placement('bottom');
field.keys = field.keys || [field.key];
// only create the fields that are actually being shown
@@ -81,7 +84,7 @@ export function uiField(context, presetField, entity, options) {
function revert(d) {
d3_event.stopPropagation();
d3_event.preventDefault();
if (!entity) return false;
if (!entity || _locked) return;
var original = context.graph().base().entities[entity.id];
var t = {};
@@ -96,6 +99,7 @@ export function uiField(context, presetField, entity, options) {
function remove(d) {
d3_event.stopPropagation();
d3_event.preventDefault();
if (_locked) return;
var t = {};
d.keys.forEach(function(key) {
@@ -117,18 +121,26 @@ export function uiField(context, presetField, entity, options) {
.classed('nowrap', !options.wrap);
if (options.wrap) {
var label = enter
var labelEnter = enter
.append('label')
.attr('class', 'field-label')
.attr('for', function(d) { return 'preset-input-' + d.safeid; });
label
var textEnter = labelEnter
.append('span')
.attr('class', 'label-text')
.attr('class', 'label-text');
textEnter
.append('span')
.attr('class', 'label-textvalue')
.text(function(d) { return d.label(); });
textEnter
.append('span')
.attr('class', 'label-textannotation');
if (options.remove) {
label
labelEnter
.append('button')
.attr('class', 'remove-icon')
.attr('title', t('icons.remove'))
@@ -137,7 +149,7 @@ export function uiField(context, presetField, entity, options) {
}
if (options.revert) {
label
labelEnter
.append('button')
.attr('class', 'modified-icon')
.attr('title', t('icons.undo'))
@@ -158,9 +170,9 @@ export function uiField(context, presetField, entity, options) {
.on('click', revert);
container
.classed('modified', isModified())
.classed('present', isPresent())
.each(function(d) {
var selection = d3_select(this);
if (!d.impl) {
createField();
}
@@ -185,12 +197,12 @@ export function uiField(context, presetField, entity, options) {
}
}
d3_select(this)
selection
.call(d.impl);
// add field help components
if (help) {
d3_select(this)
selection
.call(help.body)
.select('.field-label')
.call(help.button);
@@ -198,7 +210,7 @@ export function uiField(context, presetField, entity, options) {
// add tag reference components
if (reference) {
d3_select(this)
selection
.call(reference.body)
.select('.field-label')
.call(reference.button);
@@ -206,6 +218,29 @@ export function uiField(context, presetField, entity, options) {
d.impl.tags(_tags);
});
container
.classed('locked', _locked)
.classed('modified', isModified())
.classed('present', isPresent());
// show a tip and lock icon if the field is locked
var annotation = container.selectAll('.field-label .label-textannotation');
var icon = annotation.selectAll('.icon')
.data(_locked ? [0]: []);
icon.exit()
.remove();
icon.enter()
.append('svg')
.attr('class', 'icon')
.append('use')
.attr('xlink:href', '#fas-lock');
container.call(_locked ? _lockedTip : _lockedTip.destroy);
};
@@ -223,6 +258,13 @@ export function uiField(context, presetField, entity, options) {
};
field.locked = function(val) {
if (!arguments.length) return _locked;
_locked = val;
return field;
};
field.show = function() {
_show = true;
if (!field.impl) {
@@ -235,7 +277,6 @@ export function uiField(context, presetField, entity, options) {
}
};
// A shown field has a visible UI, a non-shown field is in the 'Add field' dropdown
field.isShown = function() {
return _show || isPresent();
+5 -27
View File
@@ -1,8 +1,5 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import {
select as d3_select,
event as d3_event
} from 'd3-selection';
import { select as d3_select, event as d3_event } from 'd3-selection';
import { t, textDirection } from '../../util/locale';
import { dataPhoneFormats } from '../../../data';
@@ -24,18 +21,11 @@ export function uiFieldText(field, context) {
var nominatim = services.geocoder;
var input = d3_select(null);
var _entity;
var _brandTip;
if (field.id === 'brand') {
_brandTip = tooltip()
.title(t('inspector.lock.suggestion', { label: field.label }))
.placement('bottom');
}
function i(selection) {
var preset = _entity && context.presets().match(_entity, context.graph());
var isSuggestion = preset && preset.suggestion && field.id === 'brand';
var isLocked = preset && preset.suggestion && field.id === 'brand';
field.locked(isLocked);
var wrap = selection.selectAll('.form-field-input-wrap')
.data([0]);
@@ -60,8 +50,8 @@ export function uiFieldText(field, context) {
.merge(input);
input
.classed('disabled', !!isSuggestion)
.attr('readonly', isSuggestion || null)
.classed('disabled', !!isLocked)
.attr('readonly', isLocked || null)
.on('input', change(true))
.on('blur', change())
.on('change', change());
@@ -102,18 +92,6 @@ export function uiFieldText(field, context) {
input.node().value = vals.join(';');
change()();
});
} else if (preset && field.id === 'brand') {
var pTag = preset.id.split('/', 2);
var pKey = pTag[0];
if (isSuggestion) {
// A "suggestion" preset (brand name)
// Put suggestion keys in `field.keys` so delete button can remove them all.
field.keys = Object.keys(preset.removeTags)
.filter(function(k) { return k !== pKey && k !== 'name'; });
}
wrap.call(isSuggestion ? _brandTip : _brandTip.destroy);
}
}
+29 -34
View File
@@ -1,10 +1,5 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import {
select as d3_select,
event as d3_event
} from 'd3-selection';
import { select as d3_select, event as d3_event } from 'd3-selection';
import { t } from '../../util/locale';
import { dataWikipedia } from '../../../data';
@@ -37,10 +32,6 @@ export function uiFieldLocalized(field, context) {
var _selection = d3_select(null);
var _multilingual = [];
var _isLocked = false;
var _brandTip = tooltip()
.title(t('inspector.lock.suggestion', { label: field.label }))
.placement('bottom');
var _buttonTip = tooltip()
.title(t('translate.translate'))
.placement('left');
@@ -50,13 +41,13 @@ export function uiFieldLocalized(field, context) {
function calcLocked() {
if (!_entity) { // the original entity
_isLocked = false;
field.locked(false);
return;
}
var latest = context.hasEntity(_entity.id);
if (!latest) { // get current entity, possibly edited
_isLocked = false;
field.locked(false);
return;
}
@@ -67,8 +58,10 @@ export function uiFieldLocalized(field, context) {
var showsBrand = preset && preset.fields
.filter(function(d) { return d.id === 'brand'; }).length;
_isLocked = !!(field.id === 'name' && hasOriginalName &&
var isLocked = !!(field.id === 'name' && hasOriginalName &&
(hasWikidata || (isSuggestion && !showsBrand)));
field.locked(isLocked);
}
@@ -87,6 +80,7 @@ export function uiFieldLocalized(field, context) {
function localized(selection) {
_selection = selection;
calcLocked();
var isLocked = field.locked();
var entity = _entity && context.hasEntity(_entity.id); // get latest
var preset = entity && context.presets().match(entity, context.graph());
@@ -97,9 +91,7 @@ export function uiFieldLocalized(field, context) {
wrap = wrap.enter()
.append('div')
.attr('class', 'form-field-input-wrap form-field-input-' + field.type)
.merge(wrap)
.call(_isLocked ? _brandTip : _brandTip.destroy);
.merge(wrap);
input = wrap.selectAll('.localized-main')
.data([0]);
@@ -119,13 +111,7 @@ export function uiFieldLocalized(field, context) {
var pKey = pTag[0];
var pValue = pTag[1];
if (preset.suggestion) {
// A "suggestion" preset (brand name)
// Put suggestion keys in `field.keys` so delete button can remove them all.
field.keys = Object.keys(preset.removeTags)
.filter(function(k) { return k !== pKey; });
} else {
if (!preset.suggestion) {
// Not a suggestion preset - Add a suggestions dropdown if it makes sense to.
// This code attempts to determine if the matched preset is the
// kind of preset that even can benefit from name suggestions..
@@ -154,8 +140,8 @@ export function uiFieldLocalized(field, context) {
}
input
.classed('disabled', !!_isLocked)
.attr('readonly', _isLocked || null)
.classed('disabled', !!isLocked)
.attr('readonly', isLocked || null)
.on('input', change(true))
.on('blur', change())
.on('change', change());
@@ -172,8 +158,8 @@ export function uiFieldLocalized(field, context) {
.merge(translateButton);
translateButton
.classed('disabled', !!_isLocked)
.call(_isLocked ? _buttonTip.destroy : _buttonTip)
.classed('disabled', !!isLocked)
.call(isLocked ? _buttonTip.destroy : _buttonTip)
.on('click', addNew);
@@ -193,8 +179,9 @@ export function uiFieldLocalized(field, context) {
.call(renderMultilingual);
localizedInputs.selectAll('button, input')
.classed('disabled', !!_isLocked)
.attr('readonly', _isLocked || null);
.classed('disabled', !!isLocked)
.attr('readonly', isLocked || null);
// We are not guaranteed to get an `accept` or `cancel` when blurring the field.
@@ -297,7 +284,7 @@ export function uiFieldLocalized(field, context) {
function addNew() {
d3_event.preventDefault();
if (_isLocked) return;
if (field.locked()) return;
var defaultLang = utilDetect().locale.toLowerCase().split('-')[0];
var langExists = _multilingual.find(function(datum) { return datum.lang === defaultLang; });
@@ -314,7 +301,7 @@ export function uiFieldLocalized(field, context) {
function change(onInput) {
return function() {
if (_isLocked) {
if (field.locked()) {
d3_event.preventDefault();
return;
}
@@ -404,16 +391,24 @@ export function uiFieldLocalized(field, context) {
.append('label')
.attr('class', 'field-label');
label
var text = label
.append('span')
.attr('class', 'label-text')
.attr('class', 'label-text');
text
.append('span')
.attr('class', 'label-textvalue')
.text(t('translate.localized_translation_label'));
text
.append('span')
.attr('class', 'label-textannotation');
label
.append('button')
.attr('class', 'remove-icon-multilingual')
.on('click', function(d){
if (_isLocked) return;
if (field.locked()) return;
d3_event.preventDefault();
var t = {};
t[key(d.lang)] = undefined;
+1
View File
@@ -0,0 +1 @@
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="lock" class="svg-inline--fa fa-lock fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"></path></svg>

After

Width:  |  Height:  |  Size: 440 B

+88 -75
View File
@@ -1,69 +1,69 @@
describe('iD.osmEntity', function () {
it('returns a subclass of the appropriate type', function () {
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);
expect(iD.osmEntity({type: 'node'})).be.an.instanceOf(iD.osmNode);
expect(iD.osmEntity({type: 'way'})).be.an.instanceOf(iD.osmWay);
expect(iD.osmEntity({type: 'relation'})).be.an.instanceOf(iD.osmRelation);
expect(iD.osmEntity({id: 'n1'})).be.an.instanceOf(iD.osmNode);
expect(iD.osmEntity({id: 'w1'})).be.an.instanceOf(iD.osmWay);
expect(iD.osmEntity({id: 'r1'})).be.an.instanceOf(iD.osmRelation);
});
if (iD.debug) {
it('is frozen', function () {
expect(Object.isFrozen(iD.Entity())).to.be.true;
expect(Object.isFrozen(iD.osmEntity())).to.be.true;
});
it('freezes tags', function () {
expect(Object.isFrozen(iD.Entity().tags)).to.be.true;
expect(Object.isFrozen(iD.osmEntity().tags)).to.be.true;
});
}
describe('.id', function () {
it('generates unique IDs', function () {
expect(iD.Entity.id('node')).not.to.equal(iD.Entity.id('node'));
expect(iD.osmEntity.id('node')).not.to.equal(iD.osmEntity.id('node'));
});
describe('.fromOSM', function () {
it('returns a ID string unique across entity types', function () {
expect(iD.Entity.id.fromOSM('node', '1')).to.equal('n1');
expect(iD.osmEntity.id.fromOSM('node', '1')).to.equal('n1');
});
});
describe('.toOSM', function () {
it('reverses fromOSM', function () {
expect(iD.Entity.id.toOSM(iD.Entity.id.fromOSM('node', '1'))).to.equal('1');
expect(iD.osmEntity.id.toOSM(iD.osmEntity.id.fromOSM('node', '1'))).to.equal('1');
});
});
});
describe('#copy', function () {
it('returns a new Entity', function () {
var n = iD.Entity({id: 'n'}),
result = n.copy(null, {});
expect(result).to.be.an.instanceof(iD.Entity);
var n = iD.osmEntity({id: 'n'});
var result = n.copy(null, {});
expect(result).to.be.an.instanceof(iD.osmEntity);
expect(result).not.to.equal(n);
});
it('adds the new Entity to input object', function () {
var n = iD.Entity({id: 'n'}),
copies = {},
result = n.copy(null, copies);
var n = iD.osmEntity({id: 'n'});
var copies = {};
var result = n.copy(null, copies);
expect(Object.keys(copies)).to.have.length(1);
expect(copies.n).to.equal(result);
});
it('returns an existing copy in input object', function () {
var n = iD.Entity({id: 'n'}),
copies = {},
result1 = n.copy(null, copies),
result2 = n.copy(null, copies);
var n = iD.osmEntity({id: 'n'});
var copies = {};
var result1 = n.copy(null, copies);
var result2 = n.copy(null, copies);
expect(Object.keys(copies)).to.have.length(1);
expect(result1).to.equal(result2);
});
it('resets \'id\', \'user\', and \'version\' properties', function () {
var n = iD.Entity({id: 'n', version: 10, user: 'user'}),
copies = {};
var n = iD.osmEntity({id: 'n', version: 10, user: 'user'});
var copies = {};
n.copy(null, copies);
expect(copies.n.isNew()).to.be.ok;
expect(copies.n.version).to.be.undefined;
@@ -71,8 +71,8 @@ describe('iD.osmEntity', function () {
});
it('copies tags', function () {
var n = iD.Entity({id: 'n', tags: {foo: 'foo'}}),
copies = {};
var n = iD.osmEntity({id: 'n', tags: {foo: 'foo'}});
var copies = {};
n.copy(null, copies);
expect(copies.n.tags).to.equal(n.tags);
});
@@ -80,85 +80,85 @@ describe('iD.osmEntity', function () {
describe('#update', function () {
it('returns a new Entity', function () {
var a = iD.Entity(),
b = a.update({});
expect(b instanceof iD.Entity).to.be.true;
var a = iD.osmEntity();
var b = a.update({});
expect(b instanceof iD.osmEntity).to.be.true;
expect(a).not.to.equal(b);
});
it('updates the specified attributes', function () {
var tags = {foo: 'bar'},
e = iD.Entity().update({tags: tags});
var tags = {foo: 'bar'};
var e = iD.osmEntity().update({tags: tags});
expect(e.tags).to.equal(tags);
});
it('preserves existing attributes', function () {
var e = iD.Entity({id: 'w1'}).update({});
var e = iD.osmEntity({id: 'w1'}).update({});
expect(e.id).to.equal('w1');
});
it('doesn\'t modify the input', function () {
var attrs = {tags: {foo: 'bar'}};
iD.Entity().update(attrs);
iD.osmEntity().update(attrs);
expect(attrs).to.eql({tags: {foo: 'bar'}});
});
it('doesn\'t copy prototype properties', function () {
expect(iD.Entity().update({})).not.to.have.ownProperty('update');
expect(iD.osmEntity().update({})).not.to.have.ownProperty('update');
});
it('sets v to 1 if previously undefined', function() {
expect(iD.Entity().update({}).v).to.equal(1);
expect(iD.osmEntity().update({}).v).to.equal(1);
});
it('increments v', function() {
expect(iD.Entity({v: 1}).update({}).v).to.equal(2);
expect(iD.osmEntity({v: 1}).update({}).v).to.equal(2);
});
});
describe('#mergeTags', function () {
it('returns self if unchanged', function () {
var a = iD.Entity({tags: {a: 'a'}}),
b = a.mergeTags({a: 'a'});
var a = iD.osmEntity({tags: {a: 'a'}});
var b = a.mergeTags({a: 'a'});
expect(a).to.equal(b);
});
it('returns a new Entity if changed', function () {
var a = iD.Entity({tags: {a: 'a'}}),
b = a.mergeTags({a: 'b'});
expect(b instanceof iD.Entity).to.be.true;
var a = iD.osmEntity({tags: {a: 'a'}});
var b = a.mergeTags({a: 'b'});
expect(b instanceof iD.osmEntity).to.be.true;
expect(a).not.to.equal(b);
});
it('merges tags', function () {
var a = iD.Entity({tags: {a: 'a'}}),
b = a.mergeTags({b: 'b'});
var a = iD.osmEntity({tags: {a: 'a'}});
var b = a.mergeTags({b: 'b'});
expect(b.tags).to.eql({a: 'a', b: 'b'});
});
it('combines non-conflicting tags', function () {
var a = iD.Entity({tags: {a: 'a'}}),
b = a.mergeTags({a: 'a'});
var a = iD.osmEntity({tags: {a: 'a'}});
var b = a.mergeTags({a: 'a'});
expect(b.tags).to.eql({a: 'a'});
});
it('combines conflicting tags with semicolons', function () {
var a = iD.Entity({tags: {a: 'a'}}),
b = a.mergeTags({a: 'b'});
var a = iD.osmEntity({tags: {a: 'a'}});
var b = a.mergeTags({a: 'b'});
expect(b.tags).to.eql({a: 'a;b'});
});
it('combines combined tags', function () {
var a = iD.Entity({tags: {a: 'a;b'}}),
b = iD.Entity({tags: {a: 'b'}});
var a = iD.osmEntity({tags: {a: 'a;b'}});
var b = iD.osmEntity({tags: {a: 'b'}});
expect(a.mergeTags(b.tags).tags).to.eql({a: 'a;b'});
expect(b.mergeTags(a.tags).tags).to.eql({a: 'b;a'});
});
it('combines combined tags with whitespace', function () {
var a = iD.Entity({tags: {a: 'a; b'}}),
b = iD.Entity({tags: {a: 'b'}});
var a = iD.osmEntity({tags: {a: 'a; b'}});
var b = iD.osmEntity({tags: {a: 'b'}});
expect(a.mergeTags(b.tags).tags).to.eql({a: 'a;b'});
expect(b.mergeTags(a.tags).tags).to.eql({a: 'b;a'});
@@ -167,24 +167,24 @@ describe('iD.osmEntity', function () {
describe('#osmId', function () {
it('returns an OSM ID as a string', function () {
expect(iD.Entity({id: 'w1234'}).osmId()).to.eql('1234');
expect(iD.Entity({id: 'n1234'}).osmId()).to.eql('1234');
expect(iD.Entity({id: 'r1234'}).osmId()).to.eql('1234');
expect(iD.osmEntity({id: 'w1234'}).osmId()).to.eql('1234');
expect(iD.osmEntity({id: 'n1234'}).osmId()).to.eql('1234');
expect(iD.osmEntity({id: 'r1234'}).osmId()).to.eql('1234');
});
});
describe('#intersects', function () {
it('returns true for a way with a node within the given extent', function () {
var node = iD.osmNode({loc: [0, 0]}),
way = iD.osmWay({nodes: [node.id]}),
graph = iD.coreGraph([node, way]);
var node = iD.osmNode({loc: [0, 0]});
var way = iD.osmWay({nodes: [node.id]});
var 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.osmNode({loc: [6, 6]}),
way = iD.osmWay({nodes: [node.id]}),
graph = iD.coreGraph([node, way]);
var node = iD.osmNode({loc: [6, 6]});
var way = iD.osmWay({nodes: [node.id]});
var graph = iD.coreGraph([node, way]);
expect(way.intersects([[-5, -5], [5, 5]], graph)).to.equal(false);
});
});
@@ -208,59 +208,72 @@ describe('iD.osmEntity', function () {
describe('#hasParentRelations', function () {
it('returns true for an entity that is a relation member', function () {
var node = iD.osmNode(),
relation = iD.osmRelation({members: [{id: node.id}]}),
graph = iD.coreGraph([node, relation]);
var node = iD.osmNode();
var relation = iD.osmRelation({members: [{id: node.id}]});
var 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.osmNode(),
graph = iD.coreGraph([node]);
var node = iD.osmNode();
var graph = iD.coreGraph([node]);
expect(node.hasParentRelations(graph)).to.equal(false);
});
});
describe('#hasDeprecatedTags', function () {
it('returns false if entity has no tags', function () {
expect(iD.Entity().deprecatedTags()).to.eql([]);
expect(iD.osmEntity().deprecatedTags()).to.eql([]);
});
it('returns true if entity has deprecated tags', function () {
expect(iD.Entity({ tags: { amenity: 'toilet' } }).deprecatedTags()).to.eql([{
old: { amenity: 'toilet' },
replace: { amenity: 'toilets' }
}]);
expect(iD.osmEntity({ tags: { amenity: 'toilet' } }).deprecatedTags()).to.eql(
[{ old: { amenity: 'toilet' }, replace: { amenity: 'toilets' } }]
);
});
});
describe('#hasWikidata', function () {
it('returns false if entity has no tags', function () {
expect(iD.osmEntity().hasWikidata()).to.be.not.ok;
});
it('returns true if entity has a wikidata tag', function () {
expect(iD.osmEntity({ tags: { wikidata: 'Q18275868' } }).hasWikidata()).to.be.ok;
});
it('returns true if entity has a brand:wikidata tag', function () {
expect(iD.osmEntity({ tags: { 'brand:wikidata': 'Q18275868' } }).hasWikidata()).to.be.ok;
});
});
describe('#hasInterestingTags', function () {
it('returns false if the entity has no tags', function () {
expect(iD.Entity().hasInterestingTags()).to.equal(false);
expect(iD.osmEntity().hasInterestingTags()).to.equal(false);
});
it('returns true if the entity has tags other than \'attribution\', \'created_by\', \'source\', \'odbl\' and tiger tags', function () {
expect(iD.Entity({tags: {foo: 'bar'}}).hasInterestingTags()).to.equal(true);
expect(iD.osmEntity({tags: {foo: 'bar'}}).hasInterestingTags()).to.equal(true);
});
it('return false if the entity has only uninteresting tags', function () {
expect(iD.Entity({tags: {source: 'Bing'}}).hasInterestingTags()).to.equal(false);
expect(iD.osmEntity({tags: {source: 'Bing'}}).hasInterestingTags()).to.equal(false);
});
it('return false if the entity has only tiger tags', function () {
expect(iD.Entity({tags: {'tiger:source': 'blah', 'tiger:foo': 'bar'}}).hasInterestingTags()).to.equal(false);
expect(iD.osmEntity({tags: {'tiger:source': 'blah', 'tiger:foo': 'bar'}}).hasInterestingTags()).to.equal(false);
});
});
describe('#isHighwayIntersection', function () {
it('returns false', function () {
expect(iD.Entity().isHighwayIntersection()).to.be.false;
expect(iD.osmEntity().isHighwayIntersection()).to.be.false;
});
});
describe('#isDegenerate', function () {
it('returns true', function () {
expect(iD.Entity().isDegenerate()).to.be.true;
expect(iD.osmEntity().isDegenerate()).to.be.true;
});
});
+21
View File
@@ -185,6 +185,27 @@ describe('iD.svgTagClasses', function () {
expect(selection.classed('tag-unpaved')).to.be.false;
});
it('does not add tag-wikidata if no wikidata tag', function() {
selection
.datum(iD.osmEntity())
.call(iD.svgTagClasses());
expect(selection.classed('tag-wikidata')).to.be.false;
});
it('adds tag-wikidata if entity has a wikidata tag', function() {
selection
.datum(iD.osmEntity({ tags: { wikidata: 'Q18275868' } }))
.call(iD.svgTagClasses());
expect(selection.classed('tag-wikidata')).to.be.true;
});
it('adds tag-wikidata if entity has a brand:wikidata tag', function() {
selection
.datum(iD.osmEntity({ tags: { 'brand:wikidata': 'Q18275868' } }))
.call(iD.svgTagClasses());
expect(selection.classed('tag-wikidata')).to.be.true;
});
it('adds tags based on the result of the `tags` accessor', function() {
var primary = function () { return { highway: 'primary'}; };
selection
+1
View File
@@ -5,6 +5,7 @@ describe('iD.uiFieldLocalized', function() {
context = iD.coreContext();
selection = d3.select(document.createElement('div'));
field = iD.presetField('name', { key: 'name', type: 'localized' });
field.locked = function() { return false; };
});
it('adds a blank set of fields when the + button is clicked', function() {