tests_multi.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. export default function (qunit, $, Inputmask) {
  2. qunit.module("multi masks");
  3. qunit.test("inputmask({ mask: [\"99-99\", \"999-99\"]}) - input 12345", function (assert) {
  4. var done = assert.async(),
  5. $fixture = $("#qunit-fixture");
  6. $fixture.append('<input type="text" id="testmask" />');
  7. var testmask = document.getElementById("testmask");
  8. Inputmask({
  9. mask: ["99-99", "999-99"]
  10. }).mask(testmask);
  11. testmask.focus();
  12. $("#testmask").Type("12345");
  13. setTimeout(function () {
  14. assert.equal(testmask.value, "123-45", "Result " + testmask.value);
  15. done();
  16. }, 0);
  17. });
  18. qunit.test("inputmask({ mask: [\"999.999.999-99\", \"99.999.999/9999-99\"]}) - input 12312312312", function (assert) {
  19. var done = assert.async(),
  20. $fixture = $("#qunit-fixture");
  21. $fixture.append('<input type="text" id="testmask" />');
  22. var testmask = document.getElementById("testmask");
  23. Inputmask({
  24. mask: ["999.999.999-99", "99.999.999/9999-99"]
  25. }).mask(testmask);
  26. testmask.focus();
  27. $("#testmask").Type("12312312312");
  28. setTimeout(function () {
  29. assert.equal(testmask.value, "123.123.123-12", "Result " + testmask.value);
  30. done();
  31. }, 0);
  32. });
  33. qunit.test("inputmask({ mask: [\"999.999.999-99\", \"99.999.999/9999-99\"]}) - input 12.123123123412", function (assert) {
  34. var done = assert.async(),
  35. $fixture = $("#qunit-fixture");
  36. $fixture.append('<input type="text" id="testmask" />');
  37. var testmask = document.getElementById("testmask");
  38. Inputmask({
  39. mask: ["999.999.999-99", "99.999.999/9999-99"]
  40. }).mask(testmask);
  41. testmask.focus();
  42. $("#testmask").Type("12.123123123412");
  43. setTimeout(function () {
  44. assert.equal(testmask.value, "12.123.123/1234-12", "Result " + testmask.value);
  45. done();
  46. }, 0);
  47. });
  48. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 12345 greedy + blur", function (assert) {
  49. var done = assert.async(),
  50. $fixture = $("#qunit-fixture");
  51. $fixture.append('<input type="text" id="testmask" />');
  52. var testmask = document.getElementById("testmask");
  53. Inputmask({
  54. mask: ["99999", "99999-9999"]
  55. }).mask(testmask);
  56. testmask.focus();
  57. $("#testmask").Type("12345");
  58. testmask.blur();
  59. setTimeout(function () {
  60. assert.equal(testmask.inputmask._valueGet(), "12345", "Result " + testmask.inputmask._valueGet());
  61. done();
  62. }, 0);
  63. });
  64. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 12345 not greedy", function (assert) {
  65. var done = assert.async(),
  66. $fixture = $("#qunit-fixture");
  67. $fixture.append('<input type="text" id="testmask" />');
  68. var testmask = document.getElementById("testmask");
  69. Inputmask({
  70. mask: ["99999", "99999-9999"],
  71. greedy: false,
  72. keepStatic: true
  73. }).mask(testmask);
  74. testmask.focus();
  75. $("#testmask").Type("12345");
  76. setTimeout(function () {
  77. assert.equal(testmask.value, "12345", "Result " + testmask.value);
  78. done();
  79. }, 0);
  80. });
  81. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 12345-1234", function (assert) {
  82. var done = assert.async(),
  83. $fixture = $("#qunit-fixture");
  84. $fixture.append('<input type="text" id="testmask" />');
  85. var testmask = document.getElementById("testmask");
  86. Inputmask({
  87. mask: ["99999", "99999-9999"]
  88. }).mask(testmask);
  89. testmask.focus();
  90. $("#testmask").Type("12345-1234");
  91. setTimeout(function () {
  92. assert.equal(testmask.value, "12345-1234", "Result " + testmask.value);
  93. done();
  94. }, 0);
  95. });
  96. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 123451234", function (assert) {
  97. var done = assert.async(),
  98. $fixture = $("#qunit-fixture");
  99. $fixture.append('<input type="text" id="testmask" />');
  100. var testmask = document.getElementById("testmask");
  101. Inputmask({
  102. mask: ["99999", "99999-9999"]
  103. }).mask(testmask);
  104. testmask.focus();
  105. $("#testmask").Type("123451234");
  106. setTimeout(function () {
  107. assert.equal(testmask.value, "12345-1234", "Result " + testmask.value);
  108. done();
  109. }, 0);
  110. });
  111. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 1234512", function (assert) {
  112. var done = assert.async(),
  113. $fixture = $("#qunit-fixture");
  114. $fixture.append('<input type="text" id="testmask" />');
  115. var testmask = document.getElementById("testmask");
  116. Inputmask({
  117. mask: ["99999", "99999-9999"]
  118. }).mask(testmask);
  119. testmask.focus();
  120. $("#testmask").Type("1234512");
  121. setTimeout(function () {
  122. assert.equal(testmask.value, "12345-12__", "Result " + testmask.value);
  123. done();
  124. }, 0);
  125. });
  126. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\", \"999999-9999\"]]}) - input 1234561234", function (assert) {
  127. var done = assert.async(),
  128. $fixture = $("#qunit-fixture");
  129. $fixture.append('<input type="text" id="testmask" />');
  130. var testmask = document.getElementById("testmask");
  131. Inputmask({
  132. mask: ["99999", "99999-9999", "999999-9999"]
  133. }).mask(testmask);
  134. testmask.focus();
  135. $("#testmask").Type("1234561234");
  136. setTimeout(function () {
  137. assert.equal(testmask.value, "123456-1234", "Result " + testmask.value);
  138. done();
  139. }, 0);
  140. });
  141. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\", \"999999-9999\"]]}) - input 12345-6", function (assert) {
  142. var done = assert.async(),
  143. $fixture = $("#qunit-fixture");
  144. $fixture.append('<input type="text" id="testmask" />');
  145. var testmask = document.getElementById("testmask");
  146. Inputmask({
  147. mask: ["99999", "99999-9999", "999999-9999"]
  148. }).mask(testmask);
  149. testmask.focus();
  150. $("#testmask").Type("12345-6");
  151. setTimeout(function () {
  152. assert.equal(testmask.value, "12345-6___", "Result " + testmask.value);
  153. done();
  154. }, 0);
  155. });
  156. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\", \"999999-9999\"], keepStatic: false}) - input 123456", function (assert) {
  157. var done = assert.async(),
  158. $fixture = $("#qunit-fixture");
  159. $fixture.append('<input type="text" id="testmask" />');
  160. var testmask = document.getElementById("testmask");
  161. Inputmask({
  162. mask: ["99999", "99999-9999", "999999-9999"],
  163. keepStatic: false
  164. }).mask(testmask);
  165. testmask.focus();
  166. $("#testmask").Type("123456");
  167. setTimeout(function () {
  168. assert.equal(testmask.value, "123456-____", "Result " + testmask.value);
  169. done();
  170. }, 0);
  171. });
  172. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\", \"999999-9999\"] , keepStatic: true}) - input 123456", function (assert) {
  173. var done = assert.async(),
  174. $fixture = $("#qunit-fixture");
  175. $fixture.append('<input type="text" id="testmask" />');
  176. var testmask = document.getElementById("testmask");
  177. Inputmask({
  178. mask: ["99999", "99999-9999", "999999-9999"],
  179. keepStatic: true
  180. }).mask(testmask);
  181. testmask.focus();
  182. $("#testmask").Type("123456");
  183. setTimeout(function () {
  184. assert.equal(testmask.value, "12345-6___", "Result " + testmask.value);
  185. done();
  186. }, 0);
  187. });
  188. qunit.test("inputmask({ mask: [\"99999\", \"99999-9999\", \"999999-9999\"]]}) - input 123456 (rtl)", function (assert) {
  189. var done = assert.async(),
  190. $fixture = $("#qunit-fixture");
  191. $fixture.append('<input type="text" id="testmask" dir="rtl" />');
  192. var testmask = document.getElementById("testmask");
  193. Inputmask({
  194. mask: ["99999", "99999-9999", "999999-9999"]
  195. }).mask(testmask);
  196. testmask.focus();
  197. setTimeout(function () { //needed to pass on ie
  198. $("#testmask").Type("123456");
  199. setTimeout(function () {
  200. assert.equal(testmask.value, "___6-54321", "Result " + testmask.value);
  201. done();
  202. }, 0);
  203. }, 0);
  204. });
  205. qunit.test("inputmask({ mask: ['9 AAA-AAA', 'A 999-999'] }) ", function (assert) {
  206. var done = assert.async(),
  207. $fixture = $("#qunit-fixture");
  208. $fixture.append('<input type="text" id="testmask" />');
  209. var testmask = document.getElementById("testmask");
  210. Inputmask({
  211. mask: ['9 AAA-AAA', 'A 999-999']
  212. }).mask(testmask);
  213. $("#testmask").Type("1abc");
  214. setTimeout(function () {
  215. assert.equal(testmask.value, "1 ABC-___", "Result " + testmask.value);
  216. done();
  217. }, 0);
  218. });
  219. qunit.test("inputmask({ mask: ['9 AAA-AAA', 'A 999-999'] }) ", function (assert) {
  220. var done = assert.async(),
  221. $fixture = $("#qunit-fixture");
  222. $fixture.append('<input type="text" id="testmask" />');
  223. var testmask = document.getElementById("testmask");
  224. Inputmask({
  225. mask: ['9 AAA-AAA', 'A 999-999']
  226. }).mask(testmask);
  227. $("#testmask").Type("a123");
  228. setTimeout(function () {
  229. assert.equal(testmask.value, "A 123-___", "Result " + testmask.value);
  230. done();
  231. }, 0);
  232. });
  233. qunit.test("inputmask({ mask: ['99.9', 'X'}) - annames", function (assert) {
  234. var $fixture = $("#qunit-fixture");
  235. $fixture.append('<input type="text" id="testmask" />');
  236. var testmask = document.getElementById("testmask");
  237. Inputmask({
  238. mask: ["99.9", "X", "abc"],
  239. definitions: {
  240. "X": {
  241. validator: "[xX]",
  242. cardinality: 1,
  243. casing: "upper"
  244. }
  245. }
  246. }).mask(testmask);
  247. $("#testmask").Type("x");
  248. assert.equal(testmask.value, "X", "Result " + testmask.value);
  249. });
  250. qunit.test("inputmask({ mask: [{ \"mask\": \"###-##-####\" }]) - lynxlive", function (assert) {
  251. var $fixture = $("#qunit-fixture");
  252. $fixture.append('<input type="text" id="testmask" />');
  253. var testmask = document.getElementById("testmask");
  254. var ssns = [{
  255. "mask": "###-##-####"
  256. }];
  257. Inputmask({
  258. mask: ssns,
  259. greedy: false,
  260. definitions: {
  261. '#': {
  262. validator: "[0-9]",
  263. cardinality: 1
  264. }
  265. }
  266. }).mask(testmask);
  267. $("#testmask").Type("123121234");
  268. assert.equal(testmask.value, "123-12-1234", "Result " + testmask.value);
  269. });
  270. qunit.test("'[9-]AAA-999', '999999' - type 1A - dekdegiv", function (assert) {
  271. var $fixture = $("#qunit-fixture");
  272. $fixture.append('<input type="text" id="testmask" />');
  273. var testmask = document.getElementById("testmask");
  274. Inputmask({
  275. "mask": ['[9-]AAA-999', '999999'],
  276. keepStatic: false
  277. }).mask(testmask);
  278. $("#testmask").Type("1a");
  279. assert.equal(testmask.value, "1-A__-___", "Result " + testmask.value);
  280. });
  281. qunit.test("(99 99 999999)|(*{+}) - 12abc - dekdegiv", function (assert) {
  282. var $fixture = $("#qunit-fixture");
  283. $fixture.append('<input type="text" id="testmask" />');
  284. var testmask = document.getElementById("testmask");
  285. Inputmask("(99 99 999999)|(*{+})").mask(testmask);
  286. $("#testmask").Type("12abc");
  287. assert.equal(testmask.value, "12abc", "Result " + testmask.value);
  288. });
  289. qunit.test("(99 99 999999)|(*{+}) - 12 34 delete ' 34' + 2abc", function (assert) {
  290. var $fixture = $("#qunit-fixture");
  291. $fixture.append('<input type="text" id="testmask" />');
  292. var testmask = document.getElementById("testmask");
  293. Inputmask("(99 99 999999)|(*{+})").mask(testmask);
  294. $("#testmask").Type("12 34");
  295. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  296. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  297. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  298. $("#testmask").Type("2abc");
  299. assert.equal(testmask.value, "122abc", "Result " + testmask.value);
  300. });
  301. qunit.test("(99 99 999999)|(i{+}) - 12 3abc - dekdegiv", function (assert) {
  302. var $fixture = $("#qunit-fixture");
  303. $fixture.append('<input type="text" id="testmask" />');
  304. var testmask = document.getElementById("testmask");
  305. Inputmask("(99 99 999999)|(*{+})", {
  306. definitions: {
  307. "*": {
  308. validator: ".",
  309. cardinality: 1,
  310. definitionSymbol: "*"
  311. }
  312. },
  313. staticDefinitionSymbol: "*"
  314. }).mask(testmask);
  315. $("#testmask").Type("12 3abc");
  316. assert.equal(testmask.value, "12 3abc", "Result " + testmask.value);
  317. });
  318. qunit.test("[\"(99) 9999-9999\",\"(99) 99999-9999\"] - 12123451234 - click front - asyncerror", function (assert) {
  319. var $fixture = $("#qunit-fixture");
  320. $fixture.append('<input type="text" id="testmask" />');
  321. var testmask = document.getElementById("testmask");
  322. Inputmask(["(99) 9999-9999", "(99) 99999-9999"]).mask(testmask);
  323. $("#testmask").Type("12123451234");
  324. $.caret(testmask, 0);
  325. testmask.focus();
  326. $("#testmask").trigger("click");
  327. assert.equal(testmask.value, "(12) 12345-1234", "Result " + testmask.value);
  328. });
  329. qunit.test("[\"+7(999)999-99-99\",\"+380(99)999-99-99\",\"+375(99)999-99-99\"] - andychups", function (assert) {
  330. var done = assert.async(),
  331. $fixture = $("#qunit-fixture");
  332. $fixture.append('<input type="text" id="testmask" />');
  333. var testmask = document.getElementById("testmask");
  334. Inputmask(["+7(999)999-99-99", "+380(99)999-99-99", "+375(99)999-99-99"], {
  335. keepStatic: false
  336. }).mask(testmask);
  337. $("#testmask").Type("3");
  338. setTimeout(function () {
  339. assert.equal(testmask.inputmask._valueGet(), "+3__(__)___-__-__", "Result " + testmask.inputmask._valueGet());
  340. done();
  341. }, 0);
  342. });
  343. qunit.test("[\"+7(999)999-99-99\",\"+380(99)999-99-99\",\"+375(99)999-99-99\"] - andychups", function (assert) {
  344. var $fixture = $("#qunit-fixture");
  345. $fixture.append('<input type="text" id="testmask" />');
  346. var testmask = document.getElementById("testmask");
  347. Inputmask(["+7(999)999-99-99", "+380(99)999-99-99", "+375(99)999-99-99"], {
  348. keepStatic: false
  349. }).mask(testmask);
  350. testmask.focus();
  351. $("#testmask").trigger("click");
  352. assert.equal(testmask.inputmask._valueGet(), "+_(___)___-__-__", "Result " + testmask.inputmask._valueGet());
  353. });
  354. qunit.test("(9{4} 9{4} 9{4} 9{4})|(9{4} 9{6} 9[5])|(9{9} 9{9}) - 1234123412341234 - necrosisoff ", function (assert) {
  355. var $fixture = $("#qunit-fixture");
  356. $fixture.append('<input type="text" id="testmask" />');
  357. var testmask = document.getElementById("testmask");
  358. Inputmask("(9{4} 9{4} 9{4} 9{4})|(9{4} 9{6} 9[5])|(9{9} 9{9})", {
  359. "keepStatic": true
  360. }
  361. ).mask(testmask);
  362. testmask.focus();
  363. $("#testmask").Type("1234123412341234")
  364. assert.equal(testmask.inputmask._valueGet(), "1234 1234 1234 1234", "Result " + testmask.inputmask._valueGet());
  365. });
  366. qunit.test("(9{4} 9{4} 9{4} 9{4})|(9{4} 9{6} 9[5])|(9{9} 9{9}) - 12341234123412341 - necrosisoff ", function (assert) {
  367. var $fixture = $("#qunit-fixture");
  368. $fixture.append('<input type="text" id="testmask" />');
  369. var testmask = document.getElementById("testmask");
  370. Inputmask("(9{4} 9{4} 9{4} 9{4})|(9{4} 9{6} 9[5])|(9{9} 9{9})", {
  371. "keepStatic": true
  372. }
  373. ).mask(testmask);
  374. testmask.focus();
  375. $("#testmask").Type("12341234123412341")
  376. assert.equal(testmask.inputmask._valueGet(), "123412341 23412341_", "Result " + testmask.inputmask._valueGet());
  377. });
  378. };