tests_paste.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. export default function (qunit, $, Inputmask) {
  2. qunit.module("Paste value");
  3. qunit.test("inputmask(\"+7 (999) 999-99-99\") ~ paste \"+79114041112\"", function (assert) {
  4. var done = assert.async(), $fixture = $("#qunit-fixture");
  5. $fixture.append('<input type="text" id="testmask" />');
  6. var testmask = document.getElementById("testmask");
  7. Inputmask("+7 (999) 999-99-99").mask(testmask);
  8. testmask.focus();
  9. $("#testmask").paste("+79114041112");
  10. setTimeout(function () {
  11. assert.equal(testmask.value, "+7 (911) 404-11-12", "Result " + testmask.value);
  12. done();
  13. }, 0);
  14. });
  15. qunit.test("inputmask(\"+7 (999) 999-99-99\") ~ paste \"+7 (9114041112___)\"", function (assert) {
  16. var done = assert.async(), $fixture = $("#qunit-fixture");
  17. $fixture.append('<input type="text" id="testmask" />');
  18. var testmask = document.getElementById("testmask");
  19. Inputmask("+7 (999) 999-99-99").mask(testmask);
  20. testmask.focus();
  21. $("#testmask").paste("+7 (9114041112___)");
  22. setTimeout(function () {
  23. assert.equal(testmask.value, "+7 (911) 404-11-12", "Result " + testmask.value);
  24. done();
  25. }, 0);
  26. });
  27. qunit.test("inputmask(\"+7 (999) 999-99-99\") ~ paste \"0079114041112\" - monoblaine", function (assert) {
  28. var done = assert.async(), $fixture = $("#qunit-fixture");
  29. $fixture.append('<input type="text" id="testmask" />');
  30. var testmask = document.getElementById("testmask");
  31. Inputmask("+7 (999) 999-99-99", {
  32. onBeforePaste: function (pastedValue) {
  33. //just simplistic for the test ;-)
  34. var strippedValue = pastedValue.substr(3);
  35. return strippedValue;
  36. }
  37. }).mask(testmask);
  38. testmask.focus();
  39. $("#testmask").paste("0079114041112");
  40. setTimeout(function () {
  41. assert.equal(testmask.value, "+7 (911) 404-11-12", "Result " + testmask.value);
  42. done();
  43. }, 0);
  44. });
  45. qunit.test("inputmask(\"+31 9999999999\") ~ paste \"3112345678\" - jason16v", function (assert) {
  46. var done = assert.async(), $fixture = $("#qunit-fixture");
  47. $fixture.append('<input type="text" id="testmask" />');
  48. var testmask = document.getElementById("testmask");
  49. Inputmask("+31 9999999999").mask(testmask);
  50. testmask.focus();
  51. $("#testmask").paste("3112345678");
  52. setTimeout(function () {
  53. assert.equal(testmask.value, "+31 3112345678", "Result " + testmask.value);
  54. done();
  55. }, 0);
  56. });
  57. qunit.test("inputmask(\"+31 9999999999\") ~ paste \"+3112345678\" - jason16v", function (assert) {
  58. var done = assert.async(), $fixture = $("#qunit-fixture");
  59. $fixture.append('<input type="text" id="testmask" />');
  60. var testmask = document.getElementById("testmask");
  61. Inputmask("+31 9999999999").mask(testmask);
  62. testmask.focus();
  63. $("#testmask").paste("+3112345678");
  64. setTimeout(function () {
  65. assert.equal(testmask.value, "+31 12345678__", "Result " + testmask.value);
  66. done();
  67. }, 0);
  68. });
  69. qunit.test("99.999.999/9999-99 numericInput ~ paste __-____/..__79100085302751__-____/..__ - imbelo", function (assert) {
  70. var done = assert.async(), $fixture = $("#qunit-fixture");
  71. $fixture.append('<input type="text" id="testmask" />');
  72. var testmask = document.getElementById("testmask");
  73. Inputmask({
  74. "mask": "99.999.999/9999-99",
  75. "numericInput": true
  76. }).mask(testmask);
  77. testmask.focus();
  78. $("#testmask").paste("__-____/..__79100085302751__-____/..__");
  79. setTimeout(function () {
  80. assert.equal(testmask.value, "79.100.085/3027-51", "Result " + testmask.value);
  81. done();
  82. }, 0);
  83. });
  84. qunit.test("currency ~ $123.22 - sjk07", function (assert) {
  85. var done = assert.async(), $fixture = $("#qunit-fixture");
  86. $fixture.append('<input type="text" id="testmask" />');
  87. var testmask = document.getElementById("testmask");
  88. Inputmask('currency').mask(testmask);
  89. testmask.focus();
  90. $("#testmask").paste("$123.22");
  91. setTimeout(function () {
  92. assert.equal(testmask.value, "$ 123.22", "Result " + testmask.value);
  93. done();
  94. }, 0);
  95. });
  96. qunit.test("currency ~ $-123.22 - sjk07", function (assert) {
  97. var done = assert.async(), $fixture = $("#qunit-fixture");
  98. $fixture.append('<input type="text" id="testmask" />');
  99. var testmask = document.getElementById("testmask");
  100. Inputmask('currency').mask(testmask);
  101. testmask.focus();
  102. $("#testmask").paste("$-123.22");
  103. setTimeout(function () {
  104. assert.equal(testmask.value, "-$ 123.22", "Result " + testmask.value);
  105. done();
  106. }, 0);
  107. });
  108. qunit.test("currency ~ 1000.00 - sjk07", function (assert) {
  109. var done = assert.async(), $fixture = $("#qunit-fixture");
  110. $fixture.append('<input type="text" id="testmask" />');
  111. var testmask = document.getElementById("testmask");
  112. Inputmask('currency').mask(testmask);
  113. testmask.focus();
  114. $("#testmask").paste("1000.00");
  115. setTimeout(function () {
  116. assert.equal(testmask.value, "$ 1,000.00", "Result " + testmask.value);
  117. done();
  118. }, 0);
  119. });
  120. qunit.test("currency ~ -1000.00 - sjk07", function (assert) {
  121. var done = assert.async(), $fixture = $("#qunit-fixture");
  122. $fixture.append('<input type="text" id="testmask" />');
  123. var testmask = document.getElementById("testmask");
  124. Inputmask('currency').mask(testmask);
  125. testmask.focus();
  126. $("#testmask").paste("-1000.00");
  127. setTimeout(function () {
  128. assert.equal(testmask.value, "-$ 1,000.00", "Result " + testmask.value);
  129. done();
  130. }, 0);
  131. });
  132. qunit.test("currency ~ $1000.00 - sjk07", function (assert) {
  133. var done = assert.async(), $fixture = $("#qunit-fixture");
  134. $fixture.append('<input type="text" id="testmask" />');
  135. var testmask = document.getElementById("testmask");
  136. Inputmask('currency').mask(testmask);
  137. testmask.focus();
  138. $("#testmask").paste("$1000.00");
  139. setTimeout(function () {
  140. assert.equal(testmask.value, "$ 1,000.00", "Result " + testmask.value);
  141. done();
  142. }, 0);
  143. });
  144. qunit.test("currency ~ $-1000.00 - sjk07", function (assert) {
  145. var done = assert.async(), $fixture = $("#qunit-fixture");
  146. $fixture.append('<input type="text" id="testmask" />');
  147. var testmask = document.getElementById("testmask");
  148. Inputmask('currency').mask(testmask);
  149. testmask.focus();
  150. $("#testmask").paste("$-1000.00");
  151. setTimeout(function () {
  152. assert.equal(testmask.value, "-$ 1,000.00", "Result " + testmask.value);
  153. done();
  154. }, 0);
  155. });
  156. qunit.test("currency ~ 000.02 - sjk07", function (assert) {
  157. var done = assert.async(), $fixture = $("#qunit-fixture");
  158. $fixture.append('<input type="text" id="testmask" />');
  159. var testmask = document.getElementById("testmask");
  160. Inputmask('currency').mask(testmask);
  161. testmask.focus();
  162. $("#testmask").paste("000.02");
  163. setTimeout(function () {
  164. $(testmask).trigger("blur");
  165. assert.equal(testmask.value, "$ 0.02", "Result " + testmask.value);
  166. done();
  167. }, 0);
  168. });
  169. qunit.test("02.999.999 ~ paste 02.024.900 - tnavarra", function (assert) {
  170. var done = assert.async(), $fixture = $("#qunit-fixture");
  171. $fixture.append('<input type="text" id="testmask" />');
  172. var testmask = document.getElementById("testmask");
  173. Inputmask("02.999.999").mask(testmask);
  174. testmask.focus();
  175. $("#testmask").paste("02.024.900");
  176. setTimeout(function () {
  177. assert.equal(testmask.value, "02.024.900", "Result " + testmask.value);
  178. done();
  179. }, 0);
  180. });
  181. qunit.test("R9999999999 ~ paste 1234567890 - s-a", function (assert) {
  182. var done = assert.async(), $fixture = $("#qunit-fixture");
  183. $fixture.append('<input type="text" id="testmask" />');
  184. var testmask = document.getElementById("testmask");
  185. Inputmask("R9999999999", {
  186. "placeholder": "0",
  187. "showMaskOnFocus": false,
  188. "numericInput": true
  189. }).mask(testmask);
  190. $("#testmask").trigger("click");
  191. $("#testmask").paste("1234567890");
  192. setTimeout(function () {
  193. assert.equal(testmask.value, "R1234567890", "Result " + testmask.value);
  194. done();
  195. }, 0);
  196. });
  197. };