123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- export default function(qunit, $, Inputmask) {
- qunit.module("keepStatic mask switching");
- qunit.test("{ mask: [\"+55-99-9999-9999\", \"+55-99-99999-9999\", ], keepStatic: true }", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: ["+55-99-9999-9999", "+55-99-99999-9999"],
- keepStatic: true
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("12123451234");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "+55-12-12345-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("{ mask: \"+55-99-9999|(99)-9999\", keepStatic: true } - type 12123451234", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: "+55-99-9999|(99)-9999",
- keepStatic: true
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("12123451234");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "+55-12-12345-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("{ mask: ['(99) 9999-9999', '(99) 99999-9999'] } - val('1212341234')", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: ['(99) 9999-9999', '(99) 99999-9999']
- }).mask(testmask);
- $("#testmask").val("1212341234");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "(12) 1234-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("{ mask: \"+55-99-9999|(99)-9999\", keepStatic: false } type 12123451234", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: "+55-99-9999|(99)-9999",
- keepStatic: false
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("12123451234");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "+55-12-12345-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("{ mask: [\"+55-99-9999-9999\", \"+55-99-99999-9999\", ], keepStatic: true } - type 12123451234 + backspace", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: ["+55-99-9999-9999", "+55-99-99999-9999"],
- keepStatic: true
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("12123451234");
- $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "+55-12-1234-5123", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("{ mask: [\"99-9999-99\",\"99-99999-99\"] } - type 12123412 + add 1 upfront", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: ["99-9999-99", "99-99999-99"]
- }).mask(testmask);
- $("#testmask").Type("12123412");
- $.caret(testmask, 0);
- $("#testmask").Type("1");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "11-21234-12", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("{ mask: [\"99-99999-9\",\"99-999999-9\"] } - type 121234561", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: ["99-99999-9", "99-999999-9"]
- }).mask(testmask);
- $("#testmask").Type("121234561");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12-123456-1", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("{ \"keepStatic\": true, greedy: false, mask: \"(99-9)|(99999)\" } - type 12345", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- "keepStatic": true,
- greedy: false,
- "mask": "(99-9)|(99999)"
- }).mask(testmask);
- $("#testmask").Type("12345");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12345", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("7|8 999 99 99 - hiddenman", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("7|8 999 99 99").mask(testmask);
- testmask.focus();
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "_ ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("7|8 999 99 99 type 7 - hiddenman", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("7|8 999 99 99").mask(testmask);
- $("#testmask").Type("7");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "7 ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("7|8 999 99 99 type 8 - hiddenman", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("7|8 999 99 99").mask(testmask);
- $("#testmask").Type("8");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "8 ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("(78)|(79) 999 99 99", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("(78)|(79) 999 99 99").mask(testmask);
- testmask.focus();
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "7_ ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("(78)|(79) 999 99 99 - type 5", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("(78)|(79) 999 99 99").mask(testmask);
- testmask.focus();
- $("#testmask").Type("5");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "75 ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("(78)|(74) 999 99 99", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("(78)|(74) 999 99 99").mask(testmask);
- testmask.focus();
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "7_ ___ __ __", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("5-9|(9a)-5 - keepstatic: false", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: "5-9|(9a)-5",
- keepStatic: false
- }).mask(testmask);
- testmask.focus();
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "5-_-5", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("['(99) 9999-9999', '(99) 9-9999-9999'] - type 12123412345 - 3m0", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: ['(99) 9999-9999', '(99) 9-9999-9999'],
- removeMaskOnSubmit: false,
- clearmaskonlostfocus: true
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("12123412345")
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "(12) 1-2341-2345", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("['(99) 9999-9999', '(99) 9-9999-9999'] - type 12123412345 - backspace - 3m0", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- mask: ['(99) 9999-9999', '(99) 9-9999-9999'],
- removeMaskOnSubmit: false,
- clearmaskonlostfocus: true
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("12123412345")
- $("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "(12) 1234-1234", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("(99 99)|(*****) keepStatic false - type 12 abc", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("(99 99)|(*****)", {
- keepStatic: false
- }).mask(testmask);
- $("#testmask").Type("12 abc");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12 __", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("(99 99)|(*****) keepStatic false - type 12 123", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("(99 99)|(*****)", {
- keepStatic: false
- }).mask(testmask);
- $("#testmask").Type("12 123");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12 12", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("(99 99)|(*****) keepStatic true - type 1212", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("(99 99)|(*****)", {
- keepStatic: true
- }).mask(testmask);
- $("#testmask").Type("1212");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12 12", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("(99 99)|(*****) keepStatic true - type 12123", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("(99 99)|(*****)", {
- keepStatic: true
- }).mask(testmask);
- $("#testmask").Type("12123");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "12123", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("(99 99)|(*****) keepStatic true - type abcde", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask("(99 99)|(*****)", {
- keepStatic: true
- }).mask(testmask);
- $("#testmask").Type("abcde");
- assert.equal(document.getElementById("testmask").inputmask._valueGet(), "abcde", "Result " + document.getElementById("testmask").inputmask._valueGet());
- });
- qunit.test("[\"9+9\", \"(99)+99+99\"] keepStatic true - type 123 - ishytow", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask(["9+9", "(99)+99+99"], {
- keepStatic: true
- }).mask(testmask);
- $("#testmask").Type("123");
- assert.equal(testmask.value, "(12)+3_+__", "Result " + testmask.value);
- });
- qunit.test("[\"9+9\", \"99+99\", \"(99)+99+99\"] keepStatic true - type 12345 - ishytow", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask(["9+9", "99+99", "(99)+99+99"], {
- keepStatic: true
- }).mask(testmask);
- $("#testmask").Type("12345");
- assert.equal(testmask.value, "(12)+34+5_", "Result " + testmask.value);
- });
- qunit.test("[\"9+9\", \"99+99\", \"(99)+99+99\"] keepStatic true - type 1234 - ishytow", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask(["9+9", "99+99", "(99)+99+99"], {
- keepStatic: true
- }).mask(testmask);
- $("#testmask").Type("1234");
- assert.equal(testmask.value, "12+34", "Result " + testmask.value);
- });
- qunit.test("[\"999-9999\", \"(999) 999-9999\", \"1-(999) 999-9999\"] - 999-9999 - carylewis", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask(["999-9999", "(999) 999-9999", "1-(999) 999-9999"]).mask(testmask);
- $("#testmask").Type("1231234");
- assert.equal(testmask.value, "123-1234", "Result " + testmask.value);
- });
- qunit.test("[\"999-9999\", \"(999) 999-9999\", \"1-(999) 999-9999\"] - (999) 999-9999 - carylewis", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask(["999-9999", "(999) 999-9999", "1-(999) 999-9999"]).mask(testmask);
- $("#testmask").Type("1231231234");
- assert.equal(testmask.value, "(123) 123-1234", "Result " + testmask.value);
- });
- qunit.test("[\"999-9999\", \"(999) 999-9999\", \"1-(999) 999-9999\"] - 1-(999) 999-9999 - carylewis", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask(["999-9999", "(999) 999-9999", "1-(999) 999-9999"]).mask(testmask);
- $("#testmask").Type("11231231234");
- assert.equal(testmask.value, "1-(123) 123-1234", "Result " + testmask.value);
- });
- };
|