Browse Source

added `macroregion` to default and GBR schemas (with tests!)

pull/461/head
Stephen Hess 9 years ago
parent
commit
c746bd8d36
  1. 9
      helper/labelSchema.js
  2. 17
      test/unit/helper/labelGenerator_GBR.js
  3. 51
      test/unit/helper/labelGenerator_default.js

9
helper/labelSchema.js

@ -8,7 +8,7 @@ module.exports = {
'country': getFirstProperty(['country_a'])
},
'GBR': {
'local': getFirstProperty(['neighbourhood', 'county', 'localadmin', 'locality', 'region']),
'local': getFirstProperty(['neighbourhood', 'county', 'localadmin', 'locality', 'macroregion', 'region']),
'regional': getFirstProperty(['county','country','region'])
},
'SGP': {
@ -20,7 +20,7 @@ module.exports = {
'regional': getFirstProperty(['country'])
},
'default': {
'local': getFirstProperty(['localadmin', 'locality', 'neighbourhood', 'county', 'region']),
'local': getFirstProperty(['localadmin', 'locality', 'neighbourhood', 'county', 'macroregion', 'region']),
'regional': getFirstProperty(['country'])
}
};
@ -28,10 +28,15 @@ module.exports = {
// find the first field of record that has a non-empty value that's not already in labelParts
function getFirstProperty(fields) {
return function(record, labelParts) {
console.log(record);
console.log();
for (var i = 0; i < fields.length; i++) {
console.log('considering ' + fields[i]);
var fieldValue = record[fields[i]];
if (check.nonEmptyString(fieldValue) && !_.includes(labelParts, fieldValue)) {
console.log('adding ' + fields[i] + ' value: ' + fieldValue);
labelParts.push( fieldValue );
return labelParts;
}

17
test/unit/helper/labelGenerator_GBR.js

@ -58,6 +58,23 @@ module.exports.tests.wales = function(test, common) {
});
};
// GBR macroregion
module.exports.tests.macroregion_trumps_region = function(test, common) {
test('macroregion should trump region when none of neighbourhood, county, localadmin, locality are available', function(t) {
var doc = {
'name': 'Name',
'country_a': 'GBR',
'country': 'Country Name',
'macroregion': 'Macroregion Name',
'region': 'Region Name'
};
t.equal(generator(doc), 'Name, Macroregion Name, Country Name');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {

51
test/unit/helper/labelGenerator_default.js

@ -251,6 +251,57 @@ module.exports.tests.waiotapu = function(test, common) {
});
};
module.exports.tests.non_us_or_ca_region = function(test, common) {
test('geonames US', function(t) {
var doc = {
'name': 'Default Name',
'country_a': 'XYZ',
'country': 'Full Country Name',
'region': 'Full Region Name',
'layer': 'region',
'source': 'geonames'
};
t.equal(generator(doc), 'Default Name, Full Region Name, Full Country Name');
t.end();
});
test('whosonfirst US', function(t) {
var doc = {
'name': 'Default Name',
'country_a': 'XYZ',
'country': 'Full Country Name',
'region': 'Full Region Name',
'layer': 'region',
'source': 'whosonfirst'
};
t.equal(generator(doc), 'Default Name, Full Region Name, Full Country Name');
t.end();
});
};
// macroregion
module.exports.tests.macroregion_trumps_region = function(test, common) {
test('macroregion should trump region when none of localadmin, locality, neighbourhood, county are available', function(t) {
var doc = {
'name': 'Name',
'country_a': 'Country abbreviation',
'country': 'Country Name',
'macroregion': 'Macroregion Name',
'region': 'Region Name'
};
t.equal(generator(doc), 'Name, Macroregion Name, Country Name');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {

Loading…
Cancel
Save