From 117c26cfd3d0818c852b94317b05c6e94a34bc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Sat, 25 Jan 2014 21:01:43 -0300 Subject: [PATCH] Added tests for translations (env.t) --- test/spec/rootCtrlSpec.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/spec/rootCtrlSpec.js b/test/spec/rootCtrlSpec.js index 1b9e24c1bf..20bb41857f 100644 --- a/test/spec/rootCtrlSpec.js +++ b/test/spec/rootCtrlSpec.js @@ -28,5 +28,30 @@ describe('Root Controller', function() { expect(scope.contribText({level: 8, text: 'Blacksmith'}, {npc: 'NPC'})).to.eql('NPC'); }); + describe('i18n', function(){ + var t = env.t; + beforeEach(function(){ + env.translations = { + "text1": 'translatedText1', + "text2": '<%= number %> eggs', + "stringNotFound" : "String '<%= string %>' not found.", + }; + }); + + it('translates strings', function(){ + expect(t('')).to.eql("String '' not found."); + expect(t('text1')).to.eql('translatedText1'); + expect(t(' text1 ')).to.eql("String ' text1 ' not found."); + expect(t('text3')).to.eql("String 'text3' not found."); + }); + + it('interpolates strings', function(){ + expect(t('text2', {number: 2})).to.eql('2 eggs'); + expect(t('text2', {number: 'ten'})).to.eql('ten eggs'); + expect(t('text2', {n: 10, number: 'ten'})).to.eql('ten eggs'); + expect(t('text2')).to.eql('<%= number %> eggs'); + }); + }); + }); \ No newline at end of file