tests_keepStatic.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. export default function(qunit, $, Inputmask) {
  2. qunit.module("keepStatic mask switching");
  3. qunit.test("{ mask: [\"+55-99-9999-9999\", \"+55-99-99999-9999\", ], keepStatic: true }", function(assert) {
  4. var $fixture = $("#qunit-fixture");
  5. $fixture.append('<input type="text" id="testmask" />');
  6. var testmask = document.getElementById("testmask");
  7. Inputmask({
  8. mask: ["+55-99-9999-9999", "+55-99-99999-9999"],
  9. keepStatic: true
  10. }).mask(testmask);
  11. testmask.focus();
  12. $("#testmask").Type("12123451234");
  13. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "+55-12-12345-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
  14. });
  15. qunit.test("{ mask: \"+55-99-9999|(99)-9999\", keepStatic: true } - type 12123451234", function(assert) {
  16. var $fixture = $("#qunit-fixture");
  17. $fixture.append('<input type="text" id="testmask" />');
  18. var testmask = document.getElementById("testmask");
  19. Inputmask({
  20. mask: "+55-99-9999|(99)-9999",
  21. keepStatic: true
  22. }).mask(testmask);
  23. testmask.focus();
  24. $("#testmask").Type("12123451234");
  25. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "+55-12-12345-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
  26. });
  27. qunit.test("{ mask: ['(99) 9999-9999', '(99) 99999-9999'] } - val('1212341234')", function(assert) {
  28. var $fixture = $("#qunit-fixture");
  29. $fixture.append('<input type="text" id="testmask" />');
  30. var testmask = document.getElementById("testmask");
  31. Inputmask({
  32. mask: ['(99) 9999-9999', '(99) 99999-9999']
  33. }).mask(testmask);
  34. $("#testmask").val("1212341234");
  35. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "(12) 1234-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
  36. });
  37. qunit.test("{ mask: \"+55-99-9999|(99)-9999\", keepStatic: false } type 12123451234", function(assert) {
  38. var $fixture = $("#qunit-fixture");
  39. $fixture.append('<input type="text" id="testmask" />');
  40. var testmask = document.getElementById("testmask");
  41. Inputmask({
  42. mask: "+55-99-9999|(99)-9999",
  43. keepStatic: false
  44. }).mask(testmask);
  45. testmask.focus();
  46. $("#testmask").Type("12123451234");
  47. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "+55-12-12345-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
  48. });
  49. qunit.test("{ mask: [\"+55-99-9999-9999\", \"+55-99-99999-9999\", ], keepStatic: true } - type 12123451234 + backspace", function(assert) {
  50. var $fixture = $("#qunit-fixture");
  51. $fixture.append('<input type="text" id="testmask" />');
  52. var testmask = document.getElementById("testmask");
  53. Inputmask({
  54. mask: ["+55-99-9999-9999", "+55-99-99999-9999"],
  55. keepStatic: true
  56. }).mask(testmask);
  57. testmask.focus();
  58. $("#testmask").Type("12123451234");
  59. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  60. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "+55-12-1234-5123", "Result " + document.getElementById("testmask").inputmask._valueGet());
  61. });
  62. qunit.test("{ mask: [\"99-9999-99\",\"99-99999-99\"] } - type 12123412 + add 1 upfront", function(assert) {
  63. var $fixture = $("#qunit-fixture");
  64. $fixture.append('<input type="text" id="testmask" />');
  65. var testmask = document.getElementById("testmask");
  66. Inputmask({
  67. mask: ["99-9999-99", "99-99999-99"]
  68. }).mask(testmask);
  69. $("#testmask").Type("12123412");
  70. $.caret(testmask, 0);
  71. $("#testmask").Type("1");
  72. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "11-21234-12", "Result " + document.getElementById("testmask").inputmask._valueGet());
  73. });
  74. qunit.test("{ mask: [\"99-99999-9\",\"99-999999-9\"] } - type 121234561", function(assert) {
  75. var $fixture = $("#qunit-fixture");
  76. $fixture.append('<input type="text" id="testmask" />');
  77. var testmask = document.getElementById("testmask");
  78. Inputmask({
  79. mask: ["99-99999-9", "99-999999-9"]
  80. }).mask(testmask);
  81. $("#testmask").Type("121234561");
  82. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12-123456-1", "Result " + document.getElementById("testmask").inputmask._valueGet());
  83. });
  84. qunit.test("{ \"keepStatic\": true, greedy: false, mask: \"(99-9)|(99999)\" } - type 12345", function(assert) {
  85. var $fixture = $("#qunit-fixture");
  86. $fixture.append('<input type="text" id="testmask" />');
  87. var testmask = document.getElementById("testmask");
  88. Inputmask({
  89. "keepStatic": true,
  90. greedy: false,
  91. "mask": "(99-9)|(99999)"
  92. }).mask(testmask);
  93. $("#testmask").Type("12345");
  94. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12345", "Result " + document.getElementById("testmask").inputmask._valueGet());
  95. });
  96. qunit.test("7|8 999 99 99 - hiddenman", function(assert) {
  97. var $fixture = $("#qunit-fixture");
  98. $fixture.append('<input type="text" id="testmask" />');
  99. var testmask = document.getElementById("testmask");
  100. Inputmask("7|8 999 99 99").mask(testmask);
  101. testmask.focus();
  102. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "_ ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
  103. });
  104. qunit.test("7|8 999 99 99 type 7 - hiddenman", function(assert) {
  105. var $fixture = $("#qunit-fixture");
  106. $fixture.append('<input type="text" id="testmask" />');
  107. var testmask = document.getElementById("testmask");
  108. Inputmask("7|8 999 99 99").mask(testmask);
  109. $("#testmask").Type("7");
  110. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "7 ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
  111. });
  112. qunit.test("7|8 999 99 99 type 8 - hiddenman", function(assert) {
  113. var $fixture = $("#qunit-fixture");
  114. $fixture.append('<input type="text" id="testmask" />');
  115. var testmask = document.getElementById("testmask");
  116. Inputmask("7|8 999 99 99").mask(testmask);
  117. $("#testmask").Type("8");
  118. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "8 ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
  119. });
  120. qunit.test("(78)|(79) 999 99 99", function(assert) {
  121. var $fixture = $("#qunit-fixture");
  122. $fixture.append('<input type="text" id="testmask" />');
  123. var testmask = document.getElementById("testmask");
  124. Inputmask("(78)|(79) 999 99 99").mask(testmask);
  125. testmask.focus();
  126. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "7_ ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
  127. });
  128. qunit.test("(78)|(79) 999 99 99 - type 5", function(assert) {
  129. var $fixture = $("#qunit-fixture");
  130. $fixture.append('<input type="text" id="testmask" />');
  131. var testmask = document.getElementById("testmask");
  132. Inputmask("(78)|(79) 999 99 99").mask(testmask);
  133. testmask.focus();
  134. $("#testmask").Type("5");
  135. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "75 ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
  136. });
  137. qunit.test("(78)|(74) 999 99 99", function(assert) {
  138. var $fixture = $("#qunit-fixture");
  139. $fixture.append('<input type="text" id="testmask" />');
  140. var testmask = document.getElementById("testmask");
  141. Inputmask("(78)|(74) 999 99 99").mask(testmask);
  142. testmask.focus();
  143. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "7_ ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
  144. });
  145. qunit.test("5-9|(9a)-5 - keepstatic: false", function(assert) {
  146. var $fixture = $("#qunit-fixture");
  147. $fixture.append('<input type="text" id="testmask" />');
  148. var testmask = document.getElementById("testmask");
  149. Inputmask({
  150. mask: "5-9|(9a)-5",
  151. keepStatic: false
  152. }).mask(testmask);
  153. testmask.focus();
  154. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "5-_-5", "Result " + document.getElementById("testmask").inputmask._valueGet());
  155. });
  156. qunit.test("['(99) 9999-9999', '(99) 9-9999-9999'] - type 12123412345 - 3m0", function(assert) {
  157. var $fixture = $("#qunit-fixture");
  158. $fixture.append('<input type="text" id="testmask" />');
  159. var testmask = document.getElementById("testmask");
  160. Inputmask({
  161. mask: ['(99) 9999-9999', '(99) 9-9999-9999'],
  162. removeMaskOnSubmit: false,
  163. clearmaskonlostfocus: true
  164. }).mask(testmask);
  165. testmask.focus();
  166. $("#testmask").Type("12123412345")
  167. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "(12) 1-2341-2345", "Result " + document.getElementById("testmask").inputmask._valueGet());
  168. });
  169. qunit.test("['(99) 9999-9999', '(99) 9-9999-9999'] - type 12123412345 - backspace - 3m0", function(assert) {
  170. var $fixture = $("#qunit-fixture");
  171. $fixture.append('<input type="text" id="testmask" />');
  172. var testmask = document.getElementById("testmask");
  173. Inputmask({
  174. mask: ['(99) 9999-9999', '(99) 9-9999-9999'],
  175. removeMaskOnSubmit: false,
  176. clearmaskonlostfocus: true
  177. }).mask(testmask);
  178. testmask.focus();
  179. $("#testmask").Type("12123412345")
  180. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  181. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "(12) 1234-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
  182. });
  183. qunit.test("(99 99)|(*****) keepStatic false - type 12 abc", function(assert) {
  184. var $fixture = $("#qunit-fixture");
  185. $fixture.append('<input type="text" id="testmask" />');
  186. var testmask = document.getElementById("testmask");
  187. Inputmask("(99 99)|(*****)", {
  188. keepStatic: false
  189. }).mask(testmask);
  190. $("#testmask").Type("12 abc");
  191. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12 __", "Result " + document.getElementById("testmask").inputmask._valueGet());
  192. });
  193. qunit.test("(99 99)|(*****) keepStatic false - type 12 123", function(assert) {
  194. var $fixture = $("#qunit-fixture");
  195. $fixture.append('<input type="text" id="testmask" />');
  196. var testmask = document.getElementById("testmask");
  197. Inputmask("(99 99)|(*****)", {
  198. keepStatic: false
  199. }).mask(testmask);
  200. $("#testmask").Type("12 123");
  201. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12 12", "Result " + document.getElementById("testmask").inputmask._valueGet());
  202. });
  203. qunit.test("(99 99)|(*****) keepStatic true - type 1212", function(assert) {
  204. var $fixture = $("#qunit-fixture");
  205. $fixture.append('<input type="text" id="testmask" />');
  206. var testmask = document.getElementById("testmask");
  207. Inputmask("(99 99)|(*****)", {
  208. keepStatic: true
  209. }).mask(testmask);
  210. $("#testmask").Type("1212");
  211. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12 12", "Result " + document.getElementById("testmask").inputmask._valueGet());
  212. });
  213. qunit.test("(99 99)|(*****) keepStatic true - type 12123", function(assert) {
  214. var $fixture = $("#qunit-fixture");
  215. $fixture.append('<input type="text" id="testmask" />');
  216. var testmask = document.getElementById("testmask");
  217. Inputmask("(99 99)|(*****)", {
  218. keepStatic: true
  219. }).mask(testmask);
  220. $("#testmask").Type("12123");
  221. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12123", "Result " + document.getElementById("testmask").inputmask._valueGet());
  222. });
  223. qunit.test("(99 99)|(*****) keepStatic true - type abcde", function(assert) {
  224. var $fixture = $("#qunit-fixture");
  225. $fixture.append('<input type="text" id="testmask" />');
  226. var testmask = document.getElementById("testmask");
  227. Inputmask("(99 99)|(*****)", {
  228. keepStatic: true
  229. }).mask(testmask);
  230. $("#testmask").Type("abcde");
  231. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "abcde", "Result " + document.getElementById("testmask").inputmask._valueGet());
  232. });
  233. qunit.test("[\"9+9\", \"(99)+99+99\"] keepStatic true - type 123 - ishytow", function(assert) {
  234. var $fixture = $("#qunit-fixture");
  235. $fixture.append('<input type="text" id="testmask" />');
  236. var testmask = document.getElementById("testmask");
  237. Inputmask(["9+9", "(99)+99+99"], {
  238. keepStatic: true
  239. }).mask(testmask);
  240. $("#testmask").Type("123");
  241. assert.equal(testmask.value, "(12)+3_+__", "Result " + testmask.value);
  242. });
  243. qunit.test("[\"9+9\", \"99+99\", \"(99)+99+99\"] keepStatic true - type 12345 - ishytow", function(assert) {
  244. var $fixture = $("#qunit-fixture");
  245. $fixture.append('<input type="text" id="testmask" />');
  246. var testmask = document.getElementById("testmask");
  247. Inputmask(["9+9", "99+99", "(99)+99+99"], {
  248. keepStatic: true
  249. }).mask(testmask);
  250. $("#testmask").Type("12345");
  251. assert.equal(testmask.value, "(12)+34+5_", "Result " + testmask.value);
  252. });
  253. qunit.test("[\"9+9\", \"99+99\", \"(99)+99+99\"] keepStatic true - type 1234 - ishytow", function(assert) {
  254. var $fixture = $("#qunit-fixture");
  255. $fixture.append('<input type="text" id="testmask" />');
  256. var testmask = document.getElementById("testmask");
  257. Inputmask(["9+9", "99+99", "(99)+99+99"], {
  258. keepStatic: true
  259. }).mask(testmask);
  260. $("#testmask").Type("1234");
  261. assert.equal(testmask.value, "12+34", "Result " + testmask.value);
  262. });
  263. qunit.test("[\"999-9999\", \"(999) 999-9999\", \"1-(999) 999-9999\"] - 999-9999 - carylewis", function(assert) {
  264. var $fixture = $("#qunit-fixture");
  265. $fixture.append('<input type="text" id="testmask" />');
  266. var testmask = document.getElementById("testmask");
  267. Inputmask(["999-9999", "(999) 999-9999", "1-(999) 999-9999"]).mask(testmask);
  268. $("#testmask").Type("1231234");
  269. assert.equal(testmask.value, "123-1234", "Result " + testmask.value);
  270. });
  271. qunit.test("[\"999-9999\", \"(999) 999-9999\", \"1-(999) 999-9999\"] - (999) 999-9999 - carylewis", function(assert) {
  272. var $fixture = $("#qunit-fixture");
  273. $fixture.append('<input type="text" id="testmask" />');
  274. var testmask = document.getElementById("testmask");
  275. Inputmask(["999-9999", "(999) 999-9999", "1-(999) 999-9999"]).mask(testmask);
  276. $("#testmask").Type("1231231234");
  277. assert.equal(testmask.value, "(123) 123-1234", "Result " + testmask.value);
  278. });
  279. qunit.test("[\"999-9999\", \"(999) 999-9999\", \"1-(999) 999-9999\"] - 1-(999) 999-9999 - carylewis", function(assert) {
  280. var $fixture = $("#qunit-fixture");
  281. $fixture.append('<input type="text" id="testmask" />');
  282. var testmask = document.getElementById("testmask");
  283. Inputmask(["999-9999", "(999) 999-9999", "1-(999) 999-9999"]).mask(testmask);
  284. $("#testmask").Type("11231231234");
  285. assert.equal(testmask.value, "1-(123) 123-1234", "Result " + testmask.value);
  286. });
  287. };