Browse Source

Added flag to not include `default.name` in label

when source=`geonames` or `whosonfirst` and layer=`region`

This will stop, say, a search for "New Mexico" resulting in the label "New Mexico, NM, USA"
pull/430/head
Stephen Hess 9 years ago committed by Julian Simioni
parent
commit
5456632cdf
  1. 11
      helper/labelGenerator.js
  2. 44
      test/unit/helper/labelGenerator_USA.js

11
helper/labelGenerator.js

@ -6,7 +6,7 @@ var _ = require('lodash'),
module.exports = function( record ){
var schema = getSchema(record.country_a);
var labelParts = [ record.name.default ];
var labelParts = getInitialLabel(record);
var buildOutput = function(parts, schemaArr, record) {
for (var i=0; i<schemaArr.length; i++) {
@ -35,3 +35,12 @@ function getSchema(country_a) {
return schemas.default;
}
function getInitialLabel(record) {
if ('region' === record.layer && ('geonames' === record.source || 'whosonfirst' === record.source)) {
return [];
}
return [record.name.default];
}

44
test/unit/helper/labelGenerator_USA.js

@ -88,15 +88,51 @@ module.exports.tests.ferry_building = function(test, common) {
});
};
// USA state
module.exports.tests.california = function(test, common) {
test('california', function(t) {
// USA geonames state
module.exports.tests.california_geonames = function(test, common) {
test('default name should not be prepended when source=geonames and layer=region', function(t) {
var doc = {
'name': { 'default': 'California' },
'country_a': 'USA',
'country': 'United States',
'region': 'California',
'region_a': 'CA'
'region_a': 'CA',
'source': 'geonames',
'layer': 'region'
};
t.equal(generator(doc),'CA, USA');
t.end();
});
};
// USA whosonfirst state
module.exports.tests.california_whosonfirst = function(test, common) {
test('default name should not be prepended when source=whosonfirst and layer=region', function(t) {
var doc = {
'name': { 'default': 'California' },
'country_a': 'USA',
'country': 'United States',
'region': 'California',
'region_a': 'CA',
'source': 'whosonfirst',
'layer': 'region'
};
t.equal(generator(doc),'CA, USA');
t.end();
});
};
// USA non-geonames/whosonfirst state
module.exports.tests.california_other_source = function(test, common) {
test('default name should not be prepended when source=whosonfirst and layer=region', function(t) {
var doc = {
'name': { 'default': 'California' },
'country_a': 'USA',
'country': 'United States',
'region': 'California',
'region_a': 'CA',
'source': 'not geonames or whosonfirst',
'layer': 'region'
};
t.equal(generator(doc),'California, CA, USA');
t.end();

Loading…
Cancel
Save