-
-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add provinces to Australian labels #638
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,17 @@ module.exports = { | |
'USA': { | ||
'borough': getFirstProperty(['borough']), | ||
'local': getFirstProperty(['locality', 'localadmin', 'county']), | ||
'regional': getUsOrCaState, | ||
'regional': getUsOrCaOrAusState, | ||
'country': getUSACountryValue | ||
}, | ||
'AUS': { | ||
'local' : getFirstProperty(['locality', 'localadmin']), | ||
'regional' : getUsOrCaOrAusState, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason that this function isn't called here? why does it just store the variable name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a reason! It's a bit confusing. The labelGenerator.js module which actually generates the labels loads this module, and picks the correct country's schema to use, and then calls the function from that schema |
||
'country': getFirstProperty(['country']) | ||
}, | ||
'CAN': { | ||
'local': getFirstProperty(['locality']), // no localadmins in CAN | ||
'regional': getUsOrCaState, | ||
'regional': getUsOrCaOrAusState, | ||
'country': getFirstProperty(['country']) | ||
} | ||
}; | ||
|
@@ -44,7 +49,7 @@ function getFirstProperty(fields) { | |
// 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) { | ||
function getUsOrCaOrAusState(record) { | ||
if ('region' === record.layer && record.region) { | ||
// return full state name when state is the most granular piece of info | ||
return record.region; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after how many countries do we rename this to something like
getRegionalValue
? 3 feels like a good time :)