Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addon/rules/no.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import en from 'ember-cli-i18n/rules/en';
export default en;
25 changes: 24 additions & 1 deletion test-support/ember-cli-i18n-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@
import Ember from 'ember';
import config from '../config/environment';

var flattenObject = function(ob) {
var toReturn = {};

for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;

if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;

toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = ob[i];
}
}
return toReturn;
};

if (window.QUnit) {
var keys = Ember.keys;

Expand Down Expand Up @@ -43,9 +63,12 @@ if (window.QUnit) {
continue;
}

currentLocale = flattenObject(currentLocale);
defaultLocale = flattenObject(defaultLocale);

for (var translationKey in defaultLocale) {
assert.ok(currentLocale[translationKey], '`' + translationKey + '` should exist in the `' + knownLocales[i] + '` locale.');
}
}
});
}
}
49 changes: 49 additions & 0 deletions tests/unit/rules/no-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Ember from 'ember';
import { module, test } from 'qunit';
import rules from 'ember-cli-i18n/rules/no';
import cldrTest from '../../helpers/cldr';

var result = {
one: 'one',
other: 'other'
};

var path = 'result';
var countryCode = 'no';
var ruleResults;

module('CLDR Rules - Norwegian ('+countryCode+')');

test('one', function(assert) {
cldrTest(assert, 1, 'one', rules, result, path, countryCode);
});

test('other', function(assert) {
cldrTest(assert, 0, 'other', rules, result, path, countryCode);
cldrTest(assert, 2, 'other', rules, result, path, countryCode);
});

test('assertion is thrown if no valid keys exist', function(assert) {
var badResult = {foo: 'bar'};
var count = 0;
var oldAssert = Ember.assert;
Ember.assert = function() {
count += 1;
};

rules(0, badResult, path, countryCode);
assert.equal(count, 1);
Ember.assert = oldAssert;
});

test('assertion is thrown if non-numeric value is passed ', function(assert) {
var count = 0;
var oldAssert = Ember.assert;
Ember.assert = function() {
count += 1;
};

rules('0', result, path, countryCode);
assert.equal(count, 1);
Ember.assert = oldAssert;
});