Skip to content

Commit 22d98b4

Browse files
committed
✅ test: add fieldCleave & fieldPikaday tests
1 parent 5991625 commit 22d98b4

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { expect } from "chai";
2+
import { createVueField, trigger } from "../util";
3+
4+
import Vue from "vue";
5+
import FieldCleave from "src/fields/fieldCleave.vue";
6+
7+
Vue.component("FieldCleave", FieldCleave);
8+
9+
let el, vm, field;
10+
11+
function createField(schema = {}, model = null, disabled = false, options) {
12+
[ el, vm, field ] = createVueField("fieldCleave", schema, model, disabled, options);
13+
}
14+
15+
describe("fieldCleave.vue", () => {
16+
17+
describe("check template", () => {
18+
let schema = {
19+
type: "masked",
20+
label: "Phone",
21+
model: "phone",
22+
phone: true,
23+
phoneRegionCode: 'HU',
24+
readonly: false,
25+
placeholder: "Field placeholder"
26+
};
27+
let model = { phone: "(30) 123-4567" };
28+
let input;
29+
30+
before( () => {
31+
createField(schema, model, false);
32+
input = el.getElementsByTagName("input")[0];
33+
});
34+
35+
it("should contain an masked input element", () => {
36+
expect(field).to.be.exist;
37+
expect(field.$el).to.be.exist;
38+
39+
expect(input).to.be.defined;
40+
expect(input.type).to.be.equal("text");
41+
expect(input.classList.contains("form-control")).to.be.true;
42+
expect(input.placeholder).to.be.equal(schema.placeholder);
43+
expect(input.readOnly).to.be.false;
44+
expect(input.disabled).to.be.false;
45+
});
46+
47+
it("should contain the value", (done) => {
48+
vm.$nextTick( () => {
49+
expect(input.value).to.be.equal("(30) 123-4567");
50+
done();
51+
});
52+
});
53+
54+
it("should set readOnly", (done) => {
55+
schema.readonly = true;
56+
vm.$nextTick( () => {
57+
expect(input.readOnly).to.be.true;
58+
done();
59+
});
60+
});
61+
62+
it("should set disabled", (done) => {
63+
field.disabled = true;
64+
vm.$nextTick( () => {
65+
expect(input.disabled).to.be.true;
66+
done();
67+
});
68+
});
69+
70+
it("input value should be the model value after changed", (done) => {
71+
model.phone = "(70) 555-4433";
72+
vm.$nextTick( () => {
73+
expect(input.value).to.be.equal("(70) 555-4433");
74+
done();
75+
});
76+
77+
});
78+
79+
it("model value should be the input value if changed", (done) => {
80+
input.value = "(21) 888-6655";
81+
trigger(input, "input");
82+
83+
vm.$nextTick( () => {
84+
expect(model.phone).to.be.equal("(21) 888-6655");
85+
done();
86+
});
87+
88+
});
89+
90+
});
91+
92+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { expect } from "chai";
2+
import { createVueField, trigger } from "../util";
3+
import moment from "moment";
4+
5+
import Vue from "vue";
6+
import FieldPikaday from "src/fields/fieldPikaday.vue";
7+
8+
Vue.component("FieldPikaday", FieldPikaday);
9+
10+
let el, vm, field;
11+
12+
function createField(schema = {}, model = null, disabled = false, options) {
13+
[ el, vm, field ] = createVueField("fieldPikaday", schema, model, disabled, options);
14+
}
15+
16+
describe.only("fieldPikaday.vue", () => {
17+
18+
describe("check template", () => {
19+
let schema = {
20+
type: "dateTime",
21+
label: "Event",
22+
model: "event"
23+
};
24+
let model = { event: 1462799081231 };
25+
let input;
26+
27+
before( () => {
28+
createField(schema, model, false);
29+
input = el.getElementsByTagName("input")[0];
30+
});
31+
32+
it("should contain an input text element", () => {
33+
expect(field).to.be.exist;
34+
expect(field.$el).to.be.exist;
35+
36+
expect(input).to.be.defined;
37+
expect(input.type).to.be.equal("text");
38+
expect(input.classList.contains("form-control")).to.be.true;
39+
expect(input.disabled).to.be.false;
40+
});
41+
42+
it("should contain the value", (done) => {
43+
vm.$nextTick( () => {
44+
expect(input.value).to.be.equal( moment(1462799081231).format("YYYY-MM-DD HH:mm:ss") );
45+
done();
46+
});
47+
});
48+
49+
it("should set disabled", (done) => {
50+
field.disabled = true;
51+
vm.$nextTick( () => {
52+
expect(input.disabled).to.be.true;
53+
done();
54+
});
55+
});
56+
57+
it("input value should be the model value after changed", (done) => {
58+
model.event = 1234567890123;
59+
vm.$nextTick( () => {
60+
expect(input.value).to.be.equal( moment(1234567890123).format("YYYY-MM-DD HH:mm:ss") );
61+
done();
62+
});
63+
64+
});
65+
66+
it("model value should be the input value if changed", (done) => {
67+
input.value = moment(1420194153000).format("YYYY-MM-DD HH:mm:ss");
68+
trigger(input, "input");
69+
70+
vm.$nextTick( () => {
71+
expect(model.event).to.be.equal(1420194153000);
72+
done();
73+
});
74+
75+
});
76+
77+
});
78+
79+
});

0 commit comments

Comments
 (0)