kivi.js: format/round/parse_amount, format/parse_date
[kivitendo-erp.git] / js / t / kivi / setup_formats.js
1 QUnit.test("kivi.setup_formats date format initialization", function( assert ) {
2   kivi.setup_formats({ dates: "dd.mm.yy" });
3   assert.deepEqual(kivi._date_format, { sep: '.', d: 0, m: 1, y: 2 } , "German date style with dots");
4
5   kivi.setup_formats({ dates: "dd/mm/yy" });
6   assert.deepEqual(kivi._date_format, { sep: '/', d: 0, m: 1, y: 2 } , "German date style with slashes");
7
8   kivi.setup_formats({ dates: "mm/dd/yy" });
9   assert.deepEqual(kivi._date_format, { sep: '/', d: 1, m: 0, y: 2 } , "American date style");
10
11   kivi.setup_formats({ dates: "yyyy-mm-dd" });
12   assert.deepEqual(kivi._date_format, { sep: '-', d: 2, m: 1, y: 0 } , "ISO date style");
13
14   kivi.setup_formats({ dates: "dd.mm.yy" });
15   kivi.setup_formats({ dates: "Totally invalid!" });
16   assert.deepEqual(kivi._date_format, { sep: '.', d: 0, m: 1, y: 2 } , "Invalid date style should not change previously-set style");
17 });
18
19 QUnit.test("kivi.setup_formats number format initialization", function( assert ) {
20   kivi.setup_formats({ numbers: "1.000,00" });
21   assert.deepEqual(kivi._number_format, { decimalSep: ',', thousandSep: '.' } , "German number style with thousands separator");
22
23   kivi.setup_formats({ numbers: "1000,00" });
24   assert.deepEqual(kivi._number_format, { decimalSep: ',', thousandSep: '' } , "German number style without thousands separator");
25
26   kivi.setup_formats({ numbers: "1,000.00" });
27   assert.deepEqual(kivi._number_format, { decimalSep: '.', thousandSep: ',' } , "English number style with thousands separator");
28
29   kivi.setup_formats({ numbers: "1000.00" });
30   assert.deepEqual(kivi._number_format, { decimalSep: '.', thousandSep: '' } , "English number style without thousands separator");
31
32   kivi.setup_formats({ numbers: "1.000,00" });
33   kivi.setup_formats({ numbers: "Totally invalid!" });
34   assert.deepEqual(kivi._number_format, { decimalSep: ',', thousandSep: '.' } , "Invalid number style should not change previously-set style");
35 });