handlebars-i18n 1.6.4 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,6 @@
2
2
  * Tests for handlebars-i18n.js
3
3
  *
4
4
  * usage:
5
- * $ cd test
6
5
  * $ npm run test
7
6
  */
8
7
 
@@ -12,155 +11,180 @@ const expect = require('chai').expect;
12
11
  const Handlebars = require('handlebars');
13
12
  const i18next = require('i18next');
14
13
  const HandlebarsI18n = require('../dist/handlebars-i18n');
15
- //const HandlebarsModified = require("handlebars");
16
14
 
17
- describe('handlebars-i18n Test', function() {
15
+ describe('handlebars-i18n Tests', function () {
18
16
 
19
17
  const i18nInitObj = {
20
- resources : {
21
- 'en' : {
22
- translation : {
18
+ resources: {
19
+ 'en': {
20
+ translation: {
23
21
  'key1': 'What is good?',
24
22
  'key2': '{{what}} is {{adverb}}.'
25
23
  }
26
24
  },
27
- 'de' : {
25
+ 'de': {
28
26
  translation: {
29
27
  'key1': 'Was ist gut?',
30
28
  'key2': '{{what}} ist {{adverb}}.'
31
29
  }
32
30
  }
33
31
  },
34
- lng : 'en'
32
+ lng: 'en'
35
33
  };
36
34
 
37
35
  const hI18n = HandlebarsI18n.init();
38
36
 
39
- // -- Tests for method init() -- //
40
37
 
41
- it('after method call init() should return an object (HandlebarsEnvironment)', function() {
38
+ /****************************************
39
+ Tests against method init()
40
+ ****************************************/
41
+
42
+ it('after method call init() should return an object (HandlebarsEnvironment)', function () {
42
43
  assert.isObject(hI18n);
43
44
  });
44
45
 
45
- it('after method call init() HandlebarsEnvironment object should have a function __', function() {
46
+ it('after method call init() HandlebarsEnvironment object should have a function __', function () {
46
47
  assert.isFunction(hI18n.helpers.__);
47
48
  });
48
49
 
49
- it('after method call init() HandlebarsEnvironment object should have a function _locale', function() {
50
+ it('after method call init() HandlebarsEnvironment object should have a function _locale', function () {
50
51
  assert.isFunction(hI18n.helpers._locale);
51
52
  });
52
53
 
53
- it('after method call init() HandlebarsEnvironment object should have a function localeIs', function() {
54
+ it('after method call init() HandlebarsEnvironment object should have a function localeIs', function () {
54
55
  assert.isFunction(hI18n.helpers.localeIs);
55
56
  });
56
57
 
57
- it('after method call init() HandlebarsEnvironment object should have a function _date', function() {
58
+ it('after method call init() HandlebarsEnvironment object should have a function _date', function () {
58
59
  assert.isFunction(hI18n.helpers._date);
59
60
  });
60
61
 
61
- it('after method call init() HandlebarsEnvironment object should have a function _num', function() {
62
+ it('after method call init() HandlebarsEnvironment object should have a function _dateRel', function () {
63
+ assert.isFunction(hI18n.helpers._dateRel);
64
+ });
65
+
66
+ it('after method call init() HandlebarsEnvironment object should have a function _dateDiff', function () {
67
+ assert.isFunction(hI18n.helpers._dateDiff);
68
+ });
69
+
70
+ it('after method call init() HandlebarsEnvironment object should have a function _num', function () {
62
71
  assert.isFunction(hI18n.helpers._num);
63
72
  });
64
73
 
65
- it('after method call init() HandlebarsEnvironment object should have a function _price', function() {
74
+ it('after method call init() HandlebarsEnvironment object should have a function _price', function () {
66
75
  assert.isFunction(hI18n.helpers._price);
67
76
  });
68
77
 
69
78
  // -- Tests for method init() with override Argument -- //
70
79
 
71
- it('after method call init(overrideHndlbrs) with custom handlebars Object, HandlebarsEnvironment object should have custom function foo', function() {
80
+ it('after method call init(overrideHndlbrs) with custom handlebars Object, HandlebarsEnvironment object should have custom function foo', function () {
72
81
  const HandlebarsModified = require('handlebars');
73
- HandlebarsModified.registerHelper('foo', function() { return true });
82
+ HandlebarsModified.registerHelper('foo', function () {
83
+ return true
84
+ });
74
85
  const hI18nMod = HandlebarsI18n.init(HandlebarsModified);
75
86
  assert.isFunction(hI18nMod.helpers.foo);
76
87
  });
77
88
 
78
- it('after method call init(null, overrideI18n) with custom i18n Object, i18n object should have custom function foo', function() {
89
+ it('after method call init(null, overrideI18n) with custom i18n Object, i18n object should have custom function foo', function () {
79
90
  const i18nModified = require('i18next');
80
- i18nModified.init({supportedLngs: ['de','en']});
91
+ i18nModified.init({supportedLngs: ['de', 'en']});
81
92
  const hI18nMod = HandlebarsI18n.init(null, i18nModified);
82
- assert.isFunction(function(){}); // write a test here
93
+ assert.isFunction(function () {
94
+ }); // write a test here
83
95
  });
84
96
 
85
97
 
86
- // -- Tests for function _locale -- //
98
+ /****************************************
99
+ Tests against function _locale
100
+ ****************************************/
87
101
 
88
- it('expecting function _locale to be [undefined] as long as no language was set with i18next.init', function() {
102
+ it('expecting function _locale to be [undefined] as long as no language was set with i18next.init', function () {
89
103
  i18next.init(); // empty init
90
104
  const res = hI18n.helpers._locale();
91
105
  expect(res).to.be.undefined;
92
106
  });
93
107
 
94
- it('function _locale should return "en" if language is specified as "en" by init Object', function() {
108
+ it('function _locale should return "en" if language is specified as "en" by init Object', function () {
95
109
  i18next.init(i18nInitObj); // initialize with data
96
110
  const res = hI18n.helpers._locale();
97
111
  assert.equal('en', res);
98
112
  });
99
113
 
100
- it('function _locale should return "de" after language change to "de"', function() {
114
+ it('function _locale should return "de" after language change to "de"', function () {
101
115
  i18next.changeLanguage('de');
102
116
  const res = hI18n.helpers._locale();
103
117
  assert.equal('de', res);
104
118
  });
105
119
 
106
120
 
107
- // -- Tests for function isLocale -- //
121
+ /****************************************
122
+ Tests against function isLocale
123
+ ****************************************/
108
124
 
109
- it('function isLocale should return TRUE when current language is set to "en" and given "en" as parameter', function() {
125
+ it('function isLocale should return TRUE when current language is set to "en" and given "en" as parameter', function () {
110
126
  i18next.changeLanguage('en');
111
127
  const res = hI18n.helpers.localeIs('en');
112
128
  assert.equal(true, res);
113
129
  });
114
130
 
115
- it('function isLocale should return FALSE when current language is set to "en" and given "someOther" as parameter', function() {
131
+ it('function isLocale should return FALSE when current language is set to "en" and given "someOther" as parameter', function () {
116
132
  i18next.changeLanguage('en');
117
133
  const res = hI18n.helpers.localeIs('someOther');
118
134
  assert.equal(false, res);
119
135
  });
120
136
 
121
137
 
122
- // -- Tests for function __ -- //
138
+ /****************************************
139
+ Tests against function __
140
+ ****************************************/
123
141
 
124
- it('expecting __ to throw error when called with no parameter', function() {
125
- expect(function() { hI18n.helpers.__() }).to.throw();
142
+ it('expect __ to throw error when called with no parameter', function () {
143
+ expect(function () {
144
+ hI18n.helpers.__()
145
+ }).to.throw();
126
146
  });
127
147
 
128
- it('function __ should return a SafeString object with property "string" where "string" returns the first argument given to __', function() {
129
- const res = hI18n.helpers.__("someNoneExitingKey", { hash: {} });
148
+ it('function __ should return a SafeString object with property "string" where "string" returns the first argument given to __', function () {
149
+ const res = hI18n.helpers.__("someNoneExitingKey", {hash: {}});
130
150
  assert.equal("someNoneExitingKey", res.string);
131
151
  });
132
152
 
133
- it('function __ should return a SafeString object with property "string" where "string" contains "What is good?!', function() {
134
- const res = hI18n.helpers.__("key1", { hash: {} });
153
+ it('function __ should return a SafeString object with property "string" where "string" contains "What is good?!', function () {
154
+ const res = hI18n.helpers.__("key1", {hash: {}});
135
155
  assert.equal("What is good?", res.string);
136
156
  });
137
157
 
138
- it('function __ should return a SafeString object with property "string" where "string" contains "Was ist gut?"', function() {
158
+ it('function __ should return a SafeString object with property "string" where "string" contains "Was ist gut?"', function () {
139
159
  i18next.changeLanguage('de');
140
- const res = hI18n.helpers.__("key1", { hash: {} });
160
+ const res = hI18n.helpers.__("key1", {hash: {}});
141
161
  assert.equal("Was ist gut?", res.string);
142
162
  });
143
163
 
144
- it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next is good."', function() {
164
+ it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next is good."', function () {
145
165
  i18next.changeLanguage('en');
146
- const res = hI18n.helpers.__("key2", { hash: { what : "handlebarsI18next", adverb : "good" } });
166
+ const res = hI18n.helpers.__("key2", {hash: {what: "handlebarsI18next", adverb: "good"}});
147
167
  assert.equal("handlebarsI18next is good.", res.string);
148
168
  });
149
169
 
150
- it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next ist gut."', function() {
170
+ it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next ist gut."', function () {
151
171
  i18next.changeLanguage('de');
152
- const res = hI18n.helpers.__("key2", { hash: { what: "handlebarsI18next", adverb: "gut" } });
172
+ const res = hI18n.helpers.__("key2", {hash: {what: "handlebarsI18next", adverb: "gut"}});
153
173
  assert.equal("handlebarsI18next ist gut.", res.string);
154
174
  });
155
175
 
156
176
 
157
- // -- Tests for function _date -- //
177
+ /****************************************
178
+ Tests against function _date
179
+ ****************************************/
158
180
 
159
- it('expect function _date to throw error when called with invalid date parameter', function() {
160
- expect(function() { hI18n.helpers._date('someStrangeString') }).to.throw("Invalid valid date passed to format");
181
+ it('expect function _date to throw error when called with invalid date parameter', function () {
182
+ expect(function () {
183
+ hI18n.helpers._date('someStrangeString')
184
+ }).to.throw("Invalid valid date passed to format");
161
185
  });
162
186
 
163
- it('function _date should return today\'s date in Intl default format when called without parameter', function() {
187
+ it('function _date should return todays date in Intl default format when called without parameter', function () {
164
188
  i18next.changeLanguage('en');
165
189
  const today = new Date();
166
190
  const todayFormated = new Intl.DateTimeFormat().format(today);
@@ -169,180 +193,421 @@ describe('handlebars-i18n Test', function() {
169
193
  assert.equal(todayFormated, res);
170
194
  });
171
195
 
172
- it('function _date should return today\'s date in Intl default format when called with parameter, "Today" or "Now" no matter of upper or lower case writing', function() {
173
- i18next.changeLanguage('en');
174
- const today = new Date();
175
- const todayFormated = new Intl.DateTimeFormat().format(today);
196
+ it('function _date should return todays date in Intl default format when called with parameter, "Today" or "Now" no matter of upper or lower case writing',
197
+ function () {
198
+ i18next.changeLanguage('en');
199
+ const today = new Date();
200
+ const todayFormated = new Intl.DateTimeFormat().format(today);
176
201
 
177
- assert.equal(todayFormated, hI18n.helpers._date("today"));
178
- assert.equal(todayFormated, hI18n.helpers._date("Today"));
179
- assert.equal(todayFormated, hI18n.helpers._date("TODAY"));
180
- assert.equal(todayFormated, hI18n.helpers._date("now"));
181
- assert.equal(todayFormated, hI18n.helpers._date("Now"));
182
- assert.equal(todayFormated, hI18n.helpers._date("NOW"));
183
- });
202
+ assert.equal(todayFormated, hI18n.helpers._date("today"));
203
+ assert.equal(todayFormated, hI18n.helpers._date("Today"));
204
+ assert.equal(todayFormated, hI18n.helpers._date("TODAY"));
205
+ assert.equal(todayFormated, hI18n.helpers._date("now"));
206
+ assert.equal(todayFormated, hI18n.helpers._date("Now"));
207
+ assert.equal(todayFormated, hI18n.helpers._date("NOW"));
208
+ });
184
209
 
185
- it('function _date should return "1/1/1970" (Intl default format) when called with parameter 1 as number ', function() {
210
+ it('function _date should return "1/1/1970" (Intl default format) when called with parameter 1 as number ', function () {
186
211
  i18next.changeLanguage('en');
187
212
  const res = hI18n.helpers._date(1);
188
213
  assert.equal('1/1/1970', res);
189
214
  });
190
215
 
191
- it('function _date should return "12/17/1995" (Intl default format) when called with parameter "1995-12-17T03:24:00"', function() {
216
+ it('function _date should return "12/17/1995" (Intl default format) when called with parameter "1995-12-17T03:24:00"', function () {
192
217
  i18next.changeLanguage('en');
193
218
  const res = hI18n.helpers._date('1995-12-17T03:24:00');
194
219
  assert.equal('12/17/1995', res);
195
220
  });
196
221
 
197
- it('function _date should return "12/17/1995" (Intl default format) when called with parameter "December 17, 1995 03:24:00"', function() {
222
+ it('function _date should return "12/17/1995" (Intl default format) when called with parameter "December 17, 1995 03:24:00"', function () {
198
223
  i18next.changeLanguage('en');
199
224
  const res = hI18n.helpers._date('December 17, 1995 03:24:00');
200
225
  assert.equal('12/17/1995', res);
201
226
  });
202
227
 
203
- it('function _date should return "1/1/2020" (Intl default format) when called with parameter "[2020]"', function() {
228
+ it('function _date should return "1/1/2020" (Intl default format) when called with parameter "[2020]"', function () {
204
229
  i18next.changeLanguage('en');
205
230
  const res = hI18n.helpers._date('[1995]');
206
231
  assert.equal('1/1/1995', res);
207
232
  });
208
233
 
209
- it('function _date should return "12/1/1995" (Intl default format) when called with parameter "[2020,11]"', function() {
234
+ it('function _date should return "12/1/1995" (Intl default format) when called with parameter "[2020,11]"', function () {
210
235
  i18next.changeLanguage('en');
211
236
  const res = hI18n.helpers._date('[1995,11]');
212
237
  assert.equal('12/1/1995', res);
213
238
  });
214
239
 
215
- it('function _date should return "12/17/1995" (Intl default format) when called with parameter "[2020,11,17]"', function() {
240
+ it('function _date should return "12/17/1995" (Intl default format) when called with parameter "[2020,11,17]"', function () {
216
241
  i18next.changeLanguage('en');
217
242
  const res = hI18n.helpers._date('[1995,11,17]');
218
243
  assert.equal('12/17/1995', res);
219
244
  });
220
245
 
221
- it('function _date should return "12/1/95" when called with parameter "[2020,11,01] and specifying options"', function() {
246
+ it('function _date should return "12/1/95" when called with parameter "[2020,11,01] and specifying options"', function () {
222
247
  i18next.changeLanguage('en');
223
- const res = hI18n.helpers._date('[1995,11,1]', { hash: { year:"2-digit", month:"2-digit", day:"2-digit" } });
248
+ const res = hI18n.helpers._date('[1995,11,1]', {hash: {year: "2-digit", month: "2-digit", day: "2-digit"}});
224
249
  assert.equal('12/1/95', res);
225
250
  });
226
251
 
227
- it('function _date should return "01.12.95" when called with parameter "[2020,11,01] and specifying options an language set to "de"', function() {
252
+ it('function _date should return "01.12.95" when called with parameter "[2020,11,01] and specifying options an language set to "de"', function () {
228
253
  i18next.changeLanguage('de');
229
- const res = hI18n.helpers._date('[1995,11,1]', { hash: { year:"2-digit", month:"2-digit", day:"2-digit" } });
254
+ const res = hI18n.helpers._date('[1995,11,1]', {hash: {year: "2-digit", month: "2-digit", day: "2-digit"}});
230
255
  assert.equal('01.12.95', res);
231
256
  });
232
257
 
233
258
 
234
- // -- Tests for function _num -- //
259
+ /****************************************
260
+ Tests against function _dateRel
261
+ ****************************************/
262
+
263
+ it('expect function _dateRel to throw error when called without parameter', function () {
264
+ expect(function () {
265
+ hI18n.helpers._dateRel()
266
+ }).to.throw('Invalid "number" argument: NaN');
267
+ });
268
+
269
+ it('expect function _dateRel to throw error when called with invalid date parameter', function () {
270
+ expect(function () {
271
+ hI18n.helpers._dateRel('someStrangeString')
272
+ }).to.throw('Invalid "number" argument: NaN');
273
+ });
274
+
275
+ it('expect function _dateRel to throw error when called with non-existent language shortcode', function () {
276
+ i18next.changeLanguage('invalid');
277
+ expect(function () {
278
+ hI18n.helpers._dateRel(1, {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: "day"}})
279
+ }).to.throw('No locale data passed');
280
+ });
281
+
282
+ it('expect function _dateRel to return \'in 1 hour\' when called with \'en\' and first parameter being 1', function () {
283
+ i18next.changeLanguage('en');
284
+ const res = hI18n.helpers._dateRel(1);
285
+ assert.equal('in 1 hour', res);
286
+ });
287
+
288
+ it('expect function _dateRel to return \'1 hour ago\' when called with \'en\' and first parameter being -1', function () {
289
+ i18next.changeLanguage('en');
290
+ const res = hI18n.helpers._dateRel(-1);
291
+ assert.equal('1 hour ago', res);
292
+ });
293
+
294
+ it('expect function _dateRel to return \'in 1 second\' when called with \'en\' and first parameter being 1 and according options', function () {
295
+ i18next.changeLanguage('en');
296
+ const res = hI18n.helpers._dateRel(1, {
297
+ hash: {
298
+ localeMatcher: "best fit",
299
+ numeric: "always",
300
+ style: "long",
301
+ unit: "seconds"
302
+ }
303
+ });
304
+ assert.equal('in 1 second', res);
305
+ });
306
+
307
+ it('expect function _dateRel to return \'in 1 Tag\' when called with \'de\' and paramter 1 and according options', function () {
308
+ i18next.changeLanguage('de');
309
+ const res = hI18n.helpers._dateRel(1, {
310
+ hash: {
311
+ localeMatcher: "best fit",
312
+ numeric: "always",
313
+ style: "long",
314
+ unit: "day"
315
+ }
316
+ });
317
+ assert.equal('in 1 Tag', res);
318
+ });
319
+
320
+
321
+ /****************************************
322
+ Tests against function _dateDiff
323
+ ****************************************/
324
+
325
+ it('function _dateDiff should return null when called with no parameter', function () {
326
+ i18next.changeLanguage('en');
327
+ const res = hI18n.helpers._dateDiff();
328
+ assert.equal(null, res);
329
+ });
330
+
331
+ it('expect function _dateDiff to throw error when called with invalid 1. date parameter', function () {
332
+ expect(function () {
333
+ hI18n.helpers._dateDiff('someStrangeString', '1995-12-17T03:24:00')
334
+ })
335
+ .to.throw('Invalid "number" argument: NaN');
336
+ });
337
+
338
+ it('expect function _dateDiff to throw error when called with invalid 2. date parameter', function () {
339
+ expect(function () {
340
+ hI18n.helpers._dateDiff('1995-12-17T03:24:00', 'someStrangeString')
341
+ })
342
+ .to.throw('Invalid "number" argument: NaN');
343
+ });
344
+
345
+ it('expect function _dateDiff to return null when called with empty argument', function () {
346
+ i18next.changeLanguage('en');
347
+ const res = hI18n.helpers._dateDiff('');
348
+ assert.equal(null, res);
349
+ });
350
+
351
+ it('expect function _dateDiff to return "in 0 hours", when dates are identical', function () {
352
+ i18next.changeLanguage('en');
353
+ const res = hI18n.helpers._dateDiff('1995-12-17T00:00:00', '1995-12-17T00:00:00');
354
+ assert.equal('in 0 hours', res);
355
+ });
356
+
357
+ // -- Test year -- //
358
+
359
+ it('expect function _dateDiff to return "in 1 year"', function () {
360
+ i18next.changeLanguage('en');
361
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: "year"}};
362
+ const res = hI18n.helpers._dateDiff('1996-12-17T00:00:00', '1995-12-17T00:00:00', hash);
363
+ assert.equal('in 1 year', res);
364
+ });
365
+
366
+ it('expect function _dateDiff to return "1 year ago"', function () {
367
+ i18next.changeLanguage('en');
368
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: "year"}};
369
+ const res = hI18n.helpers._dateDiff('1995-12-17T00:00:00', '1996-12-17T00:00:00', hash);
370
+ assert.equal('1 year ago', res);
371
+ });
372
+
373
+ // -- Test quarter -- //
374
+
375
+ it('expect function _dateDiff to return "in 1 quarter"', function () {
376
+ i18next.changeLanguage('en');
377
+ const unit = 'quarter';
378
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
379
+ const res = hI18n.helpers._dateDiff('1996-12-17T00:00:00', '1996-09-16T00:00:00', hash);
380
+ assert.equal(`in 1 ${unit}`, res);
381
+ });
382
+
383
+ it('expect function _dateDiff to return "1 quarter ago"', function () {
384
+ i18next.changeLanguage('en');
385
+ const unit = 'quarter';
386
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
387
+ const res = hI18n.helpers._dateDiff('1996-09-16T00:00:00', '1996-12-17T00:00:00', hash);
388
+ assert.equal(`1 ${unit} ago`, res);
389
+ });
390
+
391
+ // -- Test month -- //
392
+
393
+ it('expect function _dateDiff to return "in 1 month"', function () {
394
+ i18next.changeLanguage('en');
395
+ const unit = 'month';
396
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
397
+ const res = hI18n.helpers._dateDiff('1996-12-17T00:00:00', '1996-11-16T00:00:00', hash);
398
+ assert.equal(`in 1 ${unit}`, res);
399
+ });
400
+
401
+ it('expect function _dateDiff to return "1 month ago"', function () {
402
+ i18next.changeLanguage('en');
403
+ const unit = 'month';
404
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
405
+ const res = hI18n.helpers._dateDiff('1996-11-16T00:00:00', '1996-12-17T00:00:00', hash);
406
+ assert.equal(`1 ${unit} ago`, res);
407
+ });
408
+
409
+ // -- Test week -- //
410
+
411
+ it('expect function _dateDiff to return "in 1 week"', function () {
412
+ i18next.changeLanguage('en');
413
+ const unit = 'week';
414
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
415
+ const res = hI18n.helpers._dateDiff('1996-12-08T00:00:00', '1996-12-01T00:00:00', hash);
416
+ assert.equal(`in 1 ${unit}`, res);
417
+ });
418
+
419
+ it('expect function _dateDiff to return "1 week ago"', function () {
420
+ i18next.changeLanguage('en');
421
+ const unit = 'week';
422
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
423
+ const res = hI18n.helpers._dateDiff('1996-12-01T00:00:00', '1996-12-08T00:00:00', hash);
424
+ assert.equal(`1 ${unit} ago`, res);
425
+ });
426
+
427
+ // -- Test day -- //
428
+
429
+ it('expect function _dateDiff to return "in 1 day"', function () {
430
+ i18next.changeLanguage('en');
431
+ const unit = 'day';
432
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
433
+ const res = hI18n.helpers._dateDiff('1996-12-08T00:00:00', '1996-12-07T00:00:00', hash);
434
+ assert.equal(`in 1 ${unit}`, res);
435
+ });
436
+
437
+ it('expect function _dateDiff to return "1 day ago"', function () {
438
+ i18next.changeLanguage('en');
439
+ const unit = 'day';
440
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
441
+ const res = hI18n.helpers._dateDiff('1996-12-07T00:00:00', '1996-12-08T00:00:00', hash);
442
+ assert.equal(`1 ${unit} ago`, res);
443
+ });
444
+
445
+ // -- Test minute -- //
446
+
447
+ it('expect function _dateDiff to return "in 1 minute"', function () {
448
+ i18next.changeLanguage('en');
449
+ const unit = 'minute';
450
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
451
+ const res = hI18n.helpers._dateDiff('1996-12-08T00:01:00', '1996-12-08T00:00:00', hash);
452
+ assert.equal(`in 1 ${unit}`, res);
453
+ });
454
+
455
+ it('expect function _dateDiff to return "1 minute ago"', function () {
456
+ i18next.changeLanguage('en');
457
+ const unit = 'minute';
458
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
459
+ const res = hI18n.helpers._dateDiff('1996-12-08T00:00:00', '1996-12-08T00:01:00', hash);
460
+ assert.equal(`1 ${unit} ago`, res);
461
+ });
462
+
463
+ // -- Test second -- //
464
+
465
+ it('expect function _dateDiff to return "in 1 second"', function () {
466
+ i18next.changeLanguage('en');
467
+ const unit = 'second';
468
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
469
+ const res = hI18n.helpers._dateDiff('1996-12-08T00:00:01', '1996-12-08T00:00:00', hash);
470
+ assert.equal(`in 1 ${unit}`, res);
471
+ });
472
+
473
+ it('expect function _dateDiff to return "1 second ago"', function () {
474
+ i18next.changeLanguage('en');
475
+ const unit = 'second';
476
+ const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
477
+ const res = hI18n.helpers._dateDiff('1996-12-08T00:00:00', '1996-12-08T00:00:01', hash);
478
+ assert.equal(`1 ${unit} ago`, res);
479
+ });
480
+
481
+
482
+ /****************************************
483
+ Tests against function _num
484
+ ****************************************/
235
485
 
236
- it('function _num should return comma separated triples of decimals when language is "en"', function() {
486
+ it('function _num should return comma separated triples of decimals when language is "en"', function () {
237
487
  i18next.changeLanguage('en');
238
- const res = hI18n.helpers._num(4000000, { hash: {} });
488
+ const res = hI18n.helpers._num(4000000, {hash: {}});
239
489
  assert.equal('4,000,000', res);
240
490
  });
241
491
 
242
- it('function _num should return dot separated triples of decimals when language is "de"', function() {
492
+ it('function _num should return dot separated triples of decimals when language is "de"', function () {
243
493
  i18next.changeLanguage('de');
244
- const res = hI18n.helpers._num(4000000, { hash: {} });
494
+ const res = hI18n.helpers._num(4000000, {hash: {}});
245
495
  assert.equal('4.000.000', res);
246
496
  });
247
497
 
248
- it('function _num should return comma separated triples of decimals and 2 fraction digits"', function() {
498
+ it('function _num should return comma separated triples of decimals and 2 fraction digits"', function () {
249
499
  i18next.changeLanguage('en');
250
- const res = hI18n.helpers._num(4000000, { hash: { minimumFractionDigits : 2 } });
500
+ const res = hI18n.helpers._num(4000000, {hash: {minimumFractionDigits: 2}});
251
501
  assert.equal('4,000,000.00', res);
252
502
  });
253
503
 
254
- it('function _num should return dot separated triples of decimals and 2 fraction digits when language is "de"', function() {
504
+ it('function _num should return dot separated triples of decimals and 2 fraction digits when language is "de"', function () {
255
505
  i18next.changeLanguage('de');
256
- const res = hI18n.helpers._num(4000000, { hash: { minimumFractionDigits : 2 } });
506
+ const res = hI18n.helpers._num(4000000, {hash: {minimumFractionDigits: 2}});
257
507
  assert.equal('4.000.000,00', res);
258
508
  });
259
509
 
260
510
 
261
- // -- Tests for function _price -- //
511
+ /****************************************
512
+ Tests against function _price
513
+ ****************************************/
262
514
 
263
- it('function _currency should return price in € written in comma separated triples of decimals and 2 fraction digits with leading currency symbol', function() {
515
+ it('function _currency should return price in € written in comma separated triples of decimals and 2 fraction digits with leading currency symbol', function () {
264
516
  i18next.changeLanguage('en');
265
- const res = hI18n.helpers._price(4000000, { hash: {} });
517
+ const res = hI18n.helpers._price(4000000, {hash: {}});
266
518
  assert.equal('€4,000,000.00', res);
267
519
  });
268
520
 
269
- it('function _currency should return price in € written in dot separated triples of decimals and 2 fraction digits with trailing currency symbol', function() {
521
+ it('function _currency should return price in € written in dot separated triples of decimals and 2 fraction digits with trailing currency symbol', function () {
270
522
  i18next.changeLanguage('de');
271
- const res = hI18n.helpers._price(4000000, { hash: {} });
523
+ const res = hI18n.helpers._price(4000000, {hash: {}});
272
524
  assert.isString(res);
273
525
  assert.equal('4.000.000,00 €', res);
274
526
  });
275
527
 
276
- it('function _currency should return price in ¥ written in comma separated triples of decimals with leading currency symbol', function() {
528
+ it('function _currency should return price in ¥ written in comma separated triples of decimals with leading currency symbol', function () {
277
529
  i18next.changeLanguage('en');
278
- const res = hI18n.helpers._price(4000000, { hash: { currency: 'JPY', maximumFractionDigits: 0 } });
530
+ const res = hI18n.helpers._price(4000000, {hash: {currency: 'JPY', maximumFractionDigits: 0}});
279
531
  assert.equal('¥4,000,000', res);
280
532
  });
281
533
 
282
- it('function _currency should return price in ¥ written in comma separated triples of decimals with trailing currency symbol', function() {
534
+ it('function _currency should return price in ¥ written in comma separated triples of decimals with trailing currency symbol', function () {
283
535
  i18next.changeLanguage('de');
284
- const res = hI18n.helpers._price(4000000, { hash: { currency: 'JPY', maximumFractionDigits: 0 } });
536
+ const res = hI18n.helpers._price(4000000, {hash: {currency: 'JPY', maximumFractionDigits: 0}});
285
537
  assert.equal('4.000.000 ¥', res);
286
538
  });
287
539
 
288
540
 
289
- // -- Tests for method configure() -- //
541
+ /****************************************
542
+ Tests against method configure()
543
+ ****************************************/
290
544
 
291
- it('method configure() should return false if called without argument', function() {
545
+ it('method configure() should return false if called without argument', function () {
292
546
  const configure = HandlebarsI18n.configure();
293
547
  assert.isNotOk(configure);
294
548
  });
295
549
 
296
- it('method configure() should return false if called with empty array []', function() {
550
+ it('method configure() should return false if called with empty array []', function () {
297
551
  const configure = HandlebarsI18n.configure([]);
298
552
  assert.isNotOk(configure);
299
553
  });
300
554
 
301
- it('method configure() should return false if called with only one argument', function() {
555
+ it('method configure() should return false if called with only one argument', function () {
302
556
  const configure = HandlebarsI18n.configure('en');
303
557
  assert.isNotOk(configure);
304
558
  });
305
559
 
306
- it('method configure() should return false if called with language argument and invalid second argument', function() {
560
+ it('method configure() should return false if called with language argument and invalid second argument', function () {
307
561
  const configure = HandlebarsI18n.configure('en', 'somestrangeinput');
308
562
  assert.isNotOk(configure);
309
563
  });
310
564
 
311
- it('method configure() should return false if called with language argument "en" and second argument "DateTimeFormat" and Number (invalid argument) as third', function() {
565
+ it('method configure() should return false if called with language argument "en" and second argument "DateTimeFormat" and Number (invalid argument) as third', function () {
312
566
  const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', 12);
313
567
  assert.isNotOk(configure);
314
568
  });
315
569
 
316
- it('method configure() should return true if called with language argument "en" and second argument "DateTimeFormat" and options object as third argument', function() {
317
- const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', { year:'numeric' } );
570
+ it('method configure() should return true if called with language argument "en" and second argument "DateTimeFormat" and options object as third argument', function () {
571
+ const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {year: 'numeric'});
318
572
  assert.isOk(configure);
319
573
  });
320
574
 
321
- it('method configure() should return true if called with arguments "en", "DateTimeFormat", { year:"numeric" } and a string as custom configuration name', function() {
322
- const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', { year:'numeric' }, "my-custom-conf" );
575
+ it('method configure() should return true if called with arguments "en", "DateTimeFormat", { year:"numeric" } and a string as custom configuration name', function () {
576
+ const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {year: 'numeric'}, "my-custom-conf");
323
577
  assert.isOk(configure);
324
578
  });
325
579
 
326
- it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional object (invalid argument)', function() {
327
- const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', { year:'numeric' }, {} );
580
+ it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional object (invalid argument)', function () {
581
+ const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {year: 'numeric'}, {});
328
582
  assert.isNotOk(configure);
329
583
  });
330
584
 
331
- it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional empty string (invalid argument)', function() {
332
- const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', { year:'numeric' }, "" );
585
+ it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional empty string (invalid argument)', function () {
586
+ const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {year: 'numeric'}, "");
333
587
  assert.isNotOk(configure);
334
588
  });
335
589
 
590
+ it('method configure() should return true if called with arguments "en", "RelativeTimeFormat", { localeMatcher: "best fit", numeric: "always", style: "long" }', function () {
591
+ const configure = HandlebarsI18n.configure('en', 'RelativeTimeFormat', {
592
+ localeMatcher: "best fit",
593
+ numeric: "always",
594
+ style: "long"
595
+ });
596
+ assert.isOk(configure);
597
+ });
336
598
 
337
- // -- Tests for method reset() -- //
338
599
 
339
- it('method reset() should return TRUE if called', function() {
600
+ /****************************************
601
+ Tests against method reset()
602
+ ****************************************/
603
+
604
+ it('method reset() should return TRUE if called', function () {
340
605
  const res = HandlebarsI18n.reset();
341
606
  assert.isOk(res);
342
607
  });
343
608
 
344
- it('function _num should return Intl standard format (no fraction digits) after reset() beeing called', function() {
345
- HandlebarsI18n.configure('en', 'NumberFormat', { minimumFractionDigits:4 } );
609
+ it('function _num should return Intl standard format (no fraction digits) after reset() being called', function () {
610
+ HandlebarsI18n.configure('en', 'NumberFormat', {minimumFractionDigits: 4});
346
611
  i18next.changeLanguage('en');
347
612
  HandlebarsI18n.reset();
348
613
  const res = hI18n.helpers._num(4000000);
@@ -350,226 +615,399 @@ describe('handlebars-i18n Test', function() {
350
615
  });
351
616
 
352
617
 
353
- // -- Tests for custom format configurations for function _date -- //
618
+ /********************************************************************
619
+ Tests for custom format configurations for function _date
620
+ ********************************************************************/
354
621
 
355
622
  it('function _date when called after configure() with defined custom format (year:2-digit) should return ' +
356
- 'date "95" when language is "en"', function() {
357
- HandlebarsI18n.configure('en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format');
623
+ 'date "95" when language is "en"', function () {
624
+ HandlebarsI18n.configure('en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format');
358
625
  i18next.changeLanguage('en');
359
- const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-custom-format'} });
626
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-custom-format'}});
360
627
  assert.equal('95', res);
361
628
  });
362
629
 
363
- it('function _date when called after configure() with defined custom format (year:2-digit) given as ARRAY should return ' +
364
- 'date "12/17/95" when language is "en"', function() {
365
- HandlebarsI18n.configure(['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format']);
630
+ it('function _date when called after configure() with defined custom format (year:numeric) given as ARRAY should return ' +
631
+ 'date "12/17/95" when language is "en"', function () {
632
+ HandlebarsI18n.configure(['en', 'DateTimeFormat', {year: "numeric"}, 'my-custom-format']);
366
633
  i18next.changeLanguage('en');
367
- const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-custom-format'} });
634
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-custom-format'}});
368
635
  assert.equal('95', res);
369
636
  });
370
637
 
371
638
  it('function _date when called after configure() with defined custom format (year:2-digit) should override ' +
372
- 'standard configuration when language is "en"', function() {
639
+ 'standard configuration when language is "en"', function () {
373
640
  HandlebarsI18n.configure([
374
- ['en', 'DateTimeFormat', { year:"numeric" }],
375
- ['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format']
641
+ ['en', 'DateTimeFormat', {year: "numeric"}],
642
+ ['en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format']
376
643
  ]);
377
644
  i18next.changeLanguage('en');
378
- const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-custom-format'} });
645
+ const res = hI18n.helpers._date('[1995,11,17]', {hash: {format: 'my-custom-format'}});
379
646
  assert.equal('95', res);
380
647
  });
381
648
 
382
649
  it('function _date when called after configure() with defined custom format (year:2-digit) should override ' +
383
- 'standard configuration also when beeing defined first', function() {
650
+ 'standard configuration also when being defined first', function () {
384
651
  HandlebarsI18n.configure([
385
- ['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format'],
386
- ['en', 'DateTimeFormat', { year:"numeric" }]
652
+ ['en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format'],
653
+ ['en', 'DateTimeFormat', {year: "numeric"}]
387
654
  ]);
388
655
  i18next.changeLanguage('en');
389
- const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-custom-format'} });
656
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-custom-format'}});
390
657
  assert.equal('95', res);
391
658
  });
392
659
 
393
660
  it('function _date when called after configure() should fall back to generic language format "en" when custom format is unknown' +
394
- 'standard configuration also when beeing defined first', function() {
661
+ 'standard configuration also when being defined first', function () {
395
662
  HandlebarsI18n.configure([
396
- ['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format'],
397
- ['en', 'DateTimeFormat', { year:"numeric" }]
663
+ ['en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format'],
664
+ ['en', 'DateTimeFormat', {year: "numeric"}]
398
665
  ]);
399
666
  i18next.changeLanguage('en');
400
- const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-unknown-format'} });
667
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-unknown-format'}});
401
668
  assert.equal('1995', res);
402
669
  });
403
670
 
404
671
  it('function _date when called after configure() should fall back to generic language format "all" when custom format is unknown' +
405
- 'standard configuration also when beeing defined first', function() {
672
+ 'standard configuration also when being defined first', function () {
406
673
  HandlebarsI18n.configure([
407
- ['all', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format'],
408
- ['en', 'DateTimeFormat', { year:"numeric" }]
674
+ ['all', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format'],
675
+ ['en', 'DateTimeFormat', {year: "numeric"}]
409
676
  ]);
410
677
  i18next.changeLanguage('en');
411
- const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-unknown-format'} });
678
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-unknown-format'}});
412
679
  assert.equal('1995', res);
413
680
  });
414
681
 
415
682
  it('function _date when called after configure() should fall back to Intl default format when custom format is unknown' +
416
- 'standard configuration also when beeing defined first', function() {
683
+ 'standard configuration also when being defined first', function () {
417
684
  HandlebarsI18n.reset();
418
685
  HandlebarsI18n.configure([
419
- ['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format']
686
+ ['en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format']
420
687
  ]);
421
688
  i18next.changeLanguage('en');
422
- const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-unknown-format'} });
689
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-unknown-format'}});
423
690
  assert.equal('12/17/1995', res);
424
691
  });
425
-
426
692
 
427
- // -- Tests for custom format configurations for function _num -- //
693
+
694
+ /********************************************************************
695
+ Tests for custom format configurations for _dateRel / _dateDiff
696
+ ********************************************************************/
697
+
698
+ it('function _dateRel called after configure() with defined "all" (style: "long", unit: "second") should return ' +
699
+ '"in 12 seconds" when language is "en"', function () {
700
+ HandlebarsI18n.configure('all', 'RelativeTimeFormat', {style: "long", unit: "second"});
701
+ i18next.changeLanguage('en');
702
+ const res = hI18n.helpers._dateRel('12');
703
+ assert.equal('in 12 seconds', res);
704
+ });
705
+
706
+ it('function _dateRel called after configure() with defined custom format (style: "long", unit: "year") should return ' +
707
+ '"in 12 Jahren" when language is "de"', function () {
708
+ HandlebarsI18n.configure('de', 'RelativeTimeFormat', {style: "long", unit: "year"}, 'date-rel-custom');
709
+ i18next.changeLanguage('de');
710
+ const res = hI18n.helpers._dateRel('12', {hash: {format: 'date-rel-custom'}});
711
+ assert.equal('in 12 Jahren', res);
712
+ });
713
+
714
+ it('function _dateRel called after configure() with defined custom format { style: "short", unit: "minutes" } should override ' +
715
+ 'standard configuration when language is "en"', function () {
716
+ HandlebarsI18n.configure([
717
+ ['en', 'RelativeTimeFormat', {style: "short", unit: "day"}, 'date-rel-spec'],
718
+ ['en', 'RelativeTimeFormat', {style: "long", unit: "second"}]
719
+ ]);
720
+ i18next.changeLanguage('en');
721
+ const res = hI18n.helpers._dateRel('12', {hash: {format: 'date-rel-spec'}});
722
+ assert.equal('in 12 days', res);
723
+ });
724
+
725
+ it('function _dateRel called after configure() with defined custom format { style: "short", unit: "minutes" } should override ' +
726
+ 'standard configuration when language is "en" and output: \'in 12 days\'', function () {
727
+ HandlebarsI18n.configure([
728
+ ['en', 'RelativeTimeFormat', {style: "short", unit: "day"}, 'date-rel-spec'],
729
+ ['en', 'RelativeTimeFormat', {style: "long", unit: "second"}]
730
+ ]);
731
+ i18next.changeLanguage('en');
732
+ const res = hI18n.helpers._dateRel('12', {hash: {format: 'date-rel-spec'}});
733
+ assert.equal('in 12 days', res);
734
+ });
735
+
736
+ it('function _dateDiff called after configure() with defined custom format { style: "short", unit: "minutes" } should override ' +
737
+ 'standard configuration when language is "en" and output: \'in in 1 yr.\'', function () {
738
+ HandlebarsI18n.configure([
739
+ ['en', 'RelativeTimeFormat', {style: "short", unit: "year"}, 'date-rel-spec'],
740
+ ['en', 'RelativeTimeFormat', {style: "long", unit: "day"}]
741
+ ]);
742
+ i18next.changeLanguage('en');
743
+ const res = hI18n.helpers._dateDiff('1996-12-17T00:00:00', '1995-12-17T00:00:00', {hash: {format: 'date-rel-spec'}});
744
+ assert.equal('in 1 yr.', res);
745
+ });
746
+
747
+
748
+ /********************************************************************
749
+ Tests for custom format configurations for function _num
750
+ ********************************************************************/
428
751
 
429
752
  it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) should return ' +
430
- 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
431
- HandlebarsI18n.configure('en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format');
753
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
754
+ HandlebarsI18n.configure('en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format');
432
755
  i18next.changeLanguage('en');
433
- const res = hI18n.helpers._num(4000000, { hash: { format: 'my-custom-format'} });
756
+ const res = hI18n.helpers._num(4000000, {hash: {format: 'my-custom-format'}});
434
757
  assert.equal('4,000,000.0000', res);
435
758
  });
436
759
 
437
760
  it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) given as ARRAY should return ' +
438
- 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
439
- HandlebarsI18n.configure(['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format']);
761
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
762
+ HandlebarsI18n.configure(['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format']);
440
763
  i18next.changeLanguage('en');
441
- const res = hI18n.helpers._num(4000000, { hash: { format: 'my-custom-format'} });
764
+ const res = hI18n.helpers._num(4000000, {hash: {format: 'my-custom-format'}});
442
765
  assert.equal('4,000,000.0000', res);
443
766
  });
444
767
 
445
768
  it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) should override' +
446
- 'standard configuration when language is "en"', function() {
769
+ 'standard configuration when language is "en"', function () {
447
770
  HandlebarsI18n.configure([
448
- ['en', 'NumberFormat', { maximumFractionDigits:1 }],
449
- ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format']
771
+ ['en', 'NumberFormat', {maximumFractionDigits: 1}],
772
+ ['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format']
450
773
  ]);
451
774
  i18next.changeLanguage('en');
452
- const res = hI18n.helpers._num(4000000, { hash: { format: 'my-custom-format'} });
775
+ const res = hI18n.helpers._num(4000000, {hash: {format: 'my-custom-format'}});
453
776
  assert.equal('4,000,000.0000', res);
454
777
  });
455
778
 
456
779
  it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) should override' +
457
- 'standard configuration also when being defined first', function() {
780
+ 'standard configuration also when being defined first', function () {
458
781
  HandlebarsI18n.configure([
459
- ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format'],
460
- ['en', 'NumberFormat', { maximumFractionDigits:1 }]
782
+ ['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format'],
783
+ ['en', 'NumberFormat', {maximumFractionDigits: 1}]
461
784
  ]);
462
785
  i18next.changeLanguage('en');
463
- const res = hI18n.helpers._num(4000000, { hash: { format: 'my-custom-format'} });
786
+ const res = hI18n.helpers._num(4000000, {hash: {format: 'my-custom-format'}});
464
787
  assert.equal('4,000,000.0000', res);
465
788
  });
466
789
 
467
- it('function _num when called after configure() should fall back to standard language format "en" when custom format is unknown', function() {
790
+ it('function _num when called after configure() should fall back to standard language format "en" when custom format is unknown', function () {
468
791
  HandlebarsI18n.configure([
469
- ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format'],
470
- ['en', 'NumberFormat', { minimumFractionDigits:1 }]
792
+ ['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format'],
793
+ ['en', 'NumberFormat', {minimumFractionDigits: 1}]
471
794
  ]);
472
795
  i18next.changeLanguage('en');
473
- const res = hI18n.helpers._num(4000000, { hash: { format: 'my-unknown-format'} });
796
+ const res = hI18n.helpers._num(4000000, {hash: {format: 'my-unknown-format'}});
474
797
  assert.equal('4,000,000.0', res);
475
798
  });
476
799
 
477
- it('function _num when called after configure() should fall back to standard language format "all" when custom format is unknown', function() {
800
+ it('function _num when called after configure() should fall back to standard language format "all" when custom format is unknown', function () {
478
801
  HandlebarsI18n.configure([
479
- ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format'],
480
- ['all', 'NumberFormat', { minimumFractionDigits:1 }]
802
+ ['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format'],
803
+ ['all', 'NumberFormat', {minimumFractionDigits: 1}]
481
804
  ]);
482
805
  i18next.changeLanguage('en');
483
- const res = hI18n.helpers._num(4000000, { hash: { format: 'my-unknown-format'} });
806
+ const res = hI18n.helpers._num(4000000, {hash: {format: 'my-unknown-format'}});
484
807
  assert.equal('4,000,000.0', res);
485
808
  });
486
809
 
487
- it('function _num when called after configure() should fall back to Intl default when custom format is unknown', function() {
810
+ it('function _num when called after configure() should fall back to Intl default when custom format is unknown', function () {
488
811
  HandlebarsI18n.reset();
489
812
  HandlebarsI18n.configure([
490
- ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format']
813
+ ['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format']
491
814
  ]);
492
815
  i18next.changeLanguage('en');
493
- const res = hI18n.helpers._num(4000000, { hash: { format: 'my-unknown-format'} });
816
+ const res = hI18n.helpers._num(4000000, {hash: {format: 'my-unknown-format'}});
494
817
  assert.equal('4,000,000', res);
495
818
  });
496
819
 
497
820
 
498
- // -- Tests for custom format configurations for function _price -- //
821
+ /********************************************************************
822
+ Tests for custom format configurations for function _price
823
+ ********************************************************************/
499
824
 
500
825
  it('function _price when called after configure() with defined custom format (minimumFractionDigits:4) should return ' +
501
- 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
502
- HandlebarsI18n.configure('en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format');
826
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
827
+ HandlebarsI18n.configure('en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format');
503
828
  i18next.changeLanguage('en');
504
- const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
829
+ const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
505
830
  assert.equal('€2.000', res);
506
831
  });
507
832
 
508
833
  it('function _price when called after configure() with defined custom format (minimumFractionDigits:4) should return ' +
509
- 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
510
- HandlebarsI18n.configure('en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format');
834
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
835
+ HandlebarsI18n.configure('en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format');
511
836
  i18next.changeLanguage('en');
512
- const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
837
+ const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
513
838
  assert.equal('€2.000', res);
514
839
  });
515
840
 
516
841
  it('function _price when called after configure() with defined custom format (minimumFractionDigits:4) given as ARRAY should return ' +
517
- 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
518
- HandlebarsI18n.configure(['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format']);
842
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
843
+ HandlebarsI18n.configure(['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format']);
519
844
  i18next.changeLanguage('en');
520
- const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
845
+ const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
521
846
  assert.equal('€2.000', res);
522
847
  });
523
848
 
524
849
  it('function _price when called after configure() with defined custom format (minimumFractionDigits:3) should override' +
525
- 'standard configuration when language is "en"', function() {
850
+ 'standard configuration when language is "en"', function () {
526
851
  HandlebarsI18n.configure([
527
- ['en', 'PriceFormat', { currency:'USD'}],
528
- ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format']
852
+ ['en', 'PriceFormat', {currency: 'USD'}],
853
+ ['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format']
529
854
  ]);
530
855
  i18next.changeLanguage('en');
531
- const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
856
+ const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
532
857
  assert.equal('€2.000', res);
533
858
  });
534
859
 
535
860
  it('function _price when called after configure() with defined custom format (minimumFractionDigits:3) should override' +
536
- 'standard configuration also when being defined first', function() {
861
+ 'standard configuration also when being defined first', function () {
537
862
  HandlebarsI18n.configure([
538
- ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format'],
539
- ['en', 'PriceFormat', { currency:'USD'}]
863
+ ['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format'],
864
+ ['en', 'PriceFormat', {currency: 'USD'}]
540
865
  ]);
541
866
  i18next.changeLanguage('en');
542
- const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
867
+ const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
543
868
  assert.equal('€2.000', res);
544
869
  });
545
870
 
546
- it('function _price when called after configure() should fall back to standard language format "en" when custom format is unknown', function() {
871
+ it('function _price when called after configure() should fall back to standard language format "en" when custom format is unknown', function () {
547
872
  HandlebarsI18n.configure([
548
- ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format'],
549
- ['en', 'PriceFormat', { currency:'USD'}]
873
+ ['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format'],
874
+ ['en', 'PriceFormat', {currency: 'USD'}]
550
875
  ]);
551
876
  i18next.changeLanguage('en');
552
- const res = hI18n.helpers._price(2, { hash: { format: 'my-unknown-format'} });
877
+ const res = hI18n.helpers._price(2, {hash: {format: 'my-unknown-format'}});
553
878
  assert.equal('$2.00', res);
554
879
  });
555
880
 
556
- it('function _price when called after configure() should fall back to standard language format "all" when custom format is unknown', function() {
881
+ it('function _price when called after configure() should fall back to standard language format "all" when custom format is unknown', function () {
557
882
  HandlebarsI18n.configure([
558
- ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format'],
559
- ['all', 'PriceFormat', { currency:'USD'}]
883
+ ['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format'],
884
+ ['all', 'PriceFormat', {currency: 'USD'}]
560
885
  ]);
561
886
  i18next.changeLanguage('en');
562
- const res = hI18n.helpers._price(2, { hash: { format: 'my-unknown-format'} });
887
+ const res = hI18n.helpers._price(2, {hash: {format: 'my-unknown-format'}});
563
888
  assert.equal('$2.00', res);
564
889
  });
565
890
 
566
- it('function _price when called after configure() should fall back to Intl default when custom format is unknown', function() {
891
+ it('function _price when called after configure() should fall back to Intl default when custom format is unknown', function () {
567
892
  HandlebarsI18n.configure([
568
- ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format']
893
+ ['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format']
569
894
  ]);
570
895
  i18next.changeLanguage('en');
571
- const res = hI18n.helpers._price(2, { hash: { format: 'my-unknown-format'} });
896
+ const res = hI18n.helpers._price(2, {hash: {format: 'my-unknown-format'}});
572
897
  assert.equal('$2.00', res);
573
898
  });
574
899
 
900
+ });
901
+
902
+ describe('handlebars-i18n Private helper Function Tests (in production not exported)', () => {
903
+
904
+ /********************************************************************
905
+ Tests for private function applyToConstructor
906
+ ********************************************************************/
907
+
908
+ // Mock constructor function
909
+ function TestConstructor(a, b) {
910
+ this.a = a;
911
+ this.b = b;
912
+ }
913
+
914
+ it('should return an instance of the constructor with provided arguments', () => {
915
+ const args = [1, 2];
916
+ const instance = HandlebarsI18n.private.applyToConstructor(TestConstructor, args);
917
+ expect(instance).to.be.an.instanceof(TestConstructor);
918
+ expect(instance.a).to.equal(1);
919
+ expect(instance.b).to.equal(2);
920
+ });
921
+
922
+ /* it('should handle no arguments', () => {
923
+ const instance = HandlebarsI18n.private.applyToConstructor(TestConstructor, []);
924
+ expect(instance).to.be.an.instanceof(TestConstructor);
925
+ expect(instance.a).to.equal(null);
926
+ expect(instance.b).to.equal(undefined); // because 'undefined' is passed as second argument
927
+ });*/
928
+
929
+ it('should handle constructor with no arguments', () => {
930
+ function ConstructorWithNoArgs() {
931
+ this.value = 10;
932
+ }
933
+
934
+ const instance = HandlebarsI18n.private.applyToConstructor(ConstructorWithNoArgs, []);
935
+ expect(instance).to.be.an.instanceof(ConstructorWithNoArgs);
936
+ expect(instance.value).to.equal(10);
937
+ });
938
+
939
+ it('should handle constructor with complex arguments', () => {
940
+ class ComplexArgument {
941
+ constructor(value) {
942
+ this.value = value;
943
+ }
944
+ }
945
+
946
+ const args = [new ComplexArgument(5)];
947
+
948
+ function ConstructorWithComplexArg(arg) {
949
+ this.arg = arg;
950
+ }
951
+
952
+ const instance = HandlebarsI18n.private.applyToConstructor(ConstructorWithComplexArg, args);
953
+ expect(instance).to.be.an.instanceof(ConstructorWithComplexArg);
954
+ expect(instance.arg).to.be.an.instanceof(ComplexArgument);
955
+ expect(instance.arg.value).to.equal(5);
956
+ });
957
+
958
+
959
+ /********************************************************************
960
+ Tests for private function applyToConstructor
961
+ ********************************************************************/
962
+
963
+ const hndlbrsOpts = {
964
+ hash: {
965
+ format: 'customFormat',
966
+ // Add other properties if needed for specific test cases
967
+ }
968
+ };
969
+ const lang = 'en';
970
+ const OCFormat = {
971
+ standard: {
972
+ en: { /* Standard configuration for English */},
973
+ all: { /* Universal configuration for all languages */}
974
+ },
975
+ custom: {
976
+ customFormat: {
977
+ en: { /* Custom configuration for English */}
978
+ }
979
+ }
980
+ };
981
+
982
+ /*it('should return template configuration when options object with content is provided', () => {
983
+ const result = HandlebarsI18n.private.configLookup(hndlbrsOpts, lang, OCFormat);
984
+ expect(result).to.deep.equal(hndlbrsOpts.hash);
985
+ });*/
986
+
987
+ it('should return custom configuration when custom format and language are provided', () => {
988
+ const result = HandlebarsI18n.private.configLookup(hndlbrsOpts, lang, OCFormat);
989
+ expect(result).to.deep.equal(OCFormat.custom.customFormat[lang]);
990
+ });
991
+
992
+ it('should return standard language configuration when no custom format is provided', () => {
993
+ const hndlbrsOptsWithoutFormat = {
994
+ hash: {
995
+ // Add other properties if needed for specific test cases
996
+ }
997
+ };
998
+ const result = HandlebarsI18n.private.configLookup(hndlbrsOptsWithoutFormat, lang, OCFormat);
999
+ expect(result).to.deep.equal(OCFormat.standard[lang]);
1000
+ });
1001
+
1002
+ it('should return universal configuration when no language-specific configuration is provided', () => {
1003
+ const langWithoutConfig = 'fr'; // Assuming French configuration is not provided
1004
+ const result = HandlebarsI18n.private.configLookup(hndlbrsOpts, langWithoutConfig, OCFormat);
1005
+ expect(result).to.deep.equal(OCFormat.standard.all);
1006
+ });
1007
+
1008
+ it('should return an empty object when no configuration is provided at all', () => {
1009
+ const result = HandlebarsI18n.private.configLookup({}, lang, OCFormat);
1010
+ expect(result).to.deep.equal({});
1011
+ });
1012
+
575
1013
  });