tests_numericinput.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. export default function (qunit, $, Inputmask) {
  2. qunit.module("Direction RTL");
  3. qunit.test("inputmask(\"999.999.999\") - delete 2nd with backspace, continue the mask", function (assert) {
  4. var done = assert.async(),
  5. $fixture = $("#qunit-fixture");
  6. $fixture.append('<input type="text" id="testmask" dir="rtl" />');
  7. var testmask = document.getElementById("testmask");
  8. Inputmask("999.999.999").mask(testmask);
  9. testmask.focus();
  10. setTimeout(function () {
  11. $("#testmask").SendKey("1");
  12. $("#testmask").SendKey("2");
  13. $("#testmask").SendKey("3");
  14. $("#testmask").SendKey(Inputmask.keyCode.RIGHT);
  15. $("#testmask").SendKey(Inputmask.keyCode.RIGHT);
  16. $("#testmask").SendKey(Inputmask.keyCode.RIGHT);
  17. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  18. $("#testmask").SendKey("4");
  19. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  20. $("#testmask").SendKey("5");
  21. $("#testmask").SendKey("6");
  22. assert.equal(testmask.value, "___._65.341", "Result " + testmask.value);
  23. done();
  24. }, 0);
  25. });
  26. qunit.test("inputmask(\"999.999.999\") - delete 2nd with delete, continue the mask", function (assert) {
  27. var done = assert.async(),
  28. $fixture = $("#qunit-fixture");
  29. $fixture.append('<input type="text" id="testmask" dir="rtl" />');
  30. var testmask = document.getElementById("testmask");
  31. Inputmask("999.999.999").mask(testmask);
  32. testmask.focus();
  33. setTimeout(function () {
  34. $("#testmask").SendKey("1");
  35. $("#testmask").SendKey("2");
  36. $("#testmask").SendKey("3");
  37. $("#testmask").SendKey(Inputmask.keyCode.RIGHT);
  38. $("#testmask").SendKey(Inputmask.keyCode.RIGHT);
  39. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  40. $("#testmask").SendKey("4");
  41. $("#testmask").SendKey(Inputmask.keyCode.LEFT);
  42. $("#testmask").SendKey("5");
  43. $("#testmask").SendKey("6");
  44. assert.equal(testmask.value, "___._65.341", "Result " + testmask.value);
  45. done();
  46. }, 0);
  47. });
  48. qunit.test("inputmask(\"999-aaa-999\")", function (assert) {
  49. var done = assert.async(),
  50. $fixture = $("#qunit-fixture");
  51. $fixture.append('<input type="text" id="testmask" dir="rtl" />');
  52. var testmask = document.getElementById("testmask");
  53. Inputmask("999-aaa-999").mask(testmask);
  54. testmask.focus();
  55. setTimeout(function () {
  56. $("#testmask").Type("123abc12");
  57. assert.equal(testmask.value, "_21-cba-321", "Result " + testmask.value);
  58. done();
  59. }, 0);
  60. });
  61. qunit.test("inputmask(\"999-999-999\") - replace selection", function (assert) {
  62. var done = assert.async(),
  63. $fixture = $("#qunit-fixture");
  64. $fixture.append('<input type="text" id="testmask" dir="rtl" />');
  65. var testmask = document.getElementById("testmask");
  66. Inputmask("999-999-999").mask(testmask);
  67. testmask.focus();
  68. setTimeout(function () {
  69. $("#testmask").Type("123456789");
  70. $.caret(testmask, 4, 7);
  71. $("#testmask").Type("5");
  72. assert.equal(testmask.value, "__9-875-321", "Result " + testmask.value);
  73. done();
  74. }, 0);
  75. });
  76. qunit.test("inputmask(\"999-999-999\") - replace selection with backspace", function (assert) {
  77. var done = assert.async(),
  78. $fixture = $("#qunit-fixture");
  79. $fixture.append('<input type="text" id="testmask" dir="rtl" />');
  80. var testmask = document.getElementById("testmask");
  81. Inputmask("999-999-999").mask(testmask);
  82. testmask.focus();
  83. setTimeout(function () {
  84. $("#testmask").Type("123456789");
  85. $.caret(testmask, 4, 7);
  86. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  87. $("#testmask").Type("5");
  88. assert.equal(testmask.value, "__9-875-321", "Result " + testmask.value);
  89. done();
  90. }, 0);
  91. });
  92. qunit.test("inputmask(\"999-999-999\") - replace selection - with delete", function (assert) {
  93. var done = assert.async(),
  94. $fixture = $("#qunit-fixture");
  95. $fixture.append('<input type="text" id="testmask" dir="rtl" />');
  96. var testmask = document.getElementById("testmask");
  97. Inputmask("999-999-999").mask(testmask);
  98. testmask.focus();
  99. setTimeout(function () {
  100. $("#testmask").Type("123456789");
  101. $.caret(testmask, 4, 7);
  102. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  103. $("#testmask").Type("5");
  104. assert.equal(testmask.value, "__9-875-321", "Result " + testmask.value);
  105. done();
  106. }, 0);
  107. });
  108. qunit.module("Numeric Input");
  109. qunit.test("inputmask({ mask: \"9\", numericInput: true, repeat: 10, greedy: true }); - 1234567890", function (assert) {
  110. var done = assert.async(),
  111. $fixture = $("#qunit-fixture");
  112. $fixture.append('<input type="text" id="testmask" />');
  113. var testmask = document.getElementById("testmask");
  114. Inputmask({
  115. mask: "9",
  116. numericInput: true,
  117. repeat: 10,
  118. greedy: true
  119. }).mask(testmask);
  120. testmask.focus();
  121. setTimeout(function () {
  122. $("#testmask").Type("1234567890");
  123. assert.equal(testmask.value, "1234567890", "Result " + testmask.value);
  124. done();
  125. }, 0);
  126. });
  127. qunit.test("inputmask({ mask: \"9\", numericInput: true, repeat: 10, greedy: true }); - replace selection", function (assert) {
  128. var done = assert.async(),
  129. $fixture = $("#qunit-fixture");
  130. $fixture.append('<input type="text" id="testmask" />');
  131. var testmask = document.getElementById("testmask");
  132. Inputmask({
  133. mask: "9",
  134. numericInput: true,
  135. repeat: 10,
  136. greedy: true
  137. }).mask(testmask);
  138. testmask.focus();
  139. setTimeout(function () {
  140. $("#testmask").Type("1234567890");
  141. $.caret(testmask, 3, 6);
  142. $("#testmask").Type("5");
  143. assert.equal(testmask.value, "__12357890", "Result " + testmask.value);
  144. done();
  145. }, 0);
  146. });
  147. qunit.test("inputmask({ mask: \"99-99-99\", numericInput: true }); - 1234567890", function (assert) {
  148. var done = assert.async(),
  149. $fixture = $("#qunit-fixture");
  150. $fixture.append('<input type="text" id="testmask" />');
  151. var testmask = document.getElementById("testmask");
  152. Inputmask({
  153. mask: "99-99-99",
  154. numericInput: true
  155. }).mask(testmask);
  156. testmask.focus();
  157. setTimeout(function () {
  158. $("#testmask").Type("1234567890");
  159. assert.equal(testmask.value, "12-34-56", "Result " + testmask.value);
  160. done();
  161. }, 0);
  162. });
  163. qunit.test("inputmask({ mask: \"€ 999.999.999,99\", numericInput: true }); - 123", function (assert) {
  164. var done = assert.async(),
  165. $fixture = $("#qunit-fixture");
  166. $fixture.append('<input type="text" id="testmask" />');
  167. var testmask = document.getElementById("testmask");
  168. Inputmask('€ 999.999.999,99', {
  169. numericInput: true
  170. }).mask(testmask);
  171. testmask.focus();
  172. setTimeout(function () {
  173. $("#testmask").Type("123");
  174. assert.equal(testmask.value, "€ ___.___.__1,23", "Result " + testmask.value);
  175. done();
  176. }, 0);
  177. });
  178. qunit.test("inputmask({ mask: \"€ 999.999.999,99\", numericInput: true }); - 123 position before 456", function (assert) {
  179. var done = assert.async(),
  180. $fixture = $("#qunit-fixture");
  181. $fixture.append('<input type="text" id="testmask" />');
  182. var testmask = document.getElementById("testmask");
  183. Inputmask('€ 999.999.999,99', {
  184. numericInput: true
  185. }).mask(testmask);
  186. testmask.focus();
  187. setTimeout(function () {
  188. $("#testmask").Type("123");
  189. $.caret(testmask, 12);
  190. $("#testmask").Type("456");
  191. assert.equal(testmask.value, "€ ___.__4.561,23", "Result " + testmask.value);
  192. done();
  193. }, 0);
  194. });
  195. qunit.test("inputmask({ mask: \"€ 999.999.999,99\", { numericInput: true, radixPoint: \",\" }); - 123", function (assert) {
  196. var done = assert.async(),
  197. $fixture = $("#qunit-fixture");
  198. $fixture.append('<input type="text" id="testmask" />');
  199. var testmask = document.getElementById("testmask");
  200. Inputmask('€ 999.999.999,99', {
  201. numericInput: true,
  202. radixPoint: ","
  203. }).mask(testmask);
  204. testmask.focus();
  205. $("#testmask").trigger("click");
  206. ;
  207. setTimeout(function () {
  208. $("#testmask").Type("123");
  209. assert.equal(testmask.value, "€ ___.___.__1,23", "Result " + testmask.value);
  210. done();
  211. }, 0);
  212. });
  213. qunit.test("inputmask({ mask: \"€ 999.999.999,99\", { numericInput: true, radixPoint: \",\" }); - 123,45", function (assert) {
  214. var done = assert.async(),
  215. $fixture = $("#qunit-fixture");
  216. $fixture.append('<input type="text" id="testmask" />');
  217. var testmask = document.getElementById("testmask");
  218. Inputmask('€ 999.999.999,99', {
  219. numericInput: true,
  220. radixPoint: ","
  221. }).mask(testmask);
  222. testmask.focus();
  223. $("#testmask").trigger("click");
  224. ;
  225. setTimeout(function () {
  226. $("#testmask").Type("123,45");
  227. assert.equal(testmask.value, "€ ___.___.123,45", "Result " + testmask.value);
  228. done();
  229. }, 0);
  230. });
  231. qunit.test("inputmask({ mask: \"9999 t\", { numericInput: true }); - 123 - Joe Rosa", function (assert) {
  232. var done = assert.async(),
  233. $fixture = $("#qunit-fixture");
  234. $fixture.append('<input type="text" id="testmask" />');
  235. var testmask = document.getElementById("testmask");
  236. Inputmask('9999 t', {
  237. numericInput: true
  238. }).mask(testmask);
  239. testmask.focus();
  240. $("#testmask").trigger("click");
  241. setTimeout(function () {
  242. $("#testmask").Type("123");
  243. assert.equal(testmask.value, "_123 t", "Result " + testmask.value);
  244. done();
  245. }, 0);
  246. });
  247. qunit.test("inputmask({ mask: \"9999 t\", { numericInput: true, autoUnmask: true }); - 70 - Joe Rosa", function (assert) {
  248. var done = assert.async(),
  249. $fixture = $("#qunit-fixture");
  250. $fixture.append('<input type="text" id="testmask" />');
  251. var testmask = document.getElementById("testmask");
  252. Inputmask('9999 t', {
  253. numericInput: true,
  254. autoUnmask: true
  255. }).mask(testmask);
  256. testmask.focus();
  257. $("#testmask").trigger("click");
  258. ;
  259. setTimeout(function () {
  260. $("#testmask").Type("70");
  261. assert.equal(testmask.value, "70", "Result " + testmask.value);
  262. done();
  263. }, 0);
  264. });
  265. qunit.test("inputmask({ mask: \"['$9.99', '$99.99', '$999.99', '$9,999.99', '$99,999.99', '$999,999.99', '$9,999,999.99', '$99,999,999.99', '$999,999,999.99'], 'placeholder': ' ', 'numericInput': true, 'rightAlignNumerics': false\" value=\"$100000.00\"", function (assert) {
  266. var done = assert.async(),
  267. $fixture = $("#qunit-fixture");
  268. $fixture.append("<input type=\"text\" id=\"testmask\" data-inputmask=\"'mask': ['$9.99', '$99.99', '$999.99', '$9,999.99', '$99,999.99', '$999,999.99', '$9,999,999.99', '$99,999,999.99', '$999,999,999.99'], 'placeholder': ' ', 'numericInput': true, 'rightAlignNumerics': false\" value=\"$100000.00\"/>");
  269. var testmask = document.getElementById("testmask");
  270. Inputmask().mask(testmask);
  271. setTimeout(function () {
  272. assert.equal(testmask.value, "$100,000.00", "Result " + testmask.value);
  273. done();
  274. }, 0);
  275. });
  276. qunit.test("cuurency - numericInput: true - 123456 backspace x4", function (assert) {
  277. var done = assert.async(),
  278. $fixture = $("#qunit-fixture");
  279. $fixture.append('<input type="text" id="testmask" />');
  280. var testmask = document.getElementById("testmask");
  281. Inputmask("currency", {
  282. numericInput: true
  283. }).mask(testmask);
  284. testmask.focus();
  285. setTimeout(function () {
  286. $("#testmask").Type("123456");
  287. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  288. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  289. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  290. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  291. assert.equal(testmask.value, "$ 0.12", "Result " + testmask.value);
  292. done();
  293. }, 0);
  294. });
  295. qunit.test("decimal - numericInput: true - initial value 20,00 - Inkeliz", function (assert) {
  296. var $fixture = $("#qunit-fixture");
  297. $fixture.append('<input type="text" id="testmask" value="20,00" />');
  298. var testmask = document.getElementById("testmask");
  299. Inputmask('decimal', {
  300. radixPoint: ',',
  301. rightAlign: false,
  302. showMaskOnHover: false,
  303. numericInput: true,
  304. allowPlus: false,
  305. rightAlignNumerics: false,
  306. greedy: false
  307. }).mask(testmask);
  308. assert.equal(testmask.value, "20,00", "Result " + testmask.value);
  309. });
  310. qunit.test("currency - numericInput: true - initial value 4545.56 - sadhuria", function (assert) {
  311. var $fixture = $("#qunit-fixture");
  312. $fixture.append('<input type="text" id="testmask" value="4545.56" />');
  313. var testmask = document.getElementById("testmask");
  314. Inputmask("currency", {
  315. groupSeparator: ',',
  316. placeholder: '0.00',
  317. numericInput: true,
  318. autoGroup: true
  319. }).mask(testmask);
  320. assert.equal(testmask.value, "$ 4,545.56", "Result " + testmask.value);
  321. });
  322. };