Skip to content

Commit

Permalink
added wct test for defaultLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Jubenville committed Apr 11, 2017
1 parent 100a7ce commit 752c7e3
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
</template>
</test-fixture>

<test-fixture id="defaultLanguage">
<template>
<x-translate use-default-language-if-missing default-language="en"></x-translate>
</template>
</test-fixture>

<test-fixture id="basic2">
<template>
<x-translate></x-translate>
Expand Down Expand Up @@ -110,6 +116,31 @@
assert.equal(app.$.missing.innerHTML, 'missing');
});

test('can fall back to default language when missing keys', function() {
var app = fixture('defaultLanguage');

app.resources = {
'en': {
'greeting': 'hello',
'missing': 'this text does not exist in french'
},
'fr' : {
'greeting': 'bonjour'
}
};

assert.equal(app.language, 'en');
assert.equal(app.$.output.innerHTML, 'hello');
assert.equal(app.$.missing.innerHTML, 'this text does not exist in french');

app.language = 'fr';
assert.equal(app.language, 'fr');
// ensure text where the key does exist in the new language is correctly translated
assert.equal(app.$.output.innerHTML, 'bonjour');
// ensure text where the key does not exist falls back to the default language
assert.equal(app.$.missing.innerHTML, 'this text does not exist in french');
});

test('can translate a string with a parameter', function() {
var app = fixture('interpolated');

Expand All @@ -131,7 +162,7 @@
// it's just 10$. This isn't something we control, so check the string
// is mostly right.
assert.equal(app.$.output.innerHTML.indexOf('Tout est à 10,00&nbsp;$'), 0);

app.language = 'en';
assert.equal(app.$.output.innerHTML, 'Everything is $10.00');

Expand Down

0 comments on commit 752c7e3

Please sign in to comment.