Skip to content

Commit

Permalink
Test coverage improving
Browse files Browse the repository at this point in the history
Little edit for I18NStore initialization to make possible
test the delault locale value.
  • Loading branch information
mircobe87 committed Aug 24, 2015
1 parent f624d68 commit c6da86c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
27 changes: 16 additions & 11 deletions web/client/stores/I18NStore.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,28 @@ const AvailableLang = {
"Italiano": "it-IT"
};

const _getDefaultLang = () => {
var lang;
if (navigator) {
lang = navigator.language || navigator.browserLanguage;
}
if (lang) {
const _getDefaultLang = locale => {
if (locale) {
for (let l in AvailableLang) {
if (AvailableLang.hasOwnProperty(l)) {
if (lang === AvailableLang[l]) {
return lang;
if (locale === AvailableLang[l]) {
return locale;
}
}
}
}
return "en-US";
};

var _i18nStore = {
locales: AvailableLang,
data: StaticLangStore[_getDefaultLang()]
var _i18nStore;

const _initStore = () => {
var l = navigator ? navigator.language || navigator.browserLanguage : "en-US";

_i18nStore = {
locales: AvailableLang,
data: StaticLangStore[_getDefaultLang(l)]
};
};

var I18NStore = assign({}, EventEmitter.prototype, {
Expand Down Expand Up @@ -91,6 +93,8 @@ const _actionsManager = action => {
}
};

_initStore();

Dispatcher.register(_actionsManager);

module.exports = I18NStore;
Expand All @@ -105,3 +109,4 @@ const _setMockedData = obj => {
_i18nStore = obj;
};
module.exports._set_mocked_data = _setMockedData;
module.exports._get_default_language = _getDefaultLang;
6 changes: 6 additions & 0 deletions web/client/stores/__tests__/I18NStore-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('This test for I18NStore', () => {
setTimeout(done);
});

it('checks _getDefaultLang()', () => {
expect(I18NStore._get_default_language()).toEqual("en-US");
expect(I18NStore._get_default_language("it-IT")).toEqual("it-IT");
expect(I18NStore._get_default_language("something")).toEqual("en-US");
});

it('checks getCurrentLocale()', () => {
const mockStoreData = {
data: {
Expand Down

0 comments on commit c6da86c

Please sign in to comment.