-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathfieldTextArea.spec.js
98 lines (76 loc) · 2.44 KB
/
fieldTextArea.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
import { expect } from "chai";
import { createVueField, trigger, checkAttribute } from "../util";
import Vue from "vue";
import FieldTextArea from "src/fields/core/fieldTextArea.vue";
Vue.component("FieldTextArea", FieldTextArea);
let el, vm, field;
function createField(test, schema = {}, model = null, disabled = false, options) {
[ el, vm, field ] = createVueField(test, "fieldTextArea", schema, model, disabled, options);
}
describe("fieldTextArea.vue", function() {
describe("check template", () => {
let schema = {
type: "textarea",
label: "Description",
model: "desc",
max: 500,
placeholder: "Field placeholder",
readonly: false,
fieldClasses: ["applied-class", "another-class"]
};
let model = { desc: "Lorem ipsum dolor sit amet, consectetur adipiscing elit." };
let input;
before( () => {
createField(this, schema, model, false);
input = el.getElementsByTagName("textarea")[0];
});
it("should contain a textarea element", () => {
expect(field).to.be.exist;
expect(field.$el).to.be.exist;
expect(input).to.be.defined;
expect(input.classList.contains("form-control")).to.be.true;
expect(input.rows).to.be.equal(2); // default value is 2
expect(input.maxLength).to.be.equal(500);
});
it("should change rows to 4", (done) => {
Vue.set(field.schema, "rows", 4);
vm.$nextTick( () => {
expect(input.rows).to.be.equal(4);
done();
});
});
it("should contain the value", (done) => {
vm.$nextTick( () => {
expect(input.value).to.be.equal(model.desc);
done();
});
});
describe("check optional attribute", () => {
let attributes = ["disabled", "placeholder", "readonly", "inputName"];
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.desc = "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.desc).to.be.equal("John Smith");
done();
});
});
it("should have 2 classes", () => {
expect(input.className.indexOf("applied-class")).not.to.be.equal(-1);
expect(input.className.indexOf("another-class")).not.to.be.equal(-1);
});
});
});