tests_ip.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. export default function(qunit, $, Inputmask) {
  2. qunit.module("IP - masks");
  3. qunit.test("inputmask(\"ip\" - 10.10.10.10", function(assert) {
  4. var done = assert.async(),
  5. $fixture = $("#qunit-fixture");
  6. $fixture.append('<input type="text" id="testmask" />');
  7. var testmask = document.getElementById("testmask");
  8. $fixture.append('<input type="text" id="testmask2" />');
  9. var testmask2 = document.getElementById("testmask2");
  10. Inputmask("ip").mask(testmask);
  11. testmask.focus();
  12. $("#testmask").Type("10.10.10.10");
  13. testmask2.focus();
  14. setTimeout(function() {
  15. assert.equal(testmask.value, "10.10.10.10", "Result " + testmask.value);
  16. done();
  17. }, 0);
  18. });
  19. qunit.test("inputmask(\"ip\" - 1.1.1.1", function(assert) {
  20. var done = assert.async(),
  21. $fixture = $("#qunit-fixture");
  22. $fixture.append('<input type="text" id="testmask" />');
  23. var testmask = document.getElementById("testmask");
  24. $fixture.append('<input type="text" id="testmask2" />');
  25. var testmask2 = document.getElementById("testmask2");
  26. Inputmask("ip").mask(testmask);
  27. testmask.focus();
  28. $("#testmask").Type("1.1.1.1");
  29. testmask2.focus();
  30. setTimeout(function() {
  31. assert.equal(testmask.value, "1.1.1.1", "Result " + testmask.value);
  32. done();
  33. }, 0);
  34. });
  35. qunit.test("inputmask(\"ip\" - 255.255.255.255", function(assert) {
  36. var done = assert.async(),
  37. $fixture = $("#qunit-fixture");
  38. $fixture.append('<input type="text" id="testmask" />');
  39. var testmask = document.getElementById("testmask");
  40. $fixture.append('<input type="text" id="testmask2" />');
  41. var testmask2 = document.getElementById("testmask2");
  42. Inputmask("ip").mask(testmask);
  43. testmask.focus();
  44. $("#testmask").Type("255.255.255.255");
  45. setTimeout(function() {
  46. testmask2.focus();
  47. assert.equal(testmask.value, "255.255.255.255", "Result " + testmask.value);
  48. done();
  49. }, 0);
  50. });
  51. qunit.test("inputmask(\"ip\" - 192.168.1.100", function(assert) {
  52. var done = assert.async(),
  53. $fixture = $("#qunit-fixture");
  54. $fixture.append('<input type="text" id="testmask" />');
  55. var testmask = document.getElementById("testmask");
  56. $fixture.append('<input type="text" id="testmask2" />');
  57. var testmask2 = document.getElementById("testmask2");
  58. Inputmask("ip").mask(testmask);
  59. testmask.focus();
  60. $("#testmask").Type("192.168.1.100");
  61. testmask2.focus();
  62. setTimeout(function() {
  63. assert.equal(testmask.value, "192.168.1.100", "Result " + testmask.value);
  64. done();
  65. }, 0);
  66. });
  67. qunit.test("inputmask(\"ip\" - 123123123123 - delete 2nd 1 - ", function(assert) {
  68. var done = assert.async(),
  69. $fixture = $("#qunit-fixture");
  70. $fixture.append('<input type="text" id="testmask" />');
  71. var testmask = document.getElementById("testmask");
  72. $fixture.append('<input type="text" id="testmask2" />');
  73. var testmask2 = document.getElementById("testmask2");
  74. Inputmask("ip").mask(testmask);
  75. testmask.focus();
  76. $("#testmask").Type("123123123123");
  77. testmask2.focus();
  78. $.caret(testmask, 4);
  79. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  80. setTimeout(function() {
  81. assert.equal(testmask.value, "123.23.123.123", "Result " + testmask.value);
  82. done();
  83. }, 0);
  84. });
  85. };