Skip to content

Commit

Permalink
#884 Added tests for localization service
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhyder committed Jul 16, 2016
1 parent 8074f42 commit e2b2040
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
22 changes: 1 addition & 21 deletions include/localization.js
Expand Up @@ -259,7 +259,7 @@ module.exports = function LocalizationModule(pb) {
if (keys[i].substr(index + 1) === key) {
convertedKey = keys[i];

pb.log.warn('Localization: Using the localization key %s is non-performant and should be updated to %s', key, convertedKey);
pb.log.debug('Localization: Using the localization key %s is non-performant and should be updated to %s', key, convertedKey);
break;
}
}
Expand Down Expand Up @@ -1127,26 +1127,6 @@ module.exports = function LocalizationModule(pb) {
* @return {Object} The object that contains the values for the key
*/
function findKeyBlock(key, create) {

////parse the key
//var keyParts = key.split(Localization.KEY_SEP);
//
////walk the tree looking for the storage structure
//var keyBlock = Localization.storage;
//keyParts.forEach(function(part) {
// if (util.isNullOrUndefined(keyBlock[part])) {
// keyBlock[part] = {
// __isKey: true
// };
// }
// else if (!keyBlock[part].__isKey) {
//
// //bad news bears. They tried to provide a key in a protected
// //namespace. Basically all the things with "__" prefixes
// return null;
// }
// keyBlock = keyBlock[part];
//});
if (create && typeof Localization.storage[key] === 'undefined') {
Localization.storage[key] = {};
}
Expand Down
47 changes: 36 additions & 11 deletions test/include/localization_tests.js
Expand Up @@ -16,9 +16,6 @@ describe('Localization', function() {
var Localization = null;
before('Initialize the Environment with the default configuration', function(next) {

//travis gets slow so we bump the timeout just a little here to get around the BS
this.timeout(10000);

pb = new Lib(Configuration.getBaseConfig());
Localization = pb.Localization;
Localization.init(next);
Expand All @@ -31,8 +28,8 @@ describe('Localization', function() {

it('should return a valid package when provided '+locale, function() {

var package = Localization.getLocalizationPackage(locale);
package.generic.LOCALE_DISPLAY.should.eql(dummyDisplay);
var pkg = Localization.getLocalizationPackage(locale);
pkg.generic.LOCALE_DISPLAY.should.eql(dummyDisplay);
});
});

Expand All @@ -41,8 +38,8 @@ describe('Localization', function() {

it('should return null when provided '+locale, function() {

var package = Localization.getLocalizationPackage(locale);
should(package === null).be.ok;
var pkg = Localization.getLocalizationPackage(locale);
should(pkg === null).be.ok;
});
});

Expand All @@ -51,8 +48,8 @@ describe('Localization', function() {

it('should default to English whe provided '+locale, function() {

var package = Localization.getLocalizationPackage(locale);
package.generic.LOCALE_DISPLAY.should.eql('English (United States)');
var pkg = Localization.getLocalizationPackage(locale);
pkg.generic.LOCALE_DISPLAY.should.eql('English (United States)');
});
});
});
Expand All @@ -65,7 +62,7 @@ describe('Localization', function() {
it('should return true when provided '+locale, function() {

var supported = Localization.isSupported(locale);
supported.should.be.ok;
supported.should.eql(true);
});
});

Expand Down Expand Up @@ -332,7 +329,7 @@ describe('Localization', function() {
describe('Localization.unregisterLocale', function() {

it('should return true and no longer be supported when a valid locale is unregistered', function() {
var locale = 'en-US';
var locale = 'nl-BE';
Localization.unregisterLocale(locale).should.eql(true);
Localization.isSupported(locale).should.eql(false);
});
Expand Down Expand Up @@ -378,6 +375,34 @@ describe('Localization', function() {
//TODO should return true when provided an existing key and country code with a plugin that has registered the key
});

describe('Localization.get', function() {

[null, undefined, '', 1, false, true, [], {}].forEach(function(key) {
it('should return null when an invalid key ' + key + ' is provided', function () {
var ls = new Localization('en-US');
should(ls.get(key) === null).eql(true);
});
});

it('should return the key when a non-existing localization key is passed', function() {
var key = 'SOME_NON_EXISTING_KEY';
var ls = new Localization('en-US');
ls.get(key).should.eql(key);
});

it('should lookup the key prefix and then translate the key', function() {
var key = 'LEFT';
var ls = new Localization('en-US');
ls.get(key).should.eql('Left');
});

it('should replace the key and insert the argument', function() {
var key = 'INSTALL_FAILED';
var ls = new Localization('en-US');
ls.get(key, 'test-value').should.eql('The attempt to install plugin [test-value] failed');
});
});

function getLocalizationFiles(cb) {
var options = {
recursive: false,
Expand Down

0 comments on commit e2b2040

Please sign in to comment.