tests_formatvalidate.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. export default function(qunit, $, Inputmask) {
  2. qunit.module("Value formatting");
  3. qunit.test("Inputmask.format(\"2331973\", { alias: \"date\"})", function(assert) {
  4. var formattedValue = Inputmask.format("2331973", {
  5. alias: "date"
  6. });
  7. assert.equal(formattedValue, "23/03/1973", "Result " + formattedValue);
  8. });
  9. qunit.test("Inputmask.format(\"016501030020001DE1015170\", { mask: \"99 999 999 999 9999 \\D\\E*** 9999\"})", function(assert) {
  10. var formattedValue = Inputmask.format("016501030020001DE1015170", {
  11. mask: "99 999 999 999 9999 \\D\\E*** 9999"
  12. });
  13. assert.equal(formattedValue, "01 650 103 002 0001 DE101 5170", "Result " + formattedValue);
  14. });
  15. qunit.test("Inputmask.format(\"12\", { mask: \"$ 999999\", numericInput: true, placeholder: \"0\" }); - gigermocas", function(assert) {
  16. var formattedValue = Inputmask.format("12", {
  17. mask: "$ 999999",
  18. numericInput: true,
  19. placeholder: "0"
  20. });
  21. assert.equal(formattedValue, "$ 000012", "Result " + formattedValue);
  22. });
  23. qunit.test("Inputmask.format(\"1111111.11\" - ... autoGroup: true - swd120", function(assert) {
  24. var formattedValue = Inputmask.format("1111111.11", {
  25. alias: "decimal",
  26. radixPoint: ".",
  27. digits: 2,
  28. autoGroup: true,
  29. groupSeparator: ",",
  30. groupSize: 3,
  31. allowMinus: true
  32. });
  33. assert.equal(formattedValue, "1,111,111.11", "Result " + formattedValue);
  34. });
  35. qunit.test("Inputmask.format(phone, { mask: '(999) 999-9999' })); - krivaten", function(assert) {
  36. var phone = '5551112222';
  37. var formattedValue = Inputmask.format(phone, {
  38. mask: '(999) 999-9999'
  39. });
  40. assert.equal(formattedValue, "(555) 111-2222", "Result " + formattedValue);
  41. });
  42. qunit.test("format(62.91, { alias: 'numeric' } - penihel", function(assert) {
  43. var formattedValue = Inputmask.format(62.91, { alias: 'numeric' });
  44. assert.equal(formattedValue, "62.91", "Result " + formattedValue);
  45. });
  46. qunit.module("Value Validating");
  47. qunit.test("Inputmask.isValid(\"23/03/1973\", { alias: \"date\"})", function(assert) {
  48. var isValid = Inputmask.isValid("23/03/1973", {
  49. alias: "date"
  50. });
  51. assert.equal(isValid, true, "Result " + isValid);
  52. });
  53. qunit.test("Inputmask.isValid(\"01 650 103 002 0001 DE101 5170\", { mask: \"99 999 999 999 9999 \\D\\E*** 9999\"})", function(assert) {
  54. var isValid = Inputmask.isValid("01 650 103 002 0001 DE101 5170", {
  55. mask: "99 999 999 999 9999 \\D\\E*** 9999"
  56. });
  57. assert.equal(isValid, true, "Result " + isValid);
  58. });
  59. qunit.test("Inputmask.isValid email => false", function(assert) {
  60. var isValid = Inputmask.isValid("some.body@mail.c", {
  61. alias: "email"
  62. });
  63. assert.equal(isValid, true, "Result " + isValid);
  64. });
  65. qunit.test("Inputmask.isValid email => true", function(assert) {
  66. var isValid = Inputmask.isValid("some.body@mail.com", {
  67. alias: "email"
  68. });
  69. assert.equal(isValid, true, "Result " + isValid);
  70. });
  71. qunit.test("Inputmask.isValid email greedy => false", function(assert) {
  72. var isValid = Inputmask.isValid("some.body@mail.c", {
  73. alias: "email",
  74. greedy: true
  75. });
  76. assert.equal(isValid, true, "Result " + isValid);
  77. });
  78. qunit.test("Inputmask.isValid email greedy => true", function(assert) {
  79. var isValid = Inputmask.isValid("some.body@mail.com", {
  80. alias: "email",
  81. greedy: true
  82. });
  83. assert.equal(isValid, true, "Result " + isValid);
  84. });
  85. qunit.test("YoussefTaghlabi isValid(\"100\", { alias: \"integer\" }", function(assert) {
  86. var isValid = Inputmask.isValid("100", {
  87. alias: "integer"
  88. });
  89. assert.equal(isValid, true, "Result " + isValid);
  90. });
  91. qunit.test("YoussefTaghlabi isValid(\"100.00\", { alias: \"integer\" }", function(assert) {
  92. var isValid = Inputmask.isValid("100.00", {
  93. alias: "integer"
  94. });
  95. assert.equal(isValid, false, "Result " + isValid);
  96. });
  97. qunit.test("YoussefTaghlabi isValid(\"123\", { alias: \"decimal\" }", function(assert) {
  98. var isValid = Inputmask.isValid("123", {
  99. alias: "decimal"
  100. });
  101. assert.equal(isValid, true, "Result " + isValid);
  102. });
  103. qunit.test("YoussefTaghlabi isValid(\"123.45\", { alias: \"decimal\" }", function(assert) {
  104. var isValid = Inputmask.isValid("123.45", {
  105. alias: "decimal"
  106. });
  107. assert.equal(isValid, true, "Result " + isValid);
  108. });
  109. qunit.test("YoussefTaghlabi isValid(\"123456.78\", { alias: \"decimal\" }", function(assert) {
  110. var isValid = Inputmask.isValid("123456.78", {
  111. alias: "decimal"
  112. });
  113. assert.equal(isValid, true, "Result " + isValid);
  114. });
  115. qunit.test("YoussefTaghlabi isValid(\"123,456.78\", { alias: \"decimal\" }", function(assert) {
  116. var isValid = Inputmask.isValid("123,456.78", {
  117. alias: "decimal",
  118. radixPoint: ".",
  119. groupSeparator: ",",
  120. groupSize: 3,
  121. autoGroup: true
  122. });
  123. assert.equal(isValid, true, "Result " + isValid);
  124. });
  125. qunit.test("YoussefTaghlabi isValid(\"12,\", { alias: \"decimal\" }", function(assert) {
  126. var isValid = Inputmask.isValid("12,", {
  127. alias: "decimal",
  128. radixPoint: ".",
  129. groupSeparator: ",",
  130. groupSize: 3
  131. });
  132. assert.equal(isValid, false, "Result " + isValid);
  133. });
  134. qunit.test("YoussefTaghlabi isValid(\"12,1.45\", { alias: \"decimal\" }", function(assert) {
  135. var isValid = Inputmask.isValid("12,1.45", {
  136. alias: "decimal",
  137. radixPoint: ".",
  138. groupSeparator: ",",
  139. groupSize: 3
  140. });
  141. assert.equal(isValid, false, "Result " + isValid);
  142. });
  143. qunit.test("YoussefTaghlabi isValid(\"12,345.67\", { alias: \"decimal\" }", function(assert) {
  144. var isValid = Inputmask.isValid("12,345.67", {
  145. alias: "decimal",
  146. radixPoint: ".",
  147. groupSeparator: ",",
  148. groupSize: 3,
  149. autoGroup: true
  150. });
  151. assert.equal(isValid, true, "Result " + isValid);
  152. });
  153. qunit.test("thomstark isValid(\"12lbs\", {mask:\"99[9]lb\\s\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function(assert) {
  154. var isValid = Inputmask.isValid("12lbs", {
  155. mask: "99[9]lb\\s",
  156. greedy: false,
  157. skipOptionalPartCharacter: "",
  158. "clearIncomplete": true
  159. });
  160. assert.equal(isValid, true, "Result " + isValid);
  161. });
  162. qunit.test("thomstark isValid(\"1'2\"\", {mask:\"9'9[9]\"\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function(assert) {
  163. var isValid = Inputmask.isValid("1'2\"", {
  164. mask: "9'9[9]\"",
  165. greedy: false,
  166. skipOptionalPartCharacter: "",
  167. "clearIncomplete": true
  168. });
  169. assert.equal(isValid, true, "Result " + isValid);
  170. });
  171. qunit.test("thomstark isValid(\"12lbs\", {mask:\"99{1,2}lb\\s\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function(assert) {
  172. var isValid = Inputmask.isValid("12lbs", {
  173. mask: "99{1,2}lb\\s",
  174. greedy: false,
  175. skipOptionalPartCharacter: "",
  176. "clearIncomplete": true
  177. });
  178. assert.equal(isValid, true, "Result " + isValid);
  179. });
  180. qunit.test("thomstark isValid(\"9'9{1,2}\", {mask:\"9'9[9]\"\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function(assert) {
  181. var isValid = Inputmask.isValid("1'2\"", {
  182. mask: "9'9{1,2}\"",
  183. greedy: false,
  184. skipOptionalPartCharacter: "",
  185. "clearIncomplete": true
  186. });
  187. assert.equal(isValid, true, "Result " + isValid);
  188. });
  189. qunit.test("a13x3y isValid(\"some_body@mail.com\", {alias:\"email\"}", function(assert) {
  190. var isValid = Inputmask.isValid("some_body@mail.com", {
  191. alias: "email"
  192. });
  193. assert.equal(isValid, true, "Result " + isValid);
  194. });
  195. qunit.test("Inputmask(\"99-99[ 99/99]\").isValid(\"03-11\") - pricejt", function(assert) {
  196. var isValid = Inputmask("99-99[ 99/99]").isValid("03-11");
  197. assert.equal(isValid, true, "Result " + isValid);
  198. });
  199. qunit.module("Value unmasking");
  200. qunit.test("inputmask.unmask(\"23/03/1973\", { alias: \"dd/mm/yyyy\" })", function(assert) {
  201. var unmasked = Inputmask.unmask("23/03/1973", {
  202. alias: "dd/mm/yyyy"
  203. });
  204. assert.equal(unmasked, "23031973", "Result " + unmasked);
  205. });
  206. };