tests_dynamic.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. export default function (qunit, $, Inputmask) {
  2. qunit.module("Dynamic Masks");
  3. qunit.test("inputmask(\"9-a{3}9{3}\" - simple dynamic mask", function (assert) {
  4. var $fixture = $("#qunit-fixture");
  5. $fixture.append('<input type="text" id="testmask" />');
  6. var testmask = document.getElementById("testmask");
  7. Inputmask("9-a{3}9{3}").mask(testmask);
  8. testmask.focus();
  9. $("#testmask").Type("1abc123");
  10. assert.equal(testmask.value, "1-abc123", "Result " + testmask.value);
  11. });
  12. qunit.test("inputmask(\"9-a{1,3}9{1,3}\" - simple dynamic mask", function (assert) {
  13. var $fixture = $("#qunit-fixture");
  14. $fixture.append('<input type="text" id="testmask" />');
  15. var testmask = document.getElementById("testmask");
  16. Inputmask("9-a{1,3}9{1,3}").mask(testmask);
  17. testmask.focus();
  18. $("#testmask").Type("1a1");
  19. assert.equal(testmask.value, "1-a1", "Result " + testmask.value);
  20. });
  21. qunit.test("inputmask(\"9-a{1,3}9{1,3}\" - simple dynamic mask - greedy false", function (assert) {
  22. var $fixture = $("#qunit-fixture");
  23. $fixture.append('<input type="text" id="testmask" />');
  24. var testmask = document.getElementById("testmask");
  25. Inputmask("9-a{1,3}9{1,3}", {
  26. greedy: false
  27. }).mask(testmask);
  28. testmask.focus();
  29. $("#testmask").Type("1a1");
  30. assert.equal(testmask.value, "1-a1", "Result " + testmask.value);
  31. });
  32. qunit.test("inputmask(\"9-a{1,3}/9{2,3}\" - simple dynamic mask - greedy true", function (assert) {
  33. var $fixture = $("#qunit-fixture");
  34. $fixture.append('<input type="text" id="testmask" />');
  35. var testmask = document.getElementById("testmask");
  36. Inputmask("9-a{1,3}/9{2,3}", {
  37. greedy: true
  38. }).mask(testmask);
  39. testmask.focus();
  40. $("#testmask").Type("1a/123");
  41. assert.equal(testmask.value, "1-a/123", "Result " + testmask.value);
  42. });
  43. qunit.test("email mask greedy false", function (assert) {
  44. var $fixture = $("#qunit-fixture");
  45. $fixture.append('<input type="text" id="testmask" />');
  46. var testmask = document.getElementById("testmask");
  47. Inputmask("email", {
  48. greedy: false
  49. }).mask(testmask);
  50. testmask.focus();
  51. $("#testmask").Type("some.body@mail.com");
  52. testmask.blur();
  53. assert.equal(testmask.value, "some.body@mail.com", "Result " + testmask.value);
  54. });
  55. qunit.test("email mask greedy true", function (assert) {
  56. var done = assert.async(),
  57. $fixture = $("#qunit-fixture");
  58. $fixture.append('<input type="text" id="testmask" />');
  59. var testmask = document.getElementById("testmask");
  60. Inputmask("email", {
  61. greedy: true
  62. }).mask(testmask);
  63. testmask.focus();
  64. $("#testmask").Type("some.body@mail.com");
  65. testmask.blur();
  66. setTimeout(function () {
  67. assert.equal(testmask.value, "some.body@mail.com", "Result " + testmask.value);
  68. done();
  69. }, 0);
  70. });
  71. qunit.test("email mask - partial input", function (assert) {
  72. var $fixture = $("#qunit-fixture");
  73. $fixture.append('<input type="text" id="testmask" />');
  74. var testmask = document.getElementById("testmask");
  75. Inputmask("email").mask(testmask);
  76. testmask.focus();
  77. $("#testmask").Type("some.");
  78. testmask.blur();
  79. assert.equal(testmask.value, "some.@_._", "Result " + testmask.value);
  80. });
  81. qunit.test("email mask - partial input 2", function (assert) {
  82. var $fixture = $("#qunit-fixture");
  83. $fixture.append('<input type="text" id="testmask" />');
  84. var testmask = document.getElementById("testmask");
  85. Inputmask("email").mask(testmask);
  86. testmask.focus();
  87. $("#testmask").Type("some@mail.com");
  88. $.caret(testmask, 4);
  89. $("#testmask").Type(".body");
  90. assert.equal(testmask.value, "some.body@mail.com", "Result " + testmask.value);
  91. });
  92. qunit.test("email mask - babu@us.lufthansa.com - babupca", function (assert) {
  93. var $fixture = $("#qunit-fixture");
  94. $fixture.append('<input type="text" id="testmask" />');
  95. var testmask = document.getElementById("testmask");
  96. Inputmask("email").mask(testmask);
  97. testmask.focus();
  98. $("#testmask").Type("babu@us.lufthansa.com");
  99. assert.equal(testmask.value, "babu@us.lufthansa.com", "Result " + testmask.value);
  100. });
  101. qunit.test("email mask - email@subdomain.domain.com - babupca", function (assert) {
  102. var $fixture = $("#qunit-fixture");
  103. $fixture.append('<input type="text" id="testmask" />');
  104. var testmask = document.getElementById("testmask");
  105. Inputmask("email").mask(testmask);
  106. testmask.focus();
  107. $("#testmask").Type("email@subdomain.domain.com");
  108. assert.equal(testmask.value, "email@subdomain.domain.com", "Result " + testmask.value);
  109. });
  110. qunit.test("email mask - paste test.test@test.com - Kurumas", function (assert) {
  111. var done = assert.async(),
  112. $fixture = $("#qunit-fixture");
  113. $fixture.append('<input type="text" id="testmask" />');
  114. var testmask = document.getElementById("testmask");
  115. Inputmask("email").mask(testmask);
  116. testmask.focus();
  117. $("#testmask").paste("test.test@test.com");
  118. setTimeout(function () {
  119. assert.equal(testmask.value, "test.test@test.com", "Result " + testmask.value);
  120. done();
  121. }, 0);
  122. });
  123. qunit.test("quantifier mask greedy false - FairSite2C", function (assert) {
  124. var $fixture = $("#qunit-fixture");
  125. $fixture.append('<input type="text" id="testmask" />');
  126. var testmask = document.getElementById("testmask");
  127. Inputmask("9{0,4}", {
  128. greedy: false
  129. }).mask(testmask);
  130. testmask.focus();
  131. $("#testmask").Type("123");
  132. assert.equal(testmask.value, "123", "Result " + testmask.value);
  133. });
  134. qunit.test("quantifier mask greedy true - FairSite2C", function (assert) {
  135. var $fixture = $("#qunit-fixture");
  136. $fixture.append('<input type="text" id="testmask" />');
  137. var testmask = document.getElementById("testmask");
  138. Inputmask("9{0,4}", {
  139. greedy: true
  140. }).mask(testmask);
  141. testmask.focus();
  142. $("#testmask").Type("123");
  143. assert.equal(testmask.value, "123", "Result " + testmask.value);
  144. });
  145. qunit.test("email mask - clearIncomplete - hiddenman", function (assert) {
  146. var done = assert.async(),
  147. $fixture = $("#qunit-fixture");
  148. $fixture.append('<input type="text" id="testmask" />');
  149. var testmask = document.getElementById("testmask");
  150. Inputmask("email", {
  151. clearIncomplete: true
  152. }).mask(testmask);
  153. testmask.focus();
  154. $("#testmask").Type("akornilov");
  155. testmask.blur();
  156. setTimeout(function () {
  157. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "", "Result " + document.getElementById("testmask").inputmask._valueGet());
  158. done();
  159. }, 0);
  160. });
  161. qunit.test("email mask - clearIncomplete - hiddenman", function (assert) {
  162. var done = assert.async(),
  163. $fixture = $("#qunit-fixture");
  164. $fixture.append('<input type="text" id="testmask" />');
  165. var testmask = document.getElementById("testmask");
  166. Inputmask("email", {
  167. clearIncomplete: true
  168. }).mask(testmask);
  169. testmask.focus();
  170. $("#testmask").Type("akornilov@");
  171. testmask.blur();
  172. setTimeout(function () {
  173. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "", "Result " + document.getElementById("testmask").inputmask._valueGet());
  174. done();
  175. }, 0);
  176. });
  177. qunit.test("email mask - clearIncomplete - hiddenman", function (assert) {
  178. var done = assert.async(),
  179. $fixture = $("#qunit-fixture");
  180. $fixture.append('<input type="text" id="testmask" />');
  181. var testmask = document.getElementById("testmask");
  182. Inputmask("email", {
  183. clearIncomplete: true
  184. }).mask(testmask);
  185. testmask.focus();
  186. $("#testmask").Type("akornilov@gmail.com");
  187. testmask.blur();
  188. setTimeout(function () {
  189. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "akornilov@gmail.com", "Result " + document.getElementById("testmask").inputmask._valueGet());
  190. done();
  191. }, 0);
  192. });
  193. qunit.test("mask: '\\\\a{*}', repeat: 5 - voidmain02", function (assert) {
  194. var $fixture = $("#qunit-fixture");
  195. $fixture.append('<input type="text" id="testmask" />');
  196. var testmask = document.getElementById("testmask");
  197. Inputmask({
  198. mask: '\\\\a{*}',
  199. repeat: 5
  200. }).mask(testmask);
  201. testmask.focus();
  202. $("#testmask").Type("abcd abcd abcd abcd abcd");
  203. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "\\abcd\\abcd\\abcd\\abcd\\abcd", "Result " + document.getElementById("testmask").inputmask._valueGet());
  204. });
  205. qunit.test("[a{1,3}-]9999 - type abc1234 => delete c - ivodopyanov", function (assert) {
  206. var $fixture = $("#qunit-fixture");
  207. $fixture.append('<input type="text" id="testmask" />');
  208. var testmask = document.getElementById("testmask");
  209. Inputmask("[a{1,3}-]9999").mask(testmask);
  210. $("#testmask").Type("abc1234");
  211. $.caret(testmask, 2);
  212. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  213. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "ab-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
  214. });
  215. qunit.test("email mask - mouseclick to domain part - hiddenman", function (assert) {
  216. var done = assert.async(),
  217. $fixture = $("#qunit-fixture");
  218. $fixture.append('<input type="text" id="testmask" />');
  219. var testmask = document.getElementById("testmask");
  220. Inputmask("email").mask(testmask);
  221. testmask.focus();
  222. $("#testmask").Type("akornilov");
  223. //fake click in position
  224. $.caret(testmask, 10);
  225. $("#testmask").trigger("click");
  226. $("#testmask").Type("gmail.com");
  227. setTimeout(function () {
  228. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "akornilov@gmail.com", "Result " + document.getElementById("testmask").inputmask._valueGet());
  229. done();
  230. }, 0);
  231. });
  232. qunit.test("I{1,3}-ZZ - rgafaric", function (assert) {
  233. var done = assert.async(),
  234. $fixture = $("#qunit-fixture");
  235. $fixture.append('<input type="text" id="testmask" value="VAA" />');
  236. var testmask = document.getElementById("testmask");
  237. Inputmask({
  238. "mask": "I{1,3}-ZZ",
  239. definitions: {
  240. 'Z': {
  241. "validator": "[A-Za-z]",
  242. cardinality: 1
  243. },
  244. 'I': {
  245. "validator": "[ivxlcdmIVXLCDM]",
  246. cardinality: 1
  247. }
  248. }
  249. }).mask(testmask);
  250. testmask.blur();
  251. setTimeout(function () {
  252. assert.equal(document.getElementById("testmask").inputmask._valueGet(), "V-AA", "Result " + document.getElementById("testmask").inputmask._valueGet());
  253. done();
  254. }, 0);
  255. });
  256. qunit.test("email mask - some.body@mail.com - delete before @", function (assert) {
  257. var $fixture = $("#qunit-fixture");
  258. $fixture.append('<input type="text" id="testmask" />');
  259. var testmask = document.getElementById("testmask");
  260. Inputmask("email").mask(testmask);
  261. testmask.focus();
  262. $("#testmask").Type("some.body@mail.com");
  263. $.caret(testmask, 9);
  264. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  265. assert.equal(testmask.value, "some.body@ail.com", "Result " + testmask.value);
  266. });
  267. qunit.test("email mask -123@mail.com - 123 => info", function (assert) {
  268. var $fixture = $("#qunit-fixture");
  269. $fixture.append('<input type="text" id="testmask" />');
  270. var testmask = document.getElementById("testmask");
  271. Inputmask("email").mask(testmask);
  272. testmask.focus();
  273. $("#testmask").Type("123@mail.com");
  274. $.caret(testmask, 0, 3);
  275. $("#testmask").Type("info");
  276. assert.equal(testmask.value, "info@mail.com", "Result " + testmask.value);
  277. });
  278. qunit.test("(aa)|(a.a.)|(aaa)|(aa.a.)|(a.aa.) - incomplete - danielpiterak", function (assert) {
  279. var $fixture = $("#qunit-fixture");
  280. $fixture.append('<input type="text" id="testmask" />');
  281. var testmask = document.getElementById("testmask");
  282. Inputmask("(aa)|(a.a.)|(aaa)|(aa.a.)|(a.aa.)", {
  283. clearMaskOnLostFocus: true,
  284. showMaskOnHover: false,
  285. placeholder: " ",
  286. casing: "upper"
  287. }).mask(testmask);
  288. testmask.focus();
  289. $("#testmask").Type("p.p");
  290. testmask.blur();
  291. assert.equal(testmask.value, "P.P.", "Result " + testmask.value);
  292. });
  293. qunit.test("(aa)|(a.a.)|(aaa)|(aa.a.)|(a.aa.) - complete - danielpiterak", function (assert) {
  294. var $fixture = $("#qunit-fixture");
  295. $fixture.append('<input type="text" id="testmask" />');
  296. var testmask = document.getElementById("testmask");
  297. Inputmask("(aa)|(a.a.)|(aaa)|(aa.a.)|(a.aa.)", {
  298. clearMaskOnLostFocus: true,
  299. showMaskOnHover: false,
  300. placeholder: " ",
  301. casing: "upper"
  302. }).mask(testmask);
  303. testmask.focus();
  304. $("#testmask").Type("p.p.");
  305. testmask.blur();
  306. assert.equal(testmask.value, "P.P.", "Result " + testmask.value);
  307. });
  308. };