tests_optional.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. export default function (qunit, $, Inputmask) {
  2. qunit.module("Optional");
  3. qunit.test("inputmask(\"(99) 9999[9]-99999\") - input 121234-12345", function (assert) {
  4. var $fixture = $("#qunit-fixture");
  5. $fixture.append('<input type="text" id="testmask" />');
  6. var testmask = document.getElementById("testmask");
  7. Inputmask("(99) 9999[9]-99999").mask(testmask);
  8. testmask.focus();
  9. $("#testmask").Type("121234-12345");
  10. assert.equal(testmask.value, "(12) 1234-12345", "Result " + testmask.value);
  11. });
  12. qunit.test("inputmask(\"(99) 9999[9]-99999\") - input 121234512345", function (assert) {
  13. var $fixture = $("#qunit-fixture");
  14. $fixture.append('<input type="text" id="testmask" />');
  15. var testmask = document.getElementById("testmask");
  16. Inputmask("(99) 9999[9]-99999").mask(testmask);
  17. testmask.focus();
  18. $("#testmask").Type("121234512345");
  19. assert.equal(testmask.value, "(12) 12345-12345", "Result " + testmask.value);
  20. });
  21. qunit.test("inputmask({ mask: \"99999[-9999]\", greedy: true }) - input 123", function (assert) {
  22. var $fixture = $("#qunit-fixture");
  23. $fixture.append('<input type="text" id="testmask" />');
  24. var testmask = document.getElementById("testmask");
  25. Inputmask({
  26. mask: "99999[-9999]",
  27. greedy: true
  28. }).mask(testmask);
  29. testmask.focus();
  30. $("#testmask").Type("123");
  31. assert.equal(testmask.value, "123__", "Result " + testmask.value);
  32. });
  33. qunit.test("inputmask({ mask: \"99999[-9999]\", greedy: false }) - input 123", function (assert) {
  34. var $fixture = $("#qunit-fixture");
  35. $fixture.append('<input type="text" id="testmask" />');
  36. var testmask = document.getElementById("testmask");
  37. Inputmask({
  38. mask: "99999[-9999]",
  39. greedy: false
  40. }).mask(testmask);
  41. testmask.focus();
  42. $("#testmask").Type("123");
  43. assert.equal(testmask.value, "123__", "Result " + testmask.value);
  44. });
  45. qunit.test("inputmask({ mask: \"99999[-9999]\", greedy: false }) - input 12345", function (assert) {
  46. var $fixture = $("#qunit-fixture");
  47. $fixture.append('<input type="text" id="testmask" />');
  48. var testmask = document.getElementById("testmask");
  49. Inputmask({
  50. mask: "99999[-9999]",
  51. greedy: false
  52. }).mask(testmask);
  53. testmask.focus();
  54. $("#testmask").Type("12345");
  55. assert.equal(testmask.value, "12345", "Result " + testmask.value);
  56. });
  57. qunit.test("inputmask({ mask: \"99999[-9999]\", greedy: false }) - input 123456", function (assert) {
  58. var $fixture = $("#qunit-fixture");
  59. $fixture.append('<input type="text" id="testmask" />');
  60. var testmask = document.getElementById("testmask");
  61. Inputmask({
  62. mask: "99999[-9999]",
  63. greedy: false
  64. }).mask(testmask);
  65. testmask.focus();
  66. $("#testmask").Type("123456");
  67. assert.equal(testmask.value, "12345-6", "Result " + testmask.value);
  68. });
  69. qunit.test("inputmask({ mask: \"99999[-9999]\", greedy: false }) - input 123456789", function (assert) {
  70. var $fixture = $("#qunit-fixture");
  71. $fixture.append('<input type="text" id="testmask" />');
  72. var testmask = document.getElementById("testmask");
  73. Inputmask({
  74. mask: "99999[-9999]",
  75. greedy: false
  76. }).mask(testmask);
  77. testmask.focus();
  78. $("#testmask").Type("123456789");
  79. assert.equal(testmask.value, "12345-6789", "Result " + testmask.value);
  80. });
  81. qunit.test("inputmask(\"9[9][9] 999[9] 9999\") - input 123123 space 1234 - vipink70", function (assert) {
  82. var $fixture = $("#qunit-fixture");
  83. $fixture.append('<input type="text" id="testmask" />');
  84. var testmask = document.getElementById("testmask");
  85. Inputmask("9[9][9] 999[9] 9999").mask(testmask);
  86. testmask.focus();
  87. $("#testmask").Type("123123");
  88. $("#testmask").SendKey(Inputmask.keyCode.SPACE);
  89. $("#testmask").Type("1234");
  90. assert.equal(testmask.value, "123 123 1234", "Result " + testmask.value);
  91. });
  92. qunit.test("inputmask('[9-]AAA.999') ", function (assert) {
  93. var $fixture = $("#qunit-fixture");
  94. $fixture.append('<input type="text" id="testmask" />');
  95. var testmask = document.getElementById("testmask");
  96. Inputmask('[9-]AAA.999').mask(testmask);
  97. $("#testmask").Type("1abc123");
  98. $.caret(testmask, 4, 5);
  99. $("#testmask").Type("d");
  100. assert.equal(testmask.value, "1-ABD.123", "Result " + testmask.value);
  101. });
  102. qunit.test("inputmask('9[9]:99') ", function (assert) {
  103. var $fixture = $("#qunit-fixture");
  104. $fixture.append('<input type="text" id="testmask" />');
  105. var testmask = document.getElementById("testmask");
  106. Inputmask('9[9]:99').mask(testmask);
  107. $("#testmask").Type("3:44");
  108. $.caret(testmask, 1);
  109. $("#testmask").Type("3");
  110. assert.equal(testmask.value, "33:44", "Result " + testmask.value);
  111. });
  112. qunit.test("inputmask({ mask: \"99999[-9999]\", greedy: false }) - input 123456", function (assert) {
  113. var $fixture = $("#qunit-fixture");
  114. $fixture.append('<input type="text" id="testmask" />');
  115. var testmask = document.getElementById("testmask");
  116. Inputmask({
  117. mask: "99999[-9999]",
  118. greedy: false
  119. }).mask(testmask);
  120. testmask.focus();
  121. $("#testmask").Type("123456");
  122. testmask.blur();
  123. $("#testmask").trigger("mouseenter");
  124. assert.equal(testmask.value, "12345-6___", "Result " + testmask.value);
  125. });
  126. qunit.test("inputmask({ mask: \"9'9{1,2}\"\", greedy: false, skipOptionalPartCharacter: \"\", \"clearIncomplete\": true }) - input 12 blur - thomstark", function (assert) {
  127. var $fixture = $("#qunit-fixture");
  128. $fixture.append('<input type="text" id="testmask" />');
  129. var testmask = document.getElementById("testmask");
  130. Inputmask({
  131. mask: "9'9{1,2}\"",
  132. greedy: false,
  133. skipOptionalPartCharacter: "",
  134. "clearIncomplete": true
  135. }).mask(testmask);
  136. testmask.focus();
  137. $("#testmask").Type("12");
  138. testmask.blur();
  139. assert.equal(testmask.value, "1'2\"", "Result " + testmask.value);
  140. });
  141. qunit.test("inputmask({ mask: \"99{1,2}lb\\s\", greedy: false, skipOptionalPartCharacter: \"\", \"clearIncomplete\": true }) - input 12 blur - thomstark", function (assert) {
  142. var $fixture = $("#qunit-fixture");
  143. $fixture.append('<input type="text" id="testmask" />');
  144. var testmask = document.getElementById("testmask");
  145. Inputmask({
  146. mask: "99{1,2}lb\\s",
  147. greedy: false,
  148. skipOptionalPartCharacter: "",
  149. "clearIncomplete": true
  150. }).mask(testmask);
  151. testmask.focus();
  152. $("#testmask").Type("12");
  153. testmask.blur();
  154. assert.equal(testmask.value, "12lbs", "Result " + testmask.value);
  155. });
  156. qunit.test("inputmask({ mask: \"9'9[9]\"\", greedy: false, skipOptionalPartCharacter: \"\", \"clearIncomplete\": true }) - input 12 blur - thomstark", 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: "9'9[9]\"",
  162. greedy: false,
  163. skipOptionalPartCharacter: "",
  164. "clearIncomplete": true
  165. }).mask(testmask);
  166. testmask.focus();
  167. $("#testmask").Type("12");
  168. testmask.blur();
  169. assert.equal(testmask.value, "1'2\"", "Result " + testmask.value);
  170. });
  171. qunit.test("inputmask({ mask: \"99[9]lb\\s\", greedy: false, skipOptionalPartCharacter: \"\", \"clearIncomplete\": true }) - input 12 blur - thomstark", function (assert) {
  172. var $fixture = $("#qunit-fixture");
  173. $fixture.append('<input type="text" id="testmask" />');
  174. var testmask = document.getElementById("testmask");
  175. Inputmask({
  176. mask: "99[9]lb\\s",
  177. greedy: false,
  178. skipOptionalPartCharacter: "",
  179. "clearIncomplete": true
  180. }).mask(testmask);
  181. testmask.focus();
  182. $("#testmask").Type("12");
  183. testmask.blur();
  184. assert.equal(testmask.value, "12lbs", "Result " + testmask.value);
  185. });
  186. qunit.test(".inputmask(\"99999[-9999]\", { greedy: false }); - type 123456 backspace iscomplete?", function (assert) {
  187. var $fixture = $("#qunit-fixture");
  188. $fixture.append('<input type="text" id="testmask" />');
  189. var testmask = document.getElementById("testmask");
  190. Inputmask("99999[-9999]", {
  191. greedy: false
  192. }).mask(testmask);
  193. testmask.focus();
  194. $("#testmask").Type("123456");
  195. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  196. assert.equal(testmask.inputmask.isComplete(), true, "Result " + testmask.inputmask.isComplete());
  197. });
  198. qunit.test(".inputmask(\"99999[-9999]\", { greedy: false }); type 123456 backspace blur", function (assert) {
  199. var $fixture = $("#qunit-fixture"), done = assert.async();
  200. $fixture.append('<input type="text" id="testmask" />');
  201. var testmask = document.getElementById("testmask");
  202. Inputmask("99999[-9999]", {
  203. greedy: false
  204. }).mask(testmask);
  205. testmask.focus();
  206. $("#testmask").Type("123456");
  207. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  208. testmask.blur();
  209. setTimeout(function () {
  210. assert.equal($("#testmask")[0].inputmask._valueGet(), "12345", "Result " + $("#testmask")[0].inputmask._valueGet());
  211. done();
  212. }, 0);
  213. });
  214. qunit.test(".inputmask(\"99999[-9999]\", { greedy: false, autoUnmask: true }); type 123456 backspace", function (assert) {
  215. var $fixture = $("#qunit-fixture"), done = assert.async();
  216. $fixture.append('<input type="text" id="testmask" />');
  217. var testmask = document.getElementById("testmask");
  218. Inputmask("99999[-9999]", {
  219. greedy: false,
  220. autoUnmask: true
  221. }).mask(testmask);
  222. testmask.focus();
  223. $("#testmask").Type("123456");
  224. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  225. setTimeout(function () {
  226. assert.equal(testmask.value, "12345", "Result " + testmask.value);
  227. done();
  228. }, 0);
  229. });
  230. qunit.test(".inputmask('999-999-9999[ ext 9{1,5}]'); - type 12345678901 backspace iscomplete? - antch", function (assert) {
  231. var $fixture = $("#qunit-fixture");
  232. $fixture.append('<input type="text" id="testmask" />');
  233. var testmask = document.getElementById("testmask");
  234. Inputmask('999-999-9999[ ext 9{1,5}]').mask(testmask);
  235. testmask.focus();
  236. $("#testmask").Type("12345678901");
  237. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  238. assert.equal(testmask.inputmask.isComplete(), true, "Result " + testmask.inputmask.isComplete());
  239. });
  240. qunit.test("inputmask({ mask: \"9999[ 9999][ 9999]\"}) - input 1234 space space - GMTA", function (assert) {
  241. var $fixture = $("#qunit-fixture");
  242. $fixture.append('<input type="text" id="testmask" />');
  243. var testmask = document.getElementById("testmask");
  244. Inputmask({
  245. mask: "9999[ 9999][ 9999]"
  246. }).mask(testmask);
  247. testmask.focus();
  248. $("#testmask").Type("1234 ");
  249. assert.equal(testmask.value, "1234", "Result " + testmask.value);
  250. });
  251. qunit.test("9999[ 9999][ 9999][ 9999][ 999] - Enfree", function (assert) {
  252. var $fixture = $("#qunit-fixture");
  253. $fixture.append('<input type="text" id="testmask" />');
  254. var testmask = document.getElementById("testmask");
  255. Inputmask({
  256. mask: '9999[ 9999][ 9999][ 9999][ 999]',
  257. placeholder: '', greedy: false
  258. }).mask(testmask);
  259. testmask.focus();
  260. $("#testmask").Type("45464748");
  261. $.caret(testmask, 2);
  262. $("#testmask").Type("0909");
  263. assert.equal(testmask.value, "4509 0946 4748", "Result " + testmask.value);
  264. });
  265. };