tests.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. /* jshint jasmine: true */
  22. /* global cordova, GlobalizationError */
  23. exports.defineAutoTests = function () {
  24. var isWindowsPhone = cordova.platformId == 'windowsphone',
  25. isWindows = (cordova.platformId === "windows") || (cordova.platformId === "windows8"),
  26. isBrowser = cordova.platformId === "browser";
  27. var fail = function (done) {
  28. expect(true).toBe(false);
  29. done();
  30. };
  31. describe('Globalization (navigator.globalization)', function () {
  32. it("globalization.spec.1 should exist", function () {
  33. expect(navigator.globalization).toBeDefined();
  34. });
  35. describe("getPreferredLanguage", function () {
  36. var checkPreferredLanguage = function (a) {
  37. expect(a).toBeDefined();
  38. expect(typeof a).toBe('object');
  39. expect(a.value).toBeDefined();
  40. expect(typeof a.value).toBe('string');
  41. expect(a.value.length > 0).toBe(true);
  42. };
  43. it("globalization.spec.1 should exist", function () {
  44. expect(typeof navigator.globalization.getPreferredLanguage).toBeDefined();
  45. expect(typeof navigator.globalization.getPreferredLanguage == 'function').toBe(true);
  46. });
  47. it("globalization.spec.3 getPreferredLanguage success callback should be called with a Properties object", function (done) {
  48. navigator.globalization.getPreferredLanguage(function (a) {
  49. checkPreferredLanguage(a);
  50. done();
  51. },
  52. fail.bind(null, done));
  53. });
  54. it("globalization.spec.4 getPreferredLanguage return string should contain one or more language subtags separated by hyphen", function (done) {
  55. navigator.globalization.getPreferredLanguage(function (a) {
  56. checkPreferredLanguage(a);
  57. expect(a.value.indexOf('_')).toBe(-1);
  58. // A language tag is composed from a sequence of one or more "subtags", separated by hyphen.
  59. // https://tools.ietf.org/html/bcp47#section-2.1
  60. expect(a.value.split('-').length).toBeGreaterThan(0);
  61. done();
  62. }, fail.bind(null, done));
  63. });
  64. });
  65. describe("getLocaleName", function () {
  66. var checkLocaleName = function (a) {
  67. expect(a).toBeDefined();
  68. expect(typeof a).toBe('object');
  69. expect(a.value).toBeDefined();
  70. expect(typeof a.value).toBe('string');
  71. expect(a.value.length > 0).toBe(true);
  72. };
  73. it("globalization.spec.1 should exist", function () {
  74. expect(typeof navigator.globalization.getLocaleName).toBeDefined();
  75. expect(typeof navigator.globalization.getLocaleName == 'function').toBe(true);
  76. });
  77. it("globalization.spec.3 getLocaleName success callback should be called with a Properties object", function (done) {
  78. navigator.globalization.getLocaleName(function (a) {
  79. checkLocaleName(a);
  80. done();
  81. }, fail.bind(null, done));
  82. });
  83. it("globalization.spec.4 getLocaleName return string should have a hyphen", function (done) {
  84. navigator.globalization.getLocaleName(function (a) {
  85. checkLocaleName(a);
  86. expect(a.value.indexOf('_')).toBe(-1);
  87. if (!isBrowser){
  88. // The browser implementation returns non-BCP 47 compatible
  89. // value in Chrome so we need to skip this expectation. See
  90. // https://github.com/MSOpenTech/cordova-plugin-globalization/blob/21f8a0ffa5aa2497ee970b6b5092b4c65fc4bf7e/README.md#browser-quirks-1
  91. expect(a.value.indexOf('-')).toBeGreaterThan(0);
  92. }
  93. done();
  94. }, fail.bind(null, done));
  95. });
  96. });
  97. describe('Globalization Constants (window.Globalization)', function () {
  98. it("globalization.spec.1 should exist", function () {
  99. expect(window.GlobalizationError).toBeDefined();
  100. expect(window.GlobalizationError.UNKNOWN_ERROR).toBe(0);
  101. expect(window.GlobalizationError.FORMATTING_ERROR).toBe(1);
  102. expect(window.GlobalizationError.PARSING_ERROR).toBe(2);
  103. expect(window.GlobalizationError.PATTERN_ERROR).toBe(3);
  104. });
  105. });
  106. describe("dateToString", function () {
  107. var checkDateToString = function (a) {
  108. expect(a).toBeDefined();
  109. expect(typeof a).toBe('object');
  110. expect(a.value).toBeDefined();
  111. expect(typeof a.value).toBe('string');
  112. expect(a.value.length > 0).toBe(true);
  113. };
  114. it("globalization.spec.1 should exist", function () {
  115. expect(typeof navigator.globalization.dateToString).toBeDefined();
  116. expect(typeof navigator.globalization.dateToString == 'function').toBe(true);
  117. });
  118. it("globalization.spec.5 dateToString using default options, success callback should be called with a Properties object", function (done) {
  119. navigator.globalization.dateToString(new Date(), function (a) {
  120. checkDateToString(a);
  121. done();
  122. }, fail.bind(null, done));
  123. });
  124. it("globalization.spec.6 dateToString using formatLength=short and selector=date options, success callback should be called with a Properties object", function (done) {
  125. navigator.globalization.dateToString(new Date(), function (a) {
  126. checkDateToString(a);
  127. done();
  128. }, fail.bind(null, done),
  129. { formatLength: 'short', selector: 'date' });
  130. });
  131. it("globalization.spec.7 dateToString using formatLength=full and selector=date options, success callback should be called with a Properties object", function (done) {
  132. navigator.globalization.dateToString(new Date(), function (a) {
  133. checkDateToString(a);
  134. done();
  135. }, fail.bind(null, done),
  136. { formatLength: 'full', selector: 'date' });
  137. });
  138. it("globalization.spec.8 dateToString using formatLength=medium and selector=date and time(default) options, success callback should be called with a Properties object", function (done) {
  139. navigator.globalization.dateToString(new Date(), function (a) {
  140. checkDateToString(a);
  141. done();
  142. }, fail.bind(null, done),
  143. { formatLength: 'medium' });
  144. });
  145. it("globalization.spec.9 dateToString using formatLength=long and selector=date and time(default) options, success callback should be called with a Properties object", function (done) {
  146. navigator.globalization.dateToString(new Date(), function (a) {
  147. checkDateToString(a);
  148. done();
  149. }, fail.bind(null, done),
  150. { formatLength: 'long' });
  151. });
  152. it("globalization.spec.10 dateToString using formatLength=full and selector=date and time(default) options, success callback should be called with a Properties object", function (done) {
  153. navigator.globalization.dateToString(new Date(), function (a) {
  154. checkDateToString(a);
  155. done();
  156. }, fail.bind(null, done),
  157. { formatLength: 'full' });
  158. });
  159. });
  160. describe("stringToDate", function () {
  161. var checkStringToDate = function (a) {
  162. expect(a).toBeDefined();
  163. expect(typeof a).toBe('object');
  164. expect(a.year).toBeDefined();
  165. expect(typeof a.year).toBe('number');
  166. expect(a.year >= 0 && a.year <= 9999).toBe(true);
  167. expect(a.month).toBeDefined();
  168. expect(typeof a.month).toBe('number');
  169. expect(a.month >= 0 && a.month <= 11).toBe(true);
  170. expect(a.day).toBeDefined();
  171. expect(typeof a.day).toBe('number');
  172. expect(a.day >= 1 && a.day <= 31).toBe(true);
  173. expect(a.hour).toBeDefined();
  174. expect(typeof a.hour).toBe('number');
  175. expect(a.hour >= 0 && a.hour <= 23).toBe(true);
  176. expect(a.minute).toBeDefined();
  177. expect(typeof a.minute).toBe('number');
  178. expect(a.minute >= 0 && a.minute <= 59).toBe(true);
  179. expect(a.second).toBeDefined();
  180. expect(typeof a.second).toBe('number');
  181. expect(a.second >= 0 && a.second <= 59).toBe(true);
  182. expect(a.millisecond).toBeDefined();
  183. expect(typeof a.millisecond).toBe('number');
  184. };
  185. it("globalization.spec.1 should exist", function () {
  186. expect(typeof navigator.globalization.stringToDate).toBeDefined();
  187. expect(typeof navigator.globalization.stringToDate == 'function').toBe(true);
  188. });
  189. it("globalization.spec.12 stringToDate using default options, success callback should be called with a Properties object", function (done) {
  190. var win = function (a) {
  191. checkStringToDate(a);
  192. done();
  193. };
  194. navigator.globalization.dateToString(new Date(), function (a) {
  195. navigator.globalization.stringToDate(a.value, win, fail.bind(null, done));
  196. }, fail.bind(null, done));
  197. });
  198. it("globalization.spec.13 stringToDate using formatLength=short and selector=date options, success callback should be called with a Properties object", function (done) {
  199. var win = function (a) {
  200. checkStringToDate(a);
  201. done();
  202. };
  203. navigator.globalization.dateToString(new Date(), function (a) {
  204. navigator.globalization.stringToDate(a.value, win, fail.bind(null, done), { formatLength: 'short', selector: 'date' });
  205. }, fail.bind(null, done), { formatLength: 'short', selector: 'date' });
  206. });
  207. it("globalization.spec.14 stringToDate using formatLength=full and selector=date options, success callback should be called with a Properties object", function (done) {
  208. var win = function (a) {
  209. checkStringToDate(a);
  210. done();
  211. };
  212. navigator.globalization.dateToString(new Date(), function (a) {
  213. navigator.globalization.stringToDate(a.value, win, fail.bind(null, done), { formatLength: 'full', selector: 'date' });
  214. }, fail.bind(null, done), { formatLength: 'full', selector: 'date' });
  215. });
  216. it("globalization.spec.15 stringToDate using invalid date, error callback should be called with a GlobalizationError object", function (done) {
  217. navigator.globalization.stringToDate('notADate', fail.bind(null, done), function (a) {
  218. expect(a).toBeDefined();
  219. expect(typeof a).toBe('object');
  220. expect(a.code).toBeDefined();
  221. expect(typeof a.code).toBe('number');
  222. expect(a.code === GlobalizationError.PARSING_ERROR).toBe(true);
  223. expect(a.message).toBeDefined();
  224. expect(typeof a.message).toBe('string');
  225. expect(a.message !== "").toBe(true);
  226. done();
  227. }, { selector: 'foobar' });
  228. });
  229. });
  230. describe("getDatePattern", function () {
  231. var checkDatePattern = function (a) {
  232. expect(a).toBeDefined();
  233. expect(typeof a).toBe('object');
  234. expect(a.pattern).toBeDefined();
  235. expect(typeof a.pattern).toBe('string');
  236. if (!isBrowser) {
  237. // In browser the 'pattern' property is not supported and returns empty string.
  238. // https://github.com/MSOpenTech/cordova-plugin-globalization/blob/21f8a0ffa5aa2497ee970b6b5092b4c65fc4bf7e/README.md#browser-quirks-4
  239. expect(a.pattern.length > 0).toBe(true);
  240. }
  241. expect(a.timezone).toBeDefined();
  242. expect(typeof a.timezone).toBe('string');
  243. if (!isBrowser) {
  244. // The browser platform partially supports 'timezone'. Only Chrome returns 'timezone' property.
  245. // Its format is "Part of the world/{City}". Other browsers return empty string.
  246. // https://github.com/MSOpenTech/cordova-plugin-globalization/blob/21f8a0ffa5aa2497ee970b6b5092b4c65fc4bf7e/README.md#browser-quirks-4
  247. expect(a.pattern.length > 0).toBe(true);
  248. }
  249. expect(a.timezone.length > 0).toBe(true);
  250. expect(a.utc_offset).toBeDefined();
  251. expect(typeof a.utc_offset).toBe('number');
  252. expect(a.dst_offset).toBeDefined();
  253. expect(typeof a.dst_offset).toBe('number');
  254. };
  255. it("globalization.spec.1 should exist", function () {
  256. expect(typeof navigator.globalization.getDatePattern).toBeDefined();
  257. expect(typeof navigator.globalization.getDatePattern == 'function').toBe(true);
  258. });
  259. it("globalization.spec.17 getDatePattern using default options, success callback should be called with a Properties object", function (done) {
  260. navigator.globalization.getDatePattern(function (a) {
  261. checkDatePattern(a);
  262. done();
  263. }, fail.bind(null, done));
  264. });
  265. it("globalization.spec.18 getDatePattern using formatLength=medium and selector=date options, success callback should be called with a Properties object", function (done) {
  266. navigator.globalization.getDatePattern(function (a) {
  267. checkDatePattern(a);
  268. done();
  269. }, fail.bind(null, done),
  270. { formatLength: 'medium', selector: 'date' });
  271. });
  272. });
  273. describe("getDateNames", function () {
  274. var checkDateNames = function (a) {
  275. expect(a).toBeDefined();
  276. expect(typeof a).toBe('object');
  277. expect(a.value).toBeDefined();
  278. expect(a.value instanceof Array).toBe(true);
  279. expect(a.value.length > 0).toBe(true);
  280. expect(typeof a.value[0]).toBe('string');
  281. };
  282. it("globalization.spec.1 should exist", function () {
  283. expect(typeof navigator.globalization.getDateNames).toBeDefined();
  284. expect(typeof navigator.globalization.getDateNames == 'function').toBe(true);
  285. });
  286. it("globalization.spec.20 getDateNames using default options, success callback should be called with a Properties object", function (done) {
  287. navigator.globalization.getDateNames(function (a) {
  288. checkDateNames(a);
  289. done();
  290. }, fail.bind(null, done));
  291. });
  292. it("globalization.spec.21 getDateNames using type=narrow and item=days options, success callback should be called with a Properties object", function (done) {
  293. navigator.globalization.getDateNames(function (a) {
  294. checkDateNames(a);
  295. done();
  296. }, fail.bind(null, done),
  297. { type: 'narrow', item: 'days' });
  298. });
  299. it("globalization.spec.22 getDateNames using type=narrow and item=months options, success callback should be called with a Properties object", function (done) {
  300. navigator.globalization.getDateNames(function (a) {
  301. checkDateNames(a);
  302. done();
  303. }, fail.bind(null, done),
  304. { type: 'narrow', item: 'months' });
  305. });
  306. it("globalization.spec.23 getDateNames using type=wide and item=days options, success callback should be called with a Properties object", function (done) {
  307. navigator.globalization.getDateNames(function (a) {
  308. checkDateNames(a);
  309. done();
  310. }, fail.bind(null, done),
  311. { type: 'wide', item: 'days' });
  312. });
  313. it("globalization.spec.24 getDateNames using type=wide and item=months options, success callback should be called with a Properties object", function (done) {
  314. navigator.globalization.getDateNames(function (a) {
  315. checkDateNames(a);
  316. done();
  317. }, fail.bind(null, done),
  318. { type: 'wide', item: 'months' });
  319. });
  320. });
  321. describe("isDayLightSavingsTime", function () {
  322. it("globalization.spec.1 should exist", function () {
  323. expect(typeof navigator.globalization.isDayLightSavingsTime).toBeDefined();
  324. expect(typeof navigator.globalization.isDayLightSavingsTime == 'function').toBe(true);
  325. });
  326. it("globalization.spec.26 isDayLightSavingsTime using default options, success callback should be called with a Properties object", function (done) {
  327. navigator.globalization.isDayLightSavingsTime(new Date(), function (a) {
  328. expect(a).toBeDefined();
  329. expect(typeof a).toBe('object');
  330. expect(a.dst).toBeDefined();
  331. expect(typeof a.dst).toBe('boolean');
  332. done();
  333. }, fail.bind(null, done));
  334. });
  335. });
  336. describe("getFirstDayOfWeek", function () {
  337. it("globalization.spec.1 should exist", function () {
  338. expect(typeof navigator.globalization.getFirstDayOfWeek).toBeDefined();
  339. expect(typeof navigator.globalization.getFirstDayOfWeek == 'function').toBe(true);
  340. });
  341. it("globalization.spec.28 getFirstDayOfWeek success callback should be called with a Properties object", function (done) {
  342. navigator.globalization.getFirstDayOfWeek(function (a) {
  343. expect(a).toBeDefined();
  344. expect(typeof a).toBe('object');
  345. expect(a.value).toBeDefined();
  346. expect(typeof a.value).toBe('number');
  347. done();
  348. }, fail.bind(null, done));
  349. });
  350. });
  351. describe("numberToString", function () {
  352. var checkNumberToString = function (a) {
  353. expect(a).toBeDefined();
  354. expect(typeof a).toBe('object');
  355. expect(a.value).toBeDefined();
  356. expect(typeof a.value).toBe('string');
  357. expect(a.value.length > 0).toBe(true);
  358. };
  359. it("globalization.spec.1 should exist", function () {
  360. expect(typeof navigator.globalization.numberToString).toBeDefined();
  361. expect(typeof navigator.globalization.numberToString == 'function').toBe(true);
  362. });
  363. it("globalization.spec.30 numberToString using default options, should be called with a Properties object", function (done) {
  364. navigator.globalization.numberToString(3.25, function (a) {
  365. checkNumberToString(a);
  366. done();
  367. }, fail.bind(null, done));
  368. });
  369. it("globalization.spec.31 numberToString using type=percent options, should be called with a Properties object", function (done) {
  370. navigator.globalization.numberToString(0.25, function (a) {
  371. checkNumberToString(a);
  372. done();
  373. }, fail.bind(null, done),
  374. { type: 'percent' });
  375. });
  376. it("globalization.spec.32 numberToString using type=currency options, should be called with a Properties object", function (done) {
  377. // the numberToString using type=currency is not supported on browser
  378. // https://github.com/MSOpenTech/cordova-plugin-globalization/blob/21f8a0ffa5aa2497ee970b6b5092b4c65fc4bf7e/README.md#browser-quirks-7
  379. if (isBrowser) {
  380. pending();
  381. }
  382. navigator.globalization.numberToString(5.20, function (a) {
  383. checkNumberToString(a);
  384. done();
  385. }, fail.bind(null, done),
  386. { type: 'currency' });
  387. });
  388. });
  389. describe("stringToNumber", function () {
  390. var checkStringToNumber = function (a) {
  391. expect(a).toBeDefined();
  392. expect(typeof a).toBe('object');
  393. expect(a.value).toBeDefined();
  394. expect(typeof a.value).toBe('number');
  395. expect(a.value > 0).toBe(true);
  396. };
  397. it("globalization.spec.1 should exist", function () {
  398. expect(typeof navigator.globalization.stringToNumber).toBeDefined();
  399. expect(typeof navigator.globalization.stringToNumber == 'function').toBe(true);
  400. });
  401. it("globalization.spec.34 stringToNumber using default options, should be called with a Properties object", function (done) {
  402. // the stringToNumber is not supported on browser
  403. // https://github.com/MSOpenTech/cordova-plugin-globalization/blob/21f8a0ffa5aa2497ee970b6b5092b4c65fc4bf7e/README.md#supported-platforms-11
  404. if (isBrowser) {
  405. pending();
  406. }
  407. var win = function (a) {
  408. checkStringToNumber(a);
  409. done();
  410. };
  411. navigator.globalization.numberToString(3.25, function (a) {
  412. navigator.globalization.stringToNumber(a.value, win, fail.bind(null, done));
  413. }, fail.bind(null, done));
  414. });
  415. it("globalization.spec.35 stringToNumber using type=percent options, should be called with a Properties object", function (done) {
  416. // the stringToNumber is not supported on browser
  417. // https://github.com/MSOpenTech/cordova-plugin-globalization/blob/21f8a0ffa5aa2497ee970b6b5092b4c65fc4bf7e/README.md#supported-platforms-11
  418. if (isBrowser) {
  419. pending();
  420. }
  421. var win = function (a) {
  422. checkStringToNumber(a);
  423. done();
  424. };
  425. navigator.globalization.numberToString(0.25, function (a) {
  426. navigator.globalization.stringToNumber(a.value, win, fail.bind(null, done), { type: 'percent' });
  427. }, fail.bind(null, done), { type: 'percent' });
  428. });
  429. });
  430. describe("getNumberPattern", function () {
  431. var checkNumberPattern = function (a) {
  432. expect(a).toBeDefined();
  433. expect(typeof a).toBe('object');
  434. expect(a.pattern).toBeDefined();
  435. expect(typeof a.pattern).toBe('string');
  436. expect(a.pattern.length > 0).toBe(true);
  437. expect(typeof a.symbol).toBe('string');
  438. expect(typeof a.fraction).toBe('number');
  439. expect(typeof a.rounding).toBe('number');
  440. expect(a.positive).toBeDefined();
  441. expect(typeof a.positive).toBe('string');
  442. expect(a.positive.length >= 0).toBe(true);
  443. expect(a.negative).toBeDefined();
  444. expect(typeof a.negative).toBe('string');
  445. expect(a.negative.length >= 0).toBe(true);
  446. expect(a.decimal).toBeDefined();
  447. expect(typeof a.decimal).toBe('string');
  448. expect(a.decimal.length > 0).toBe(true);
  449. expect(a.grouping).toBeDefined();
  450. expect(typeof a.grouping).toBe('string');
  451. expect(a.grouping.length > 0).toBe(true);
  452. };
  453. it("globalization.spec.1 should exist", function () {
  454. expect(typeof navigator.globalization.getNumberPattern).toBeDefined();
  455. expect(typeof navigator.globalization.getNumberPattern == 'function').toBe(true);
  456. });
  457. it("globalization.spec.37 getNumberPattern using default options, success callback should be called with a Properties object", function (done) {
  458. // the pattern property is not supported on windows, windows phone and browser
  459. // https://github.com/apache/cordova-plugin-globalization/blob/master/doc/index.md#windows-phone-8-quirks-5
  460. // https://github.com/MSOpenTech/cordova-plugin-globalization/blob/21f8a0ffa5aa2497ee970b6b5092b4c65fc4bf7e/README.md#browser-quirks-6
  461. if (isWindows || isWindowsPhone || isBrowser) {
  462. pending();
  463. }
  464. navigator.globalization.getNumberPattern(function (a) {
  465. checkNumberPattern(a);
  466. done();
  467. }, fail.bind(null, done));
  468. });
  469. it("globalization.spec.38 getNumberPattern using type=percent, success callback should be called with a Properties object", function (done) {
  470. // the pattern property is not supported on windows, windows phone and browser
  471. // https://github.com/apache/cordova-plugin-globalization/blob/master/doc/index.md#windows-phone-8-quirks-5
  472. // https://github.com/MSOpenTech/cordova-plugin-globalization/blob/21f8a0ffa5aa2497ee970b6b5092b4c65fc4bf7e/README.md#browser-quirks-6
  473. if (isWindows || isWindowsPhone || isBrowser) {
  474. pending();
  475. }
  476. navigator.globalization.getNumberPattern(function (a) {
  477. checkNumberPattern(a);
  478. done();
  479. }, fail.bind(null, done), { type: 'percent' });
  480. });
  481. it("globalization.spec.39 getNumberPattern using type=currency, success callback should be called with a Properties object", function (done) {
  482. // the pattern property is not supported on windows, windows phone and browser
  483. // https://github.com/apache/cordova-plugin-globalization/blob/master/doc/index.md#windows-phone-8-quirks-5
  484. // https://github.com/MSOpenTech/cordova-plugin-globalization/blob/21f8a0ffa5aa2497ee970b6b5092b4c65fc4bf7e/README.md#browser-quirks-6
  485. if (isWindows || isWindowsPhone || isBrowser) {
  486. pending();
  487. }
  488. navigator.globalization.getNumberPattern(function (a) {
  489. checkNumberPattern(a);
  490. done();
  491. }, fail.bind(null, done), { type: 'currency' });
  492. });
  493. });
  494. describe("getCurrencyPattern", function () {
  495. it("globalization.spec.1 should exist", function () {
  496. // wp8 is unsupported
  497. if (isWindowsPhone) {
  498. pending();
  499. }
  500. expect(typeof navigator.globalization.getCurrencyPattern).toBeDefined();
  501. expect(typeof navigator.globalization.getCurrencyPattern == 'function').toBe(true);
  502. });
  503. it("globalization.spec.41 getCurrencyPattern using EUR for currency, success callback should be called with a Properties object", function (done) {
  504. // only `code` and `fraction` properties are supported on windows
  505. // https://github.com/apache/cordova-plugin-globalization/blob/master/doc/index.md#windows-quirks-3
  506. // wp8 and browser are unsupported
  507. if (isWindowsPhone || isWindows || isBrowser) {
  508. pending();
  509. }
  510. navigator.globalization.getCurrencyPattern("EUR", function (a) {
  511. expect(a).toBeDefined();
  512. expect(typeof a).toBe('object');
  513. expect(a.pattern).toBeDefined();
  514. expect(typeof a.pattern).toBe('string');
  515. expect(a.pattern.length > 0).toBe(true);
  516. expect(a.code).toBeDefined();
  517. expect(typeof a.code).toBe('string');
  518. expect(a.code.length > 0).toBe(true);
  519. expect(typeof a.fraction).toBe('number');
  520. expect(typeof a.rounding).toBe('number');
  521. expect(a.decimal).toBeDefined();
  522. expect(typeof a.decimal).toBe('string');
  523. expect(a.decimal.length >= 0).toBe(true);
  524. expect(a.grouping).toBeDefined();
  525. expect(typeof a.grouping).toBe('string');
  526. expect(a.grouping.length >= 0).toBe(true);
  527. done();
  528. }, fail.bind(null, done));
  529. });
  530. });
  531. });
  532. };