Skip to content

Commit

Permalink
✅ test: add fieldMasked unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Aug 24, 2016
1 parent 7bfffb1 commit 19f5d98
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/fields/fieldMasked.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
mixins: [ abstractField ],
ready() {
if ($.fn.mask)
$(this.$el).mask("destroy").mask(this.schema.mask, this.schema.maskOptions);
if ($.fn.mask) {
$(this.$el).unmask().mask(this.schema.mask, this.schema.maskOptions);
}
else
console.warn("JQuery MaskedInput library is missing. Please download from https://github.com/digitalBush/jquery.maskedinput and load the script in the HTML head section!");
}
Expand Down
34 changes: 32 additions & 2 deletions test/unit/specs/fields/fieldMasked.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("fieldMasked.vue", () => {

before( () => {
createField(schema, model, false);
vm.$appendTo(document.body);
input = el.getElementsByTagName("input")[0];
});

Expand All @@ -54,15 +55,25 @@ describe("fieldMasked.vue", () => {
schema.readonly = true;
vm.$nextTick( () => {
expect(input.readOnly).to.be.true;
done();

// Rollback
schema.readonly = false;
vm.$nextTick( () => {
done();
});
});
});

it("should set disabled", (done) => {
field.disabled = true;
vm.$nextTick( () => {
expect(input.disabled).to.be.true;
done();

// Rollback
field.disabled = false;
vm.$nextTick( () => {
done();
});
});
});

Expand All @@ -86,6 +97,25 @@ describe("fieldMasked.vue", () => {

});

it("should be formatted data in model", (done) => {
input.value = "123456789";
// Call the paste event what trigger the formatter
let $input = window.jQuery(input);
$input.trigger(window.jQuery.Event("paste"));

setTimeout( () => {
expect(input.value).to.be.equal("(12) 345-6789");
trigger(input, "input");

vm.$nextTick( () => {
expect(model.phone).to.be.equal("(12) 345-6789");
done();
});

}, 10);

});

});

});
5 changes: 1 addition & 4 deletions test/unit/specs/fields/fieldNoUiSlider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("fieldNoUiSlider.vue", () => {

before( () => {
createField(schema, model, false);
vm.$appendTo(document.body);
input = el.getElementsByClassName("slider")[0];
});

Expand All @@ -40,10 +41,6 @@ describe("fieldNoUiSlider.vue", () => {
expect(input.disabled).to.be.undefined;
});

before( () => {
vm.$appendTo(document.body);
});

it("should contain an handle element", (done) => {
if (window.noUiSlider) {
vm.$nextTick( () => {
Expand Down

0 comments on commit 19f5d98

Please sign in to comment.