Skip to content

Commit

Permalink
Added test for i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
glena committed Oct 20, 2016
1 parent 57336fa commit 7c75e61
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ export function group(m, keyPath) {
}

export function initI18n(m) {

const language = l.ui.language(m);
const overrides = l.ui.dict(m);
const defaultDictionary = Immutable.fromJS(enDictionary);

let base = languageDictionaries[language] || Map({});

if (base.isEmpty()) {
if (base.isEmpty()) {
base = overrides;
m = sync(m, "i18n", {
syncFn: (_, cb) => syncLang(m, language, cb),
Expand Down Expand Up @@ -73,7 +72,7 @@ function assertLanguage(m, language, base, path = "") {

// sync

function syncLang(m, language, cb) {
function syncLang(m, language, cb) {
load({
method: "registerLanguageDictionary",
url: `${l.languageBaseUrl(m)}/js/lock/${__VERSION__}/${language}.js`,
Expand Down
54 changes: 54 additions & 0 deletions test/i18n.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import expect from 'expect.js';
import Immutable from 'immutable';
import {initI18n} from '../src/i18n';
import { go } from '../src/sync';
import { swap, setEntity, updateEntity, observe } from '../src/store/index';
import { dataFns } from '../src/utils/data_utils';

import enDictionary from '../src/i18n/en';
import esDictionary from '../src/i18n/es';

const core = dataFns(["core"]);

describe("load i18n configuration", function() {

it("should merge and warn missing keys", function(done) {

const id = 1;

var m = Immutable.fromJS({
languageBaseUrl: "https://cdn.auth0.com",
ui: {
disableWarnings: true,
language: "es"
}
});

go(id);

observe("test", id, (m) => {
if (m.getIn(['sync', 'i18n', 'syncStatus']) === 'ok') {
assertLanguage(m.getIn(['i18n', 'strings']).toJS(), enDictionary, esDictionary)
done();
}
});

m = core.init(id, m);

m = initI18n(m);

m = swap(setEntity, "lock", id, m);
});
});

function assertLanguage(language, en, es) {
Object.keys(en).forEach( (key) => {
expect(language).to.have.property(key);
if (typeof en[key] === 'object') {
assertLanguage(language[key], en[key], es[key]);
}
else {
expect([en[key], es[key]]).to.contain(language[key]);
}
});
}

0 comments on commit 7c75e61

Please sign in to comment.