forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldInput.spec.js
125 lines (99 loc) · 3.04 KB
/
fieldInput.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { expect } from "chai";
import { createVueField, trigger, checkAttribute } from "../util";
import Vue from "vue";
import fieldInput from "src/fields/fieldInput.vue";
Vue.component("fieldInput", fieldInput);
let el, vm, field;
function createField(test, schema = {}, model = null, disabled = false, options) {
[el, vm, field] = createVueField(test, "fieldInput", schema, model, disabled, options);
}
describe("fieldInput.vue", function() {
describe("check template", () => {
let schema = {
type: "input",
inputType: "text",
label: "Name",
model: "name",
autocomplete: "off",
placeholder: "Field placeholder",
readonly: false
};
let model = { name: "John Doe" };
let input;
before(() => {
createField(this, schema, model, false);
input = el.getElementsByTagName("input")[0];
});
it("should contain an input text element", () => {
expect(field).to.be.exist;
expect(field.$el).to.be.exist;
expect(input).to.be.defined;
expect(input.type).to.be.equal("text");
expect(input.classList.contains("form-control")).to.be.true;
});
it("should contain the value", (done) => {
vm.$nextTick(() => {
expect(input.value).to.be.equal("John Doe");
done();
});
});
let inputTypes = new Map([
["text", ["autocomplete", "disabled", "placeholder", "readonly"]],
["password", ["autocomplete", "disabled", "placeholder", "readonly"]],
["checkbox", ["autocomplete", "disabled"]],
// ["radio", [] ],
// ["button", [] ],
// ["submit", [] ],
// ["reset", [] ],
// ["file", [] ],
// ["hidden", [] ],
// ["image", [] ],
// ["datetime", ],
// ["datetime", ],
// ["date", ],
// ["month", ],
// ["time", ],
// ["week", ],
["number", ["autocomplete", "disabled", "placeholder", "readonly"]],
// ["range", ["autocomplete"]],
["email", ["autocomplete", "disabled", "placeholder", "readonly"]],
["url", ["autocomplete", "disabled", "placeholder", "readonly"]],
// ["search", ],
["tel", ["autocomplete", "disabled", "placeholder", "readonly"]],
["color", ["autocomplete"]]
]);
for (let [inputType, attributes] of inputTypes) {
describe("change type of input", () => {
it("should become a " + inputType, function(done) {
field.schema.inputType = inputType;
vm.$nextTick(() => {
expect(input.type).to.be.equal(inputType);
done();
});
});
describe("check optional attribute", () => {
attributes.forEach(function(name) {
it("should set " + name, function(done) {
checkAttribute(name, vm, input, field, schema, done);
});
});
});
});
}
it("input value should be the model value after changed", (done) => {
model.name = "Jane Doe";
vm.$nextTick(() => {
expect(input.value).to.be.equal("Jane Doe");
done();
});
});
it("model value should be the input value if changed", (done) => {
input.value = "John Smith";
trigger(input, "input");
vm.$nextTick(() => {
expect(model.name).to.be.equal("John Smith");
done();
});
});
});
});