Browse Source

Add provinces to Australian labels

pull/638/head
Alec Vulfson 8 years ago
parent
commit
a6ccbf17ce
  1. 11
      helper/labelSchema.js
  2. 201
      test/unit/helper/labelGenerator_AUS.js
  3. 4
      test/unit/helper/labelSchema.js
  4. 1
      test/unit/run.js

11
helper/labelSchema.js

@ -13,12 +13,17 @@ module.exports = {
'USA': { 'USA': {
'borough': getFirstProperty(['borough']), 'borough': getFirstProperty(['borough']),
'local': getFirstProperty(['locality', 'localadmin', 'county']), 'local': getFirstProperty(['locality', 'localadmin', 'county']),
'regional': getUsOrCaState, 'regional': getUsOrCaOrAusState,
'country': getUSACountryValue 'country': getUSACountryValue
}, },
'AUS': {
'local' : getFirstProperty(['locality', 'localadmin']),
'regional' : getUsOrCaOrAusState,
'country': getFirstProperty(['country'])
},
'CAN': { 'CAN': {
'local': getFirstProperty(['locality']), // no localadmins in CAN 'local': getFirstProperty(['locality']), // no localadmins in CAN
'regional': getUsOrCaState, 'regional': getUsOrCaOrAusState,
'country': getFirstProperty(['country']) 'country': getFirstProperty(['country'])
} }
}; };
@ -44,7 +49,7 @@ function getFirstProperty(fields) {
// the full state name, eg: Pennsylvania, USA and Ontario, CA // 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 // 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 // 3. if for some reason the abbreviation isn't available, use the full state name
function getUsOrCaState(record) { function getUsOrCaOrAusState(record) {
if ('region' === record.layer && record.region) { if ('region' === record.layer && record.region) {
// return full state name when state is the most granular piece of info // return full state name when state is the most granular piece of info
return record.region; 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('USA'), -1);
t.notEquals(supported_countries.indexOf('CAN'), -1); t.notEquals(supported_countries.indexOf('CAN'), -1);
t.notEquals(supported_countries.indexOf('GBR'), -1); t.notEquals(supported_countries.indexOf('GBR'), -1);
t.notEquals(supported_countries.indexOf('AUS'), -1);
t.notEquals(supported_countries.indexOf('default'), -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.USA).length, 4);
t.equals(Object.keys(schemas.CAN).length, 3); t.equals(Object.keys(schemas.CAN).length, 3);
t.equals(Object.keys(schemas.GBR).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.equals(Object.keys(schemas.default).length, 2);
t.end(); t.end();

1
test/unit/run.js

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

Loading…
Cancel
Save