tests_initialvalue.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. export default function(qunit, $, Inputmask) {
  2. qunit.module("Initial value setting");
  3. qunit.test("inputmask(\"999:99\", { placeholder: \"0\"}) value=\"007:20\"", function(assert) {
  4. var $fixture = $("#qunit-fixture");
  5. $fixture.append('<input type="text" id="testmask" value="007:20" />');
  6. var testmask = document.getElementById("testmask");
  7. Inputmask("999:99", {
  8. placeholder: "0"
  9. }).mask(testmask);
  10. assert.equal(testmask.value, "007:20", "Result " + testmask.value);
  11. });
  12. qunit.test("inputmask(\"99 999 999 999 9999 \\D\\E*** 9999\") ~ value=\"01 650 103 002 0001 DE101 5170\" - wuSam", function(assert) {
  13. var $fixture = $("#qunit-fixture");
  14. $fixture.append('<input type="text" id="testmask" value="01 650 103 002 0001 DE101 5170" />');
  15. var testmask = document.getElementById("testmask");
  16. Inputmask("99 999 999 999 9999 \\D\\E*** 9999").mask(testmask);
  17. assert.equal(testmask.value, "01 650 103 002 0001 DE101 5170", "Result " + testmask.value);
  18. });
  19. qunit.test("inputmask(\"99 999 999 999 9999 \\D\\E*** 9999\") ~ value=\"016501030020001DE1015170\" - wuSam", function(assert) {
  20. var $fixture = $("#qunit-fixture");
  21. $fixture.append('<input type="text" id="testmask" value="016501030020001DE1015170" />');
  22. var testmask = document.getElementById("testmask");
  23. Inputmask("99 999 999 999 9999 \\D\\E*** 9999").mask(testmask);
  24. assert.equal(testmask.value, "01 650 103 002 0001 DE101 5170", "Result " + testmask.value);
  25. });
  26. qunit.test("inputmask(\"99 999 999 999 9999 \\D\\E*** 9999\") ~ value=\"016501030020001DE1015170\" replace 2 with 3 - wuSam", function(assert) {
  27. var $fixture = $("#qunit-fixture");
  28. $fixture.append('<input type="text" id="testmask" value="016501030020001DE1015170" />');
  29. var testmask = document.getElementById("testmask");
  30. Inputmask("99 999 999 999 9999 \\D\\E*** 9999").mask(testmask);
  31. $.caret(testmask, 13, 14);
  32. $("#testmask").Type("3");
  33. assert.equal(testmask.value, "01 650 103 003 0001 DE101 5170", "Result " + testmask.value);
  34. });
  35. qunit.test("inputmask(\"99 999 999 999 9999 \\D\\E*** 9999\") ~ value=\"016501030020001DE1015170\" replace 002 with 003 - wuSam", function(assert) {
  36. var $fixture = $("#qunit-fixture");
  37. $fixture.append('<input type="text" id="testmask" value="016501030020001DE1015170" />');
  38. var testmask = document.getElementById("testmask");
  39. Inputmask("99 999 999 999 9999 \\D\\E*** 9999").mask(testmask);
  40. $.caret(testmask, 11, 14);
  41. $("#testmask").Type("003");
  42. assert.equal(testmask.value, "01 650 103 003 0001 DE101 5170", "Result " + testmask.value);
  43. });
  44. qunit.test("inputmask(\"99 999 999 999 9999 \\D\\E*** 9999\") ~ value=\"016501030020001DE1015170\" replace 02 with 01 - wuSam", function(assert) {
  45. var $fixture = $("#qunit-fixture");
  46. $fixture.append('<input type="text" id="testmask" value="016501030020001DE1015170" />');
  47. var testmask = document.getElementById("testmask");
  48. Inputmask("99 999 999 999 9999 \\D\\E*** 9999").mask(testmask);
  49. $.caret(testmask, 12, 14);
  50. $("#testmask").Type("01");
  51. assert.equal(testmask.value, "01 650 103 001 0001 DE101 5170", "Result " + testmask.value);
  52. });
  53. qunit.test("inputmask(\"99 999 999 999 9999 \\D\\E*** 9999\", { greedy: false }) ~ value=\"016501030020001DE1015170\" replace 02 with 01 - wuSam", function(assert) {
  54. var $fixture = $("#qunit-fixture");
  55. $fixture.append('<input type="text" id="testmask" value="016501030020001DE1015170" />');
  56. var testmask = document.getElementById("testmask");
  57. Inputmask("99 999 999 999 9999 \\D\\E*** 9999", {
  58. greedy: false
  59. }).mask(testmask);
  60. $.caret(testmask, 12, 14);
  61. $("#testmask").Type("01");
  62. assert.equal(testmask.value, "01 650 103 001 0001 DE101 5170", "Result " + testmask.value);
  63. });
  64. qunit.test("inputmask(\"\\D\\E***\") ~ value=\"DE001\" - wuSam", function(assert) {
  65. var $fixture = $("#qunit-fixture");
  66. $fixture.append('<input type="text" id="testmask" value="DE001" />');
  67. var testmask = document.getElementById("testmask");
  68. Inputmask("\\D\\E***").mask(testmask);
  69. assert.equal(testmask.value, "DE001", "Result " + testmask.value);
  70. });
  71. qunit.test("inputmask(\"decimal\") ~ value=\"123.45\"", function(assert) {
  72. var $fixture = $("#qunit-fixture");
  73. $fixture.append('<input type="text" id="testmask" value="123.45" />');
  74. var testmask = document.getElementById("testmask");
  75. Inputmask("decimal").mask(testmask);
  76. assert.equal(testmask.value, "123.45", "Result " + testmask.value);
  77. });
  78. qunit.test("inputmask(\"decimal\") ~ value=\"123.45\" - disabled input", function(assert) {
  79. var $fixture = $("#qunit-fixture");
  80. $fixture.append('<input type="text" id="testmask" value="123.45" disabled="disabled" />');
  81. var testmask = document.getElementById("testmask");
  82. Inputmask("decimal").mask(testmask);
  83. assert.equal(testmask.value, "123.45", "Result " + testmask.value);
  84. });
  85. qunit.test("inputmask(\"mm/yyyy\") ~ value=\"031973\" - disabled input", function(assert) {
  86. var $fixture = $("#qunit-fixture");
  87. $fixture.append('<input type="text" id="testmask" value="031973" disabled="disabled" />');
  88. var testmask = document.getElementById("testmask");
  89. Inputmask("mm/yyyy").mask(testmask);
  90. assert.equal(testmask.value, "03/1973", "Result " + testmask.value);
  91. });
  92. qunit.test("inputmask(\"6703 9999 9999 9999 9\") ~ value=\"6703 1234 5678 9012 3\" - FransVdb", function(assert) {
  93. var $fixture = $("#qunit-fixture");
  94. $fixture.append('<input type="text" id="testmask" value="6703 1234 5678 9012 3" />');
  95. Inputmask("6703 9999 9999 9999 9");
  96. assert.equal(testmask.value, "6703 1234 5678 9012 3", "Result " + testmask.value);
  97. });
  98. qunit.test("inputmask(\"6703 9999 9999 9999 9\") ~ type \"6703 1234 5678 9012 3\" + backspace - FransVdb", function(assert) {
  99. var $fixture = $("#qunit-fixture");
  100. $fixture.append('<input type="text" id="testmask" />');
  101. var testmask = document.getElementById("testmask");
  102. Inputmask("6703 9999 9999 9999 9").mask(testmask);
  103. testmask.focus();
  104. $("#testmask").Type("1234567890123");
  105. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  106. assert.equal(testmask.value, "6703 1234 5678 9012 _", "Result " + testmask.value);
  107. });
  108. qunit.test("inputmask(\"6703 9999 9999 9999 9\") ~ type \"6703670367036\" + backspace - FransVdb", function(assert) {
  109. var done = assert.async(),
  110. $fixture = $("#qunit-fixture");
  111. $fixture.append('<input type="text" id="testmask" />');
  112. var testmask = document.getElementById("testmask");
  113. Inputmask("6703 9999 9999 9999 9").mask(testmask);
  114. testmask.focus();
  115. $("#testmask").trigger("click");
  116. setTimeout(function() {
  117. $("#testmask").Type("6703670367036");
  118. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  119. assert.equal(testmask.value, "6703 6703 6703 6703 _", "Result " + testmask.value);
  120. done();
  121. }, 0);
  122. });
  123. };