source: Dev/branches/rest-dojo-ui/client/dojo/tests/currency.js @ 263

Last change on this file since 263 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 3.1 KB
Line 
1define(["../main", "doh", "require", "../currency"], function(dojo, doh, require){
2
3        var runTest= function(dojo, t) {
4                t.is("\u20ac123.45", dojo.currency.format(123.45, {currency: "EUR", locale: "en-us"}));
5                t.is("$123.45", dojo.currency.format(123.45, {currency: "USD", locale: "en-us"}));
6                t.is("$1,234.56", dojo.currency.format(1234.56, {currency: "USD", locale: "en-us"}));
7                t.is("US$123.45", dojo.currency.format(123.45, {currency: "USD", locale: "en-ca"}));
8                t.is("$123.45", dojo.currency.format(123.45, {currency: "CAD", locale: "en-ca"}));
9                t.is("CA$123.45", dojo.currency.format(123.45, {currency: "CAD", locale: "en-us"}));
10                t.is("123,45\xa0\u20ac", dojo.currency.format(123.45, {currency: "EUR", locale: "de-de"}));
11                t.is("1.234,56\xa0\u20ac", dojo.currency.format(1234.56, {currency: "EUR", locale: "de-de"}));
12                // There is no special currency symbol for ADP, so expect the ISO code instead
13                t.is("ADP123", dojo.currency.format(123, {currency: "ADP", locale: "en-us"}));
14                t.is("$1,234", dojo.currency.format(1234, {currency: "USD", fractional: false, locale: "en-us"}));
15
16                t.is(123.45, dojo.currency.parse("$123.45", {currency: "USD", locale: "en-us"}));
17                t.is(1234.56, dojo.currency.parse("$1,234.56", {currency: "USD", locale: "en-us"}));
18                t.is(123.45, dojo.currency.parse("123,45 \u20ac", {currency: "EUR", locale: "de-de"}));
19                t.is(123.45, dojo.currency.parse("123,45\xa0\u20ac", {currency: "EUR", locale: "de-de"}));
20                t.is(1234.56, dojo.currency.parse("1.234,56 \u20ac", {currency: "EUR", locale: "de-de"}));
21                t.is(1234.56, dojo.currency.parse("1.234,56\u20ac", {currency: "EUR", locale: "de-de"}));
22
23                t.is(1234, dojo.currency.parse("$1,234", {currency: "USD", locale: "en-us"}));
24                t.is(1234, dojo.currency.parse("$1,234", {currency: "USD", fractional: false, locale: "en-us"}));
25                t.t(isNaN(dojo.currency.parse("$1,234", {currency: "USD", fractional: true, locale: "en-us"})));
26        };
27
28        if(require.async){
29                require(["../main", "../currency", "../i18n"], function(dojo){
30                        doh.register("tests.currency", {
31                                name: "currency",
32                                timeout: 2000,
33                                runTest: function(t){
34                                        var
35                                                def = new doh.Deferred(),
36                                                deps= ["dojo"];
37                                        dojo.forEach(["en-us", "en-ca", "de-de"], function(locale){
38                                                deps.push(dojo.getL10nName("dojo/cldr", "currency", locale));
39                                                deps.push(dojo.getL10nName("dojo/cldr", "number", locale));
40                                        });
41                                        require(deps, function(dojo){
42                                                runTest(dojo, t);
43                                                def.callback(true);
44                                        });
45                                        return def;
46                                }
47                        });
48                });
49        }else{ // tests for the v1.x loader/i18n machinery
50                tests.register("tests.currency",{
51                        // Test formatting and parsing of currencies in various locales pre-built in dojo.cldr
52                        // NOTE: we can't set djConfig.extraLocale before bootstrapping unit tests, so directly
53                        // load resources here for specific locales:
54                        name: "currency",
55                        setUp: function(){
56                                var partLocaleList = ["en-us", "en-ca", "de-de"];
57                                for(var i = 0 ; i < partLocaleList.length; i ++){
58                                        dojo.requireLocalization("dojo.cldr","currency",partLocaleList[i]);
59                                        dojo.requireLocalization("dojo.cldr","number",partLocaleList[i]);
60                                }
61                        },
62                        runTest: function(t){
63                                runTest(dojo, t);
64                        }
65                });
66        }
67});
Note: See TracBrowser for help on using the repository browser.