tests_inputeventonly.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. export default function (qunit, $, Inputmask) {
  2. qunit.module("inputEventOnly: true");
  3. qunit.test("XXX-9999-9999-XXX-XXX - gersteba", function (assert) {
  4. var $fixture = $("#qunit-fixture");
  5. $fixture.append('<input type="text" id="testmask" />');
  6. var testmask = document.getElementById("testmask");
  7. Inputmask({
  8. inputEventOnly: true,
  9. mask: "XXX-9999-9999-XXX-XXX",
  10. definitions: {
  11. "X": {
  12. validator: "[A-Ha-hJ-Nj-nPpR-Zr-z2-9]",
  13. cardinality: 1,
  14. casing: "upper"
  15. }
  16. }
  17. }).mask(testmask);
  18. testmask.focus();
  19. //simulate input
  20. $(testmask).input("abc12341234abcabc");
  21. assert.equal(testmask.value, "ABC-1234-1234-ABC-ABC", "Result " + testmask.value);
  22. });
  23. qunit.test("(999) 999-9999", function (assert) {
  24. var $fixture = $("#qunit-fixture");
  25. $fixture.append('<input type="text" id="testmask" />');
  26. var testmask = document.getElementById("testmask");
  27. Inputmask("(999) 999-9999", {inputEventOnly: true}).mask(testmask);
  28. testmask.focus();
  29. //simulate input
  30. $(testmask).input("1231231234");
  31. assert.equal(testmask.value, "(123) 123-1234", "Result " + testmask.value);
  32. });
  33. qunit.test("(999) 999-9999 - type 123 + backspace", function (assert) {
  34. var $fixture = $("#qunit-fixture");
  35. $fixture.append('<input type="text" id="testmask" />');
  36. var testmask = document.getElementById("testmask");
  37. Inputmask("(999) 999-9999", {inputEventOnly: true}).mask(testmask);
  38. testmask.focus();
  39. //simulate input
  40. $(testmask).input("123");
  41. //simulate backspace
  42. $(testmask).input("(12) ___-____", 3);
  43. assert.ok($.caret(testmask).begin == 3, "Caret " + $.caret(testmask).begin);
  44. });
  45. };