clear locale on each spec run, fix indentation

This commit is contained in:
Florian Staudacher 2014-02-23 17:13:01 +01:00
parent 1f98e1c639
commit a2aff720a2
2 changed files with 86 additions and 63 deletions

View file

@ -2,7 +2,8 @@
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
Diaspora.I18n = {
Diaspora.I18n = {
language: "en",
locale: {},
@ -35,5 +36,12 @@
}
return _.template(translatedMessage, views || {});
},
reset: function() {
this.locale = {};
if( arguments.length > 0 && !(_.isEmpty(arguments[0])) )
this.locale = arguments[0];
}
};
};

View file

@ -3,9 +3,7 @@
* the COPYRIGHT file.
*/
describe("Diaspora", function() {
describe("widgets", function() {
describe("i18n", function() {
describe("Diaspora.I18n", function() {
var locale = {namespace: {
message: "hey",
template: "<%= myVar %>",
@ -22,7 +20,11 @@ describe("Diaspora", function() {
}
};
describe("loadLocale", function() {
beforeEach(function(){
Diaspora.I18n.reset(); // run tests with clean locale
});
describe("::loadLocale", function() {
it("sets the class's locale variable", function() {
Diaspora.I18n.loadLocale(locale);
@ -40,7 +42,7 @@ describe("Diaspora", function() {
});
});
describe("t", function() {
describe("::t", function() {
var translation;
beforeEach(function() { Diaspora.I18n.loadLocale(locale); });
@ -66,6 +68,19 @@ describe("Diaspora", function() {
expect(Diaspora.I18n.t("missing.locale")).toEqual("");
});
});
describe("::reset", function(){
it("clears the current locale", function() {
Diaspora.I18n.loadLocale(locale);
Diaspora.I18n.reset()
expect(Diaspora.I18n.locale).toEqual({});
});
it("sets the locale to only a specific value", function() {
var data = { some: 'value' };
Diaspora.I18n.loadLocale(locale);
Diaspora.I18n.reset(data);
expect(Diaspora.I18n.locale).toEqual(data);
});
});
});