Skip to content

Commit

Permalink
fix options override on show
Browse files Browse the repository at this point in the history
  • Loading branch information
glena committed Nov 24, 2016
1 parent 551dd35 commit b0515bc
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,15 @@ export function overrideOptions(m, opts) {
}
}

if (opts.language) {
opts.dict = opts.dict || {};
if (opts.language || opts.languageDictionary) {

m = tset(m, ["ui", "language"], opts.language);
m = tset(m, ["ui", "dict"], opts.dict);
if (opts.language) {
m = tset(m, ["ui", "language"], opts.language);
}

if (opts.languageDictionary) {
m = tset(m, ["ui", "dict"], opts.languageDictionary);
}

m = i18n.initI18n(m);
}
Expand Down
2 changes: 1 addition & 1 deletion src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function initI18n(m) {
return set(m, "strings", base);
}

function assertLanguage(m, language, base, path = "") {
function assertLanguage(m, language, base, path = "") {
Object.keys(base).forEach( key => {
if (!language.hasOwnProperty(key)) {
l.warn(m, `language does not have property ${path}${key}`);
Expand Down
6 changes: 5 additions & 1 deletion support/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
});
});

lock.show();
lock.show({
languageDictionary: {
title: "sarlanga"
}
});

</script>
</body>
Expand Down
70 changes: 70 additions & 0 deletions test/override_options.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"use strict";
import { stub } from 'sinon';

import expect from 'expect.js';
import Immutable from 'immutable';

import { overrideOptions } from '../src/core/index';
import * as i18n from '../src/i18n';

describe("Override state with options on show", () => {

before(function() {
stub(i18n, "initI18n", (m) => {
return m;
});
});

after(function() {
i18n.initI18n.restore();
});

it('should merge and warn missing keys', () => {

var m = Immutable.fromJS({});

var new_options = {
allowedConnections: 'facebook',
languageDictionary: {
title: 'new_title'
},
flashMessage: {
type: 'success',
text: 'test'
},
auth: {
params: {
state: '1234'
}
},
language: 'es',
theme: {
primaryColor: 'red',
logo: 'http://test.com/logo.png'
}
};

m = overrideOptions(m, new_options);

expect(m.toJS()).to.eql({
core: {
transient: {
globalSuccess: 'test',
allowedConnections: "facebook",
ui: {
primaryColor: 'red',
logo: 'http://test.com/logo.png',
language: 'es',
dict: {
title: "new_title"
}
},
authParams: {
state: '1234'
}
}
}
});

});
});

0 comments on commit b0515bc

Please sign in to comment.