Browse Source

feat: Merge pull request #638 from pelias/expand-aussie-labels

Add provinces to Australian labels
pull/648/head v3.2.0
Julian Simioni 8 years ago committed by GitHub
parent
commit
6f09259cca
  1. 21
      helper/labelSchema.js
  2. 201
      test/unit/helper/labelGenerator_AUS.js
  3. 4
      test/unit/helper/labelSchema.js
  4. 1
      test/unit/run.js

21
helper/labelSchema.js

@ -13,12 +13,17 @@ module.exports = {
'USA': {
'borough': getFirstProperty(['borough']),
'local': getFirstProperty(['locality', 'localadmin', 'county']),
'regional': getUsOrCaState,
'regional': getRegionalValue,
'country': getUSACountryValue
},
'AUS': {
'local' : getFirstProperty(['locality', 'localadmin']),
'regional' : getRegionalValue,
'country': getFirstProperty(['country'])
},
'CAN': {
'local': getFirstProperty(['locality']), // no localadmins in CAN
'regional': getUsOrCaState,
'regional': getRegionalValue,
'country': getFirstProperty(['country'])
}
};
@ -39,12 +44,12 @@ function getFirstProperty(fields) {
}
// this function is exclusively used for figuring out which field to use for US/CA States
// 1. if a US/CA state is the most granular bit of info entered, the label should contain
// the full state name, eg: Pennsylvania, USA and Ontario, CA
// 2. otherwise, the state abbreviation should be used, eg: Lancaster, PA, USA and Bruce, ON, CA
// 3. if for some reason the abbreviation isn't available, use the full state name
function getUsOrCaState(record) {
// this function is exclusively used for figuring out which field to use for states/provinces
// 1. if a state/province is the most granular bit of info entered, the label should contain
// the full state/province name, eg: Pennsylvania, USA and Ontario, CA
// 2. otherwise, the state/province abbreviation should be used, eg: Lancaster, PA, USA and Bruce, ON, CA
// 3. if the abbreviation isn't available, use the full state/province name
function getRegionalValue(record) {
if ('region' === record.layer && record.region) {
// return full state name when state is the most granular piece of info
return record.region;

201
test/unit/helper/labelGenerator_AUS.js

@ -0,0 +1,201 @@
var generator = require('../../../helper/labelGenerator');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('interface', function(t) {
t.equal(typeof generator, 'function', 'valid function');
t.end();
});
};
module.exports.tests.australia = function(test, common) {
test('venue', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'venue name, locality name, region name, Australia');
t.end();
});
test('localadmin value should be used when locality is not available', function(t) {
var doc = {
'name': 'venue name',
'layer': 'venue',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'venue name, localadmin name, region name, Australia');
t.end();
});
test('street', function(t) {
var doc = {
'name': 'house number street name',
'layer': 'address',
'housenumber': 'house number',
'street': 'street name',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'house number street name, locality name, region name, Australia');
t.end();
});
test('neighbourhood', function(t) {
var doc = {
'name': 'neighbourhood name',
'layer': 'neighbourhood',
'neighbourhood': 'neighbourhood name',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'neighbourhood name, locality name, region name, Australia');
t.end();
});
test('locality', function(t) {
var doc = {
'name': 'locality name',
'layer': 'locality',
'locality': 'locality name',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'locality name, region name, Australia');
t.end();
});
test('localadmin', function(t) {
var doc = {
'name': 'localadmin name',
'layer': 'localadmin',
'localadmin': 'localadmin name',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'localadmin name, region name, Australia');
t.end();
});
test('county', function(t) {
var doc = {
'name': 'county name',
'layer': 'county',
'county': 'county name',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'county name, region name, Australia');
t.end();
});
test('macrocounty', function(t) {
var doc = {
'name': 'macrocounty name',
'layer': 'macrocounty',
'macrocounty': 'macrocounty name',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'macrocounty name, region name, Australia');
t.end();
});
test('region', function(t) {
var doc = {
'name': 'region name',
'layer': 'region',
'region': 'region name',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'region name, Australia');
t.end();
});
test('macroregion', function(t) {
var doc = {
'name': 'macroregion name',
'layer': 'macroregion',
'macroregion': 'macroregion name',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'macroregion name, Australia');
t.end();
});
test('country', function(t) {
var doc = {
'name': 'Australia',
'layer': 'country',
'postalcode': 'postalcode',
'country_a': 'AUS',
'country': 'Australia'
};
t.equal(generator(doc),'Australia');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('label generator (AUS): ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

4
test/unit/helper/labelSchema.js

@ -18,12 +18,14 @@ module.exports.tests.supported_countries = function(test, common) {
t.notEquals(supported_countries.indexOf('USA'), -1);
t.notEquals(supported_countries.indexOf('CAN'), -1);
t.notEquals(supported_countries.indexOf('GBR'), -1);
t.notEquals(supported_countries.indexOf('AUS'), -1);
t.notEquals(supported_countries.indexOf('default'), -1);
t.equals(supported_countries.length, 4);
t.equals(supported_countries.length, 5);
t.equals(Object.keys(schemas.USA).length, 4);
t.equals(Object.keys(schemas.CAN).length, 3);
t.equals(Object.keys(schemas.GBR).length, 3);
t.equals(Object.keys(schemas.AUS).length, 3);
t.equals(Object.keys(schemas.default).length, 2);
t.end();

1
test/unit/run.js

@ -16,6 +16,7 @@ var tests = [
require('./helper/labelGenerator_examples'),
require('./helper/labelGenerator_default'),
require('./helper/labelGenerator_CAN'),
require('./helper/labelGenerator_AUS'),
require('./helper/labelGenerator_GBR'),
require('./helper/labelGenerator_USA'),
require('./helper/labelSchema'),

Loading…
Cancel
Save