Updated Branches: refs/heads/master 8f42017c9 -> 45a192ac0
CB-1474: Port Globalization Plug-in Tests to Jasmine Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/commit/45a192ac Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/tree/45a192ac Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/diff/45a192ac Branch: refs/heads/master Commit: 45a192ac030faf93a133d25a4e343cd660f36fef Parents: 8f42017 Author: Simon MacDonald <simon.macdon...@gmail.com> Authored: Wed Sep 19 10:56:27 2012 -0400 Committer: Simon MacDonald <simon.macdon...@gmail.com> Committed: Wed Sep 19 10:56:27 2012 -0400 ---------------------------------------------------------------------- autotest/index.html | 1 + autotest/pages/all.html | 1 + autotest/pages/globalization.html | 69 +++ autotest/tests/globalization.tests.js | 785 ++++++++++++++++++++++++++++ 4 files changed, 856 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/45a192ac/autotest/index.html ---------------------------------------------------------------------- diff --git a/autotest/index.html b/autotest/index.html index 2260b4f..4d3f1dc 100644 --- a/autotest/index.html +++ b/autotest/index.html @@ -45,6 +45,7 @@ <a href="pages/file.html" class="btn large" style="width:100%;">Run File Tests</a> <a href="pages/filetransfer.html" class="btn large" style="width:100%;">Run FileTransfer Tests</a> <a href="pages/geolocation.html" class="btn large" style="width:100%;">Run Geolocation Tests</a> + <a href="pages/globalization.html" class="btn large" style="width:100%;">Run Globalization Tests</a> <a href="pages/media.html" class="btn large" style="width:100%;">Run Media Tests</a> <a href="pages/network.html" class="btn large" style="width:100%;">Run Network Tests</a> <a href="pages/notification.html" class="btn large" style="width:100%;">Run Notification Tests</a> http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/45a192ac/autotest/pages/all.html ---------------------------------------------------------------------- diff --git a/autotest/pages/all.html b/autotest/pages/all.html index d9aa98f..53260c2 100644 --- a/autotest/pages/all.html +++ b/autotest/pages/all.html @@ -54,6 +54,7 @@ <script type="text/javascript" src="../tests/file.tests.js"></script> <script type="text/javascript" src="../tests/filetransfer.tests.js"></script> <script type="text/javascript" src="../tests/geolocation.tests.js"></script> + <script type="text/javascript" src="../tests/globalization.tests.js"></script> <script type="text/javascript" src="../tests/media.tests.js"></script> <script type="text/javascript" src="../tests/network.tests.js"></script> <script type="text/javascript" src="../tests/notification.tests.js"></script> http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/45a192ac/autotest/pages/globalization.html ---------------------------------------------------------------------- diff --git a/autotest/pages/globalization.html b/autotest/pages/globalization.html new file mode 100644 index 0000000..c64de63 --- /dev/null +++ b/autotest/pages/globalization.html @@ -0,0 +1,69 @@ +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +--> + +<!DOCTYPE html> +<html> +<head> + <title>Cordova: Globalization API Specs</title> + + <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" /> + + <!-- Load jasmine --> + <link href="../jasmine.css" rel="stylesheet"/> + <script type="text/javascript" src="../jasmine.js"></script> + <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script> + <script type="text/javascript" src="../html/HtmlReporter.js"></script> + <script type="text/javascript" src="../html/ReporterView.js"></script> + <script type="text/javascript" src="../html/SpecView.js"></script> + <script type="text/javascript" src="../html/SuiteView.js"></script> + <script type="text/javascript" src="../html/TrivialReporter.js"></script> + + <!-- Source --> + <script type="text/javascript" src="../../cordova.js"></script> + + <!-- Load Test Runner --> + <script type="text/javascript" src="../test-runner.js"></script> + + <!-- Tests --> + <script type="text/javascript" src="../tests/globalization.tests.js"></script> + + <script type="text/javascript"> + document.addEventListener('deviceready', function () { + var jasmineEnv = jasmine.getEnv(); + jasmineEnv.updateInterval = 1000; + + var htmlReporter = new jasmine.HtmlReporter(); + + jasmineEnv.addReporter(htmlReporter); + + jasmineEnv.specFilter = function(spec) { + return htmlReporter.specFilter(spec); + }; + + jasmineEnv.execute(); + }, false); + </script> +</head> + +<body> + <a href="javascript:" class="backBtn" onclick="backHome();">Back</a> +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/45a192ac/autotest/tests/globalization.tests.js ---------------------------------------------------------------------- diff --git a/autotest/tests/globalization.tests.js b/autotest/tests/globalization.tests.js new file mode 100644 index 0000000..76cbe9b --- /dev/null +++ b/autotest/tests/globalization.tests.js @@ -0,0 +1,785 @@ +describe('Globalization (navigator.globalization)', function () { + it("should exist", function() { + expect(navigator.globalization).toBeDefined(); + }); + + describe("getLocaleName", function() { + it("should exist", function() { + expect(typeof navigator.globalization.getLocaleName).toBeDefined(); + expect(typeof navigator.globalization.getLocaleName == 'function').toBe(true); + }); + it("getLocaleName success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getLocaleName(win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("dateToString", function() { + it("should exist", function() { + expect(typeof navigator.globalization.dateToString).toBeDefined(); + expect(typeof navigator.globalization.dateToString == 'function').toBe(true); + }); + it("dateToString using default options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.dateToString(new Date(), win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("dateToString using formatLength=short and selector=date options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.dateToString(new Date(), win, fail, {formatLength: 'short', selector: 'date'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("dateToString using formatLength=full and selector=date options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.dateToString(new Date(), win, fail, {formatLength: 'full', selector: 'date'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("dateToString using formatLength=medium and selector=date and time(default) options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.dateToString(new Date(), win, fail, {formatLength: 'medium'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("dateToString using formatLength=long and selector=date and time(default) options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.dateToString(new Date(), win, fail, {formatLength: 'long'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("dateToString using formatLength=full and selector=date and time(default) options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.dateToString(new Date(), win, fail, {formatLength: 'full'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("stringToDate", function() { + it("should exist", function() { + expect(typeof navigator.globalization.stringToDate).toBeDefined(); + expect(typeof navigator.globalization.stringToDate == 'function').toBe(true); + }); + it("stringToDate using default options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.year).toBeDefined(); + expect(typeof a.year).toBe('number'); + expect(a.year >= 0 && a.year <=9999).toBe(true); + expect(a.month).toBeDefined(); + expect(typeof a.month).toBe('number'); + expect(a.month >= 0 && a.month <=11).toBe(true); + expect(a.day).toBeDefined(); + expect(typeof a.day).toBe('number'); + expect(a.day >= 1 && a.day <=31).toBe(true); + expect(a.hour).toBeDefined(); + expect(typeof a.hour).toBe('number'); + expect(a.hour >= 0 && a.hour <=23).toBe(true); + expect(a.minute).toBeDefined(); + expect(typeof a.minute).toBe('number'); + expect(a.minute >= 0 && a.minute <=59).toBe(true); + expect(a.second).toBeDefined(); + expect(typeof a.second).toBe('number'); + expect(a.second >= 0 && a.second <=59).toBe(true); + expect(a.millisecond).toBeDefined(); + expect(typeof a.millisecond).toBe('number'); + }), + fail = jasmine.createSpy(); + + var win2 = function(a) { + navigator.globalization.stringToDate(a.value, win, fail); + }; + + runs(function () { + navigator.globalization.dateToString(new Date(), win2, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("stringToDate using formatLength=short and selector=date options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.year).toBeDefined(); + expect(typeof a.year).toBe('number'); + expect(a.year >= 0 && a.year <=9999).toBe(true); + expect(a.month).toBeDefined(); + expect(typeof a.month).toBe('number'); + expect(a.month >= 0 && a.month <=11).toBe(true); + expect(a.day).toBeDefined(); + expect(typeof a.day).toBe('number'); + expect(a.day >= 1 && a.day <=31).toBe(true); + expect(a.hour).toBeDefined(); + expect(typeof a.hour).toBe('number'); + expect(a.hour >= 0 && a.hour <=23).toBe(true); + expect(a.minute).toBeDefined(); + expect(typeof a.minute).toBe('number'); + expect(a.minute >= 0 && a.minute <=59).toBe(true); + expect(a.second).toBeDefined(); + expect(typeof a.second).toBe('number'); + expect(a.second >= 0 && a.second <=59).toBe(true); + expect(a.millisecond).toBeDefined(); + expect(typeof a.millisecond).toBe('number'); + }), + fail = jasmine.createSpy(); + + var win2 = function(a) { + navigator.globalization.stringToDate(a.value, win, fail, {formatLength: 'short', selector: 'date'}); + }; + + runs(function () { + navigator.globalization.dateToString(new Date(), win2, fail, {formatLength: 'short', selector: 'date'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("stringToDate using formatLength=full and selector=date options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.year).toBeDefined(); + expect(typeof a.year).toBe('number'); + expect(a.year >= 0 && a.year <=9999).toBe(true); + expect(a.month).toBeDefined(); + expect(typeof a.month).toBe('number'); + expect(a.month >= 0 && a.month <=11).toBe(true); + expect(a.day).toBeDefined(); + expect(typeof a.day).toBe('number'); + expect(a.day >= 1 && a.day <=31).toBe(true); + expect(a.hour).toBeDefined(); + expect(typeof a.hour).toBe('number'); + expect(a.hour >= 0 && a.hour <=23).toBe(true); + expect(a.minute).toBeDefined(); + expect(typeof a.minute).toBe('number'); + expect(a.minute >= 0 && a.minute <=59).toBe(true); + expect(a.second).toBeDefined(); + expect(typeof a.second).toBe('number'); + expect(a.second >= 0 && a.second <=59).toBe(true); + expect(a.millisecond).toBeDefined(); + expect(typeof a.millisecond).toBe('number'); + }), + fail = jasmine.createSpy(); + + var win2 = function(a) { + navigator.globalization.stringToDate(a.value, win, fail, {formatLength: 'full', selector: 'date'}); + }; + runs(function () { + navigator.globalization.dateToString(new Date(), win2, fail, {formatLength: 'full', selector: 'date'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("getDatePattern", function() { + it("should exist", function() { + expect(typeof navigator.globalization.getDatePattern).toBeDefined(); + expect(typeof navigator.globalization.getDatePattern == 'function').toBe(true); + }); + it("getDatePattern using default options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.pattern).toBeDefined(); + expect(typeof a.pattern).toBe('string'); + expect(a.pattern.length > 0).toBe(true); + expect(a.timezone).toBeDefined(); + expect(typeof a.timezone).toBe('string'); + expect(a.timezone.length > 0).toBe(true); + expect(a.utc_offset).toBeDefined(); + expect(typeof a.utc_offset).toBe('number'); + expect(a.dst_offset).toBeDefined(); + expect(typeof a.dst_offset).toBe('number'); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getDatePattern(win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("getDatePattern using formatLength=medium and selector=date options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.pattern).toBeDefined(); + expect(typeof a.pattern).toBe('string'); + expect(a.pattern.length > 0).toBe(true); + expect(a.timezone).toBeDefined(); + expect(typeof a.timezone).toBe('string'); + expect(a.timezone.length > 0).toBe(true); + expect(a.utc_offset).toBeDefined(); + expect(typeof a.utc_offset).toBe('number'); + expect(a.dst_offset).toBeDefined(); + expect(typeof a.dst_offset).toBe('number'); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getDatePattern(win, fail, {formatLength: 'medium', selector: 'date'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("getDateNames", function() { + it("should exist", function() { + expect(typeof navigator.globalization.getDateNames).toBeDefined(); + expect(typeof navigator.globalization.getDateNames == 'function').toBe(true); + }); + it("getDateNames using default options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(a.value instanceof Array).toBe(true); + expect(a.value.length > 0).toBe(true); + expect(typeof a.value[0]).toBe('string'); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getDateNames(win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("getDateNames using type=narrow and item=days options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(a.value instanceof Array).toBe(true); + expect(a.value.length > 0).toBe(true); + expect(typeof a.value[0]).toBe('string'); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getDateNames(win, fail, {type: 'narrow', item: 'days'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("getDateNames using type=narrow and item=months options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(a.value instanceof Array).toBe(true); + expect(a.value.length > 0).toBe(true); + expect(typeof a.value[0]).toBe('string'); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getDateNames(win, fail, {type: 'narrow', item: 'months'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("getDateNames using type=wide and item=days options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(a.value instanceof Array).toBe(true); + expect(a.value.length > 0).toBe(true); + expect(typeof a.value[0]).toBe('string'); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getDateNames(win, fail, {item: 'days'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("getDateNames using type=wide and item=months options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(a.value instanceof Array).toBe(true); + expect(a.value.length > 0).toBe(true); + expect(typeof a.value[0]).toBe('string'); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getDateNames(win, fail, {item: 'months'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("isDayLightSavingsTime", function() { + it("should exist", function() { + expect(typeof navigator.globalization.isDayLightSavingsTime).toBeDefined(); + expect(typeof navigator.globalization.isDayLightSavingsTime == 'function').toBe(true); + }); + it("isDayLightSavingsTime using default options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.dst).toBeDefined(); + expect(typeof a.dst).toBe('boolean'); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.isDayLightSavingsTime(new Date(), win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("getFirstDayOfWeek", function() { + it("should exist", function() { + expect(typeof navigator.globalization.getFirstDayOfWeek).toBeDefined(); + expect(typeof navigator.globalization.getFirstDayOfWeek == 'function').toBe(true); + }); + it("getFirstDayOfWeek success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('number'); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getFirstDayOfWeek(win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("numberToString", function() { + it("should exist", function() { + expect(typeof navigator.globalization.numberToString).toBeDefined(); + expect(typeof navigator.globalization.numberToString == 'function').toBe(true); + }); + it("numberToString using default options, should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.numberToString(3.25, win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("numberToString using type=percent options, should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.numberToString(.25, win, fail, {type: 'percent'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("numberToString using type=currency options, should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('string'); + expect(a.value.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.numberToString(5.20, win, fail, {type: 'currency'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("stringToNumber", function() { + it("should exist", function() { + expect(typeof navigator.globalization.stringToNumber).toBeDefined(); + expect(typeof navigator.globalization.stringToNumber == 'function').toBe(true); + }); + it("stringToNumber using default options, should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('number'); + expect(a.value > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + var win2 = function(a) { + navigator.globalization.stringToNumber(a.value, win, fail); + }; + + runs(function () { + navigator.globalization.numberToString(3.25, win2, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("stringToNumber using type=percent options, should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.value).toBeDefined(); + expect(typeof a.value).toBe('number'); + expect(a.value > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + var win2 = function(a) { + navigator.globalization.stringToNumber(a.value, win, fail, {type: 'percent'}); + }; + + runs(function () { + navigator.globalization.numberToString(.25, win2, fail, {type: 'percent'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("getNumberPattern", function() { + it("should exist", function() { + expect(typeof navigator.globalization.getNumberPattern).toBeDefined(); + expect(typeof navigator.globalization.getNumberPattern == 'function').toBe(true); + }); + it("getNumberPattern using default options, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.pattern).toBeDefined(); + expect(typeof a.pattern).toBe('string'); + expect(a.pattern.length > 0).toBe(true); + expect(typeof a.symbol).toBe('string'); + expect(typeof a.fraction).toBe('number'); + expect(typeof a.rounding).toBe('number'); + expect(a.positive).toBeDefined(); + expect(typeof a.positive).toBe('string'); + expect(a.positive.length >= 0).toBe(true); + expect(a.negative).toBeDefined(); + expect(typeof a.negative).toBe('string'); + expect(a.negative.length >= 0).toBe(true); + expect(a.decimal).toBeDefined(); + expect(typeof a.decimal).toBe('string'); + expect(a.decimal.length > 0).toBe(true); + expect(a.grouping).toBeDefined(); + expect(typeof a.grouping).toBe('string'); + expect(a.grouping.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getNumberPattern(win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("getNumberPattern using type=percent, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.pattern).toBeDefined(); + expect(typeof a.pattern).toBe('string'); + expect(a.pattern.length > 0).toBe(true); + expect(typeof a.symbol).toBe('string'); + expect(typeof a.fraction).toBe('number'); + expect(typeof a.rounding).toBe('number'); + expect(a.positive).toBeDefined(); + expect(typeof a.positive).toBe('string'); + expect(a.positive.length >= 0).toBe(true); + expect(a.negative).toBeDefined(); + expect(typeof a.negative).toBe('string'); + expect(a.negative.length >= 0).toBe(true); + expect(a.decimal).toBeDefined(); + expect(typeof a.decimal).toBe('string'); + expect(a.decimal.length > 0).toBe(true); + expect(a.grouping).toBeDefined(); + expect(typeof a.grouping).toBe('string'); + expect(a.grouping.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getNumberPattern(win, fail, {type: 'percent'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + it("getNumberPattern using type=currency, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.pattern).toBeDefined(); + expect(typeof a.pattern).toBe('string'); + expect(a.pattern.length > 0).toBe(true); + expect(typeof a.symbol).toBe('string'); + expect(typeof a.fraction).toBe('number'); + expect(typeof a.rounding).toBe('number'); + expect(a.positive).toBeDefined(); + expect(typeof a.positive).toBe('string'); + expect(a.positive.length >= 0).toBe(true); + expect(a.negative).toBeDefined(); + expect(typeof a.negative).toBe('string'); + expect(a.negative.length >= 0).toBe(true); + expect(a.decimal).toBeDefined(); + expect(typeof a.decimal).toBe('string'); + expect(a.decimal.length > 0).toBe(true); + expect(a.grouping).toBeDefined(); + expect(typeof a.grouping).toBe('string'); + expect(a.grouping.length > 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getNumberPattern(win, fail, {type: 'currency'}); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); + + describe("getCurrencyPattern", function() { + it("should exist", function() { + expect(typeof navigator.globalization.getCurrencyPattern).toBeDefined(); + expect(typeof navigator.globalization.getCurrencyPattern == 'function').toBe(true); + }); + it("getCurrencyPattern using EUR for currency, success callback should be called with a Properties object", function() { + var win = jasmine.createSpy().andCallFake(function(a) { + expect(a).toBeDefined(); + expect(typeof a).toBe('object'); + expect(a.pattern).toBeDefined(); + expect(typeof a.pattern).toBe('string'); + expect(a.pattern.length > 0).toBe(true); + expect(a.code).toBeDefined(); + expect(typeof a.code).toBe('string'); + expect(a.code.length > 0).toBe(true); + expect(typeof a.fraction).toBe('number'); + expect(typeof a.rounding).toBe('number'); + expect(a.decimal).toBeDefined(); + expect(typeof a.decimal).toBe('string'); + expect(a.decimal.length >= 0).toBe(true); + expect(a.grouping).toBeDefined(); + expect(typeof a.grouping).toBe('string'); + expect(a.grouping.length >= 0).toBe(true); + }), + fail = jasmine.createSpy(); + + runs(function () { + navigator.globalization.getCurrencyPattern("EUR", win, fail); + }); + + waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT); + + runs(function () { + expect(fail).not.toHaveBeenCalled(); + }); + }); + }); +}); \ No newline at end of file