Skip to content

Commit

Permalink
test: unit test for fieldCleave
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Aug 26, 2016
1 parent 841f20d commit 012ee91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions test/unit/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ module.exports = function(config) {
"https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.js",
"https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.4/js/ion.rangeSlider.js",
"https://rawgit.com/monterail/vue-multiselect/master/lib/vue-multiselect.min.js",
"https://rawgit.com/nosir/cleave.js/master/dist/cleave.min.js",
"https://rawgit.com/nosir/cleave.js/master/dist/cleave.js",
"https://nosir.github.io/cleave.js/lib/cleave-phone.i18n.js",
"https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/8.5.1/nouislider.js",
"https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.4.0/pikaday.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.4.0/pikaday.js",
"https://maps.googleapis.com/maps/api/js?key=AIzaSyCEz-sX9bRJorDS-D_JL0JkZVZe2gzoUMw&libraries=places",

"./index.js"
Expand Down
34 changes: 25 additions & 9 deletions test/unit/specs/fields/fieldCleave.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ describe("fieldCleave.vue", function() {
type: "masked",
label: "Phone",
model: "phone",
phone: true,
phoneRegionCode: "HU",
readonly: false,
placeholder: "Field placeholder"
placeholder: "Field placeholder",
cleaveOptions: {
phone: true,
phoneRegionCode: "HU",
}
};
let model = { phone: "(30) 123-4567" };
let model = { phone: "30 123 4567" };
let input;

before( () => {
Expand All @@ -46,7 +48,7 @@ describe("fieldCleave.vue", function() {

it("should contain the value", (done) => {
vm.$nextTick( () => {
expect(input.value).to.be.equal("(30) 123-4567");
expect(input.value).to.be.equal("30 123 4567");
done();
});
});
Expand All @@ -55,6 +57,7 @@ describe("fieldCleave.vue", function() {
schema.readonly = true;
vm.$nextTick( () => {
expect(input.readOnly).to.be.true;
schema.readonly = false;
done();
});
});
Expand All @@ -63,30 +66,43 @@ describe("fieldCleave.vue", function() {
field.disabled = true;
vm.$nextTick( () => {
expect(input.disabled).to.be.true;
field.disabled = false;
done();
});
});

it("input value should be the model value after changed", (done) => {
model.phone = "(70) 555-4433";
model.phone = "70 555 4433";
vm.$nextTick( () => {
expect(input.value).to.be.equal("(70) 555-4433");
expect(input.value).to.be.equal("70 555 4433");
done();
});

});

it("model value should be the input value if changed", (done) => {
input.value = "(21) 888-6655";
input.value = "21 888 6655";
trigger(input, "input");

vm.$nextTick( () => {
expect(model.phone).to.be.equal("(21) 888-6655");
expect(model.phone).to.be.equal("21 888 6655");
done();
});

});

it("should be formatted data in model", (done) => {
field.cleave.setRawValue("301234567");
expect(input.value).to.be.equal("30 123 4567");
trigger(input, "change");

vm.$nextTick( () => {
expect(model.phone).to.be.equal("30 123 4567");
done();
});

});

});

});

0 comments on commit 012ee91

Please sign in to comment.