|
1024 | 1024 | }, 'out of left bound of array');
|
1025 | 1025 | });
|
1026 | 1026 |
|
| 1027 | + |
| 1028 | + ////////////////////////////////////////////////////////////////////////////// |
| 1029 | + Q.module('translateString', { beforeEach: function () { |
| 1030 | + addDropdownWidgetFunc(); |
| 1031 | + }}); |
| 1032 | + Q.test('translates a string with provided translation', function (assert) { |
| 1033 | + var $dropdown = $('#dropdown').localizationTool({ |
| 1034 | + strings: { |
| 1035 | + 'this is some text' : { |
| 1036 | + 'it_IT' : 'this is some translation 1', |
| 1037 | + 'jp_JP' : 'this is some translation 2', |
| 1038 | + 'fr_FR' : 'this is some translation 3' |
| 1039 | + } |
| 1040 | + } |
| 1041 | + }); |
| 1042 | + |
| 1043 | + assert.equal($dropdown.localizationTool('translateString', |
| 1044 | + 'this is some text', |
| 1045 | + 'it_IT' |
| 1046 | + ), 'this is some translation 1', 'got the expected string'); |
| 1047 | + |
| 1048 | + }); |
| 1049 | + |
| 1050 | + Q.test('throws an error when translation is made on an unknown language', function (assert) { |
| 1051 | + var $dropdown = $('#dropdown').localizationTool({ |
| 1052 | + strings: { |
| 1053 | + 'this is some text' : { |
| 1054 | + 'it_IT' : 'this is some translation 1', |
| 1055 | + 'jp_JP' : 'this is some translation 2', |
| 1056 | + 'fr_FR' : 'this is some translation 3' |
| 1057 | + } |
| 1058 | + } |
| 1059 | + }); |
| 1060 | + assert.throws(function () { |
| 1061 | + $dropdown.localizationTool('translateString', |
| 1062 | + 'this is some text', |
| 1063 | + 'fooLanguage' // this language is not knwon |
| 1064 | + ); |
| 1065 | + }, /The language code fooLanguage is not known/); |
| 1066 | + }); |
| 1067 | + |
| 1068 | + Q.test('throws an error when translation is not defined for the given language', function (assert) { |
| 1069 | + var $dropdown = $('#dropdown').localizationTool({ |
| 1070 | + strings: { |
| 1071 | + 'this is some text' : { |
| 1072 | + 'it_IT' : 'this is some translation 1', |
| 1073 | + 'jp_JP' : 'this is some translation 2', |
| 1074 | + 'fr_FR' : 'this is some translation 3' |
| 1075 | + } |
| 1076 | + } |
| 1077 | + }); |
| 1078 | + assert.throws(function () { |
| 1079 | + $dropdown.localizationTool('translateString', |
| 1080 | + 'this is some text', |
| 1081 | + 'de_DE' |
| 1082 | + ); |
| 1083 | + }, /A translation for the string 'this is some text' was not defined for language de_DE. Defined languages are: it_IT, jp_JP, fr_FR$/); |
| 1084 | + }); |
| 1085 | + |
| 1086 | + Q.test('throws an error when string is not translated in any language', function (assert) { |
| 1087 | + var $dropdown = $('#dropdown').localizationTool({ |
| 1088 | + strings: { |
| 1089 | + 'this is some text' : { |
| 1090 | + 'it_IT' : 'this is some translation 1', |
| 1091 | + 'jp_JP' : 'this is some translation 2', |
| 1092 | + 'fr_FR' : 'this is some translation 3' |
| 1093 | + } |
| 1094 | + } |
| 1095 | + }); |
| 1096 | + assert.throws(function () { |
| 1097 | + $dropdown.localizationTool('translateString', |
| 1098 | + 'this is some other text', |
| 1099 | + 'de_DE' // this language is not knwon |
| 1100 | + ); |
| 1101 | + }, /The string 'this is some other text' was not translated in any language./); |
| 1102 | + }); |
| 1103 | + |
1027 | 1104 | }(jQuery));
|
0 commit comments