tests_date.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. export default function(qunit, $, Inputmask) {
  2. qunit.module("Date.Extensions");
  3. qunit.test("inputmask(\"dd/mm/yyyy\") - input 2331973", function(assert) {
  4. var $fixture = $("#qunit-fixture");
  5. $fixture.append('<input type="text" id="testmask" />');
  6. var testmask = document.getElementById("testmask");
  7. Inputmask("dd/mm/yyyy").mask(testmask);
  8. testmask.focus();
  9. $("#testmask").SendKey("2");
  10. $("#testmask").SendKey("3");
  11. $("#testmask").SendKey("3");
  12. $("#testmask").SendKey("1");
  13. $("#testmask").SendKey("9");
  14. $("#testmask").SendKey("7");
  15. $("#testmask").SendKey("3");
  16. assert.equal(testmask.value, "23/03/1973", "Result " + testmask.value);
  17. });
  18. qunit.test("inputmask(\"mm/dd/yyyy\") - input 3231973", function(assert) {
  19. var $fixture = $("#qunit-fixture");
  20. $fixture.append('<input type="text" id="testmask" />');
  21. var testmask = document.getElementById("testmask");
  22. Inputmask("mm/dd/yyyy").mask(testmask);
  23. testmask.focus();
  24. $("#testmask").SendKey("3");
  25. $("#testmask").SendKey("2");
  26. $("#testmask").SendKey("3");
  27. $("#testmask").SendKey("1");
  28. $("#testmask").SendKey("9");
  29. $("#testmask").SendKey("7");
  30. $("#testmask").SendKey("3");
  31. assert.equal(testmask.value, "03/23/1973", "Result " + testmask.value);
  32. });
  33. qunit.test("inputmask(\"dd/mm/yyyy\") - input 29022012", function(assert) {
  34. var $fixture = $("#qunit-fixture");
  35. $fixture.append('<input type="text" id="testmask" />');
  36. var testmask = document.getElementById("testmask");
  37. Inputmask("dd/mm/yyyy").mask(testmask);
  38. testmask.focus();
  39. $("#testmask").SendKey("2");
  40. $("#testmask").SendKey("9");
  41. $("#testmask").SendKey("0");
  42. $("#testmask").SendKey("2");
  43. $("#testmask").SendKey("2");
  44. $("#testmask").SendKey("0");
  45. $("#testmask").SendKey("1");
  46. $("#testmask").SendKey("2");
  47. assert.equal(testmask.value, "29/02/2012", "Result " + testmask.value);
  48. });
  49. qunit.test("inputmask(\"dd/mm/yyyy\") - input 29022013", function(assert) {
  50. var $fixture = $("#qunit-fixture");
  51. $fixture.append('<input type="text" id="testmask" />');
  52. var testmask = document.getElementById("testmask");
  53. Inputmask("dd/mm/yyyy").mask(testmask);
  54. testmask.focus();
  55. $("#testmask").SendKey("2");
  56. $("#testmask").SendKey("9");
  57. $("#testmask").SendKey("0");
  58. $("#testmask").SendKey("2");
  59. $("#testmask").SendKey("2");
  60. $("#testmask").SendKey("0");
  61. $("#testmask").SendKey("1");
  62. $("#testmask").SendKey("3");
  63. assert.equal(testmask.value, "29/02/201y", "Result " + testmask.value);
  64. });
  65. qunit.test("inputmask(\"mm/dd/yyyy\") - input 02292012", function(assert) {
  66. var $fixture = $("#qunit-fixture");
  67. $fixture.append('<input type="text" id="testmask" />');
  68. var testmask = document.getElementById("testmask");
  69. Inputmask("mm/dd/yyyy").mask(testmask);
  70. testmask.focus();
  71. $("#testmask").SendKey("0");
  72. $("#testmask").SendKey("2");
  73. $("#testmask").SendKey("2");
  74. $("#testmask").SendKey("9");
  75. $("#testmask").SendKey("2");
  76. $("#testmask").SendKey("0");
  77. $("#testmask").SendKey("1");
  78. $("#testmask").SendKey("2");
  79. assert.equal(testmask.value, "02/29/2012", "Result " + testmask.value);
  80. });
  81. qunit.test("inputmask(\"mm/dd/yyyy\") - input 02292013", function(assert) {
  82. var $fixture = $("#qunit-fixture");
  83. $fixture.append('<input type="text" id="testmask" />');
  84. var testmask = document.getElementById("testmask");
  85. Inputmask("mm/dd/yyyy").mask(testmask);
  86. testmask.focus();
  87. $("#testmask").SendKey("0");
  88. $("#testmask").SendKey("2");
  89. $("#testmask").SendKey("2");
  90. $("#testmask").SendKey("9");
  91. $("#testmask").SendKey("2");
  92. $("#testmask").SendKey("0");
  93. $("#testmask").SendKey("1");
  94. $("#testmask").SendKey("3");
  95. assert.equal(testmask.value, "02/29/201y", "Result " + testmask.value);
  96. });
  97. qunit.test("inputmask(\"dd/mm/yyyy\") - input CTRL RIGHT", function(assert) {
  98. var $fixture = $("#qunit-fixture");
  99. $fixture.append('<input type="text" id="testmask" />');
  100. var testmask = document.getElementById("testmask");
  101. Inputmask("dd/mm/yyyy").mask(testmask);
  102. testmask.focus();
  103. $("#testmask").SendKey(Inputmask.keyCode.RIGHT, Inputmask.keyCode.CONTROL);
  104. assert.ok(testmask.value != "dd/mm/yyyy", "Result " + testmask.value);
  105. });
  106. qunit.test("inputmask(\"dd/mm/yyyy\") - input 2331973 BACKSPACE x4 2013", function(assert) {
  107. var $fixture = $("#qunit-fixture");
  108. $fixture.append('<input type="text" id="testmask" />');
  109. var testmask = document.getElementById("testmask");
  110. Inputmask("dd/mm/yyyy").mask(testmask);
  111. testmask.focus();
  112. $("#testmask").SendKey("2");
  113. $("#testmask").SendKey("3");
  114. $("#testmask").SendKey("3");
  115. $("#testmask").SendKey("1");
  116. $("#testmask").SendKey("9");
  117. $("#testmask").SendKey("7");
  118. $("#testmask").SendKey("3");
  119. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  120. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  121. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  122. $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
  123. $("#testmask").SendKey("2");
  124. $("#testmask").SendKey("0");
  125. $("#testmask").SendKey("1");
  126. $("#testmask").SendKey("3");
  127. assert.equal(testmask.value, "23/03/2013", "Result " + testmask.value);
  128. });
  129. qunit.test("inputmask(\"dd/mm/yyyy\") - input 23373 ", function(assert) {
  130. var $fixture = $("#qunit-fixture");
  131. $fixture.append('<input type="text" id="testmask" />');
  132. var testmask = document.getElementById("testmask");
  133. Inputmask("dd/mm/yyyy").mask(testmask);
  134. testmask.focus();
  135. $("#testmask").Type("23373");
  136. assert.equal(testmask.value, "23/03/2073", "Result " + testmask.value);
  137. });
  138. qunit.test("inputmask(\"dd/mm/yyyy\") - input 23318 - jimithing277", function(assert) {
  139. var $fixture = $("#qunit-fixture");
  140. $fixture.append('<input type="text" id="testmask" />');
  141. var testmask = document.getElementById("testmask");
  142. Inputmask("dd/mm/yyyy").mask(testmask);
  143. testmask.focus();
  144. $("#testmask").Type("23318");
  145. assert.equal(testmask.value, "23/03/2018", "Result " + testmask.value);
  146. });
  147. qunit.test("inputmask(\"dd/mm/yyyy\", { yearrange: { minyear: 1900, maxyear: 2000 } }) - input 23373 ", function(assert) {
  148. var $fixture = $("#qunit-fixture");
  149. $fixture.append('<input type="text" id="testmask" />');
  150. var testmask = document.getElementById("testmask");
  151. Inputmask("dd/mm/yyyy", {
  152. yearrange: {
  153. minyear: 1900,
  154. maxyear: 2000
  155. }
  156. }).mask(testmask);
  157. testmask.focus();
  158. $("#testmask").Type("23373");
  159. assert.equal(testmask.value, "23/03/1973", "Result " + testmask.value);
  160. });
  161. qunit.test("inputmask(\"hh:mm\") - add remove add", function(assert) {
  162. var $fixture = $("#qunit-fixture");
  163. $fixture.append('<input type="text" id="testmask" />');
  164. var testmask = document.getElementById("testmask");
  165. Inputmask('hh:mm', {
  166. clearIncomplete: true
  167. }).mask(testmask);
  168. testmask.inputmask.remove();
  169. Inputmask('hh:mm', {
  170. clearIncomplete: true
  171. }).mask(testmask);
  172. testmask.focus();
  173. $("#testmask").Type("abcdef");
  174. $("#testmask").Type("23:50");
  175. assert.equal(testmask.value, "23:50", "Result " + testmask.value);
  176. });
  177. qunit.test("inputmask(\"mm/yyyy\") - input 31973", function(assert) {
  178. var $fixture = $("#qunit-fixture");
  179. $fixture.append('<input type="text" id="testmask" />');
  180. var testmask = document.getElementById("testmask");
  181. Inputmask("mm/yyyy").mask(testmask);
  182. testmask.focus();
  183. $("#testmask").Type("31973");
  184. assert.equal(testmask.value, "03/1973", "Result " + testmask.value);
  185. });
  186. qunit.test("inputmask(\"mm/dd/yyyy\") - select some input 1 - Guamaso", function(assert) {
  187. var $fixture = $("#qunit-fixture");
  188. $fixture.append('<input type="text" id="testmask" />');
  189. var testmask = document.getElementById("testmask");
  190. Inputmask("mm/dd/yyyy").mask(testmask);
  191. testmask.focus();
  192. $.caret(testmask, 0, 5);
  193. $("#testmask").Type("1");
  194. assert.equal(testmask.value, "1m/dd/yyyy", "Result " + testmask.value);
  195. });
  196. qunit.test("inputmask(\"dd/mm/yyyy\") - input 2331973 - remove 23", function(assert) {
  197. var $fixture = $("#qunit-fixture");
  198. $fixture.append('<input type="text" id="testmask" />');
  199. var testmask = document.getElementById("testmask");
  200. Inputmask("dd/mm/yyyy").mask(testmask);
  201. testmask.focus();
  202. $("#testmask").Type("23031973");
  203. $.caret(testmask, 0, 2);
  204. $("#testmask").SendKey(Inputmask.keyCode.DELETE);
  205. assert.equal(testmask.value, "dd/03/1973", "Result " + testmask.value);
  206. });
  207. qunit.test("inputmask(\"dd/mm/yyyy\") - input 01011000 - Skiv22", function(assert) {
  208. var $fixture = $("#qunit-fixture");
  209. $fixture.append('<input type="text" id="testmask" />');
  210. var testmask = document.getElementById("testmask");
  211. Inputmask("dd/mm/yyyy", {
  212. yearrange: {
  213. minyear: 1000,
  214. maxyear: 2099
  215. }
  216. }).mask(testmask);
  217. testmask.focus();
  218. $("#testmask").Type("01011000");
  219. assert.equal(testmask.value, "01/01/1000", "Result " + testmask.value);
  220. });
  221. qunit.test("inputmask(\"dd/mm/yyyy\", { yearrange: { minyear: 1900, maxyear: 2016 } })", function(assert) {
  222. var $fixture = $("#qunit-fixture");
  223. $fixture.append('<input type="text" id="testmask" />');
  224. var testmask = document.getElementById("testmask");
  225. Inputmask("dd/mm/yyyy", {
  226. yearrange: {
  227. minyear: 1900,
  228. maxyear: 2016
  229. }
  230. }).mask(testmask);
  231. testmask.focus();
  232. $("#testmask").Type("23373");
  233. assert.equal(testmask.value, "23/03/1973", "Result " + testmask.value);
  234. });
  235. qunit.test("inputmask(\"dd/mm/yyyy\", { yearrange: { minyear: 1900, maxyear: 2017 } })", function(assert) {
  236. var $fixture = $("#qunit-fixture");
  237. $fixture.append('<input type="text" id="testmask" />');
  238. var testmask = document.getElementById("testmask");
  239. Inputmask("dd/mm/yyyy", {
  240. yearrange: {
  241. minyear: 1900,
  242. maxyear: 2017
  243. }
  244. }).mask(testmask);
  245. testmask.focus();
  246. $("#testmask").Type("23373");
  247. assert.equal(testmask.value, "23/03/1973", "Result " + testmask.value);
  248. });
  249. qunit.test("inputmask(\"dd/mm/yyyy\", { yearrange: { minyear: 1900, maxyear: 2018 } })", function(assert) {
  250. var $fixture = $("#qunit-fixture");
  251. $fixture.append('<input type="text" id="testmask" />');
  252. var testmask = document.getElementById("testmask");
  253. Inputmask("dd/mm/yyyy", {
  254. yearrange: {
  255. minyear: 1900,
  256. maxyear: 2018
  257. }
  258. }).mask(testmask);
  259. testmask.focus();
  260. $("#testmask").Type("23373");
  261. assert.equal(testmask.value, "23/03/1973", "Result " + testmask.value);
  262. });
  263. qunit.test("inputmask(\"dd/mm/yyyy\", { yearrange: { minyear: 1900, maxyear: 2019 } })", function(assert) {
  264. var $fixture = $("#qunit-fixture");
  265. $fixture.append('<input type="text" id="testmask" />');
  266. var testmask = document.getElementById("testmask");
  267. Inputmask("dd/mm/yyyy", {
  268. yearrange: {
  269. minyear: 1900,
  270. maxyear: 2019
  271. }
  272. }).mask(testmask);
  273. testmask.focus();
  274. $("#testmask").Type("23373");
  275. assert.equal(testmask.value, "23/03/1973", "Result " + testmask.value);
  276. });
  277. qunit.test("inputmask(\"dd/mm/yyyy\", { yearrange: { minyear: 1900, maxyear: 2018 } }) -- 2012", function(assert) {
  278. var $fixture = $("#qunit-fixture");
  279. $fixture.append('<input type="text" id="testmask" />');
  280. var testmask = document.getElementById("testmask");
  281. Inputmask("dd/mm/yyyy", {
  282. yearrange: {
  283. minyear: 1900,
  284. maxyear: 2018
  285. }
  286. }).mask(testmask);
  287. testmask.focus();
  288. $("#testmask").Type("23312");
  289. assert.equal(testmask.value, "23/03/2012", "Result " + testmask.value);
  290. });
  291. };