Skip to content

Commit 9cf627c

Browse files
committed
More tests
1 parent facc6b2 commit 9cf627c

File tree

2 files changed

+89
-36
lines changed

2 files changed

+89
-36
lines changed

src/formGenerator.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
thead
44
tbody
55
tr(v-for="field in fields", v-if="fieldVisible(field)", :class="getFieldRowClasses(field)")
6-
td
6+
td
77
span.help(v-if="field.help")
88
i.fa.fa-question-circle
99
.helpText {{{field.help}}}

test/unit/specs/VueFormGenerator.spec.js

+88-35
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ describe("VueFormGenerator.vue", () => {
5555
readonly: false,
5656
featured: false,
5757
required: false,
58-
disabled: false,
59-
hint: null,
60-
helpText: null,
61-
placeholder: "User's name"
58+
disabled: false
6259
}
6360
]
6461
};
@@ -112,53 +109,109 @@ describe("VueFormGenerator.vue", () => {
112109
})
113110
});
114111

112+
it("should be add a custom classes", (done) => {
113+
vm.$set("schema.fields[0].styleClasses", "classA");
114+
vm.$nextTick(() => {
115+
expect(tr.classList.contains("classA")).to.be.true;
116+
done();
117+
})
118+
});
119+
120+
it("should be add more custom classes", (done) => {
121+
vm.$set("schema.fields[0].styleClasses", [ "classB", "classC" ]);
122+
vm.$nextTick(() => {
123+
expect(tr.classList.contains("classB")).to.be.true;
124+
expect(tr.classList.contains("classC")).to.be.true;
125+
done();
126+
})
127+
});
128+
115129
});
116-
/*
117-
describe("check form row classes", () => {
130+
131+
describe("check form row caption cell", () => {
132+
let tr, tdCaption, tdField;
118133
let schema = {
119134
fields: [
120135
{
121136
type: "text",
122137
label: "Name",
123138
model: "name",
124-
readonly: false,
125-
featured: false,
126-
required: false,
127-
disabled: false,
128-
hint: null,
129-
helpText: null,
130-
placeholder: "User's name"
139+
help: null
131140
}
132141
]
133142
};
134-
let model = null;
135143

136-
beforeEach((done) => {
137-
createFormGenerator(schema, model, {}, (_el, _vm) => {
138-
el = _el;
139-
vm = _vm;
144+
before( () => {
145+
createFormGenerator(schema);
146+
tr = el.getElementsByTagName("tr")[0];
147+
tdCaption = tr.getElementsByTagName("td")[0];
148+
tdField = tr.getElementsByTagName("td")[1];
149+
});
150+
151+
it("should be text of cell is the name of field", () => {
152+
expect(tdCaption).to.be.exist;
153+
expect(tdCaption.textContent).to.be.equal("Name");
154+
});
155+
156+
it("should be a question icon if has helpText", (done) => {
157+
vm.schema.fields[0].help = "Sample help";
158+
vm.$nextTick(() => {
159+
let span = tr.querySelector(".help");
160+
expect(span).to.be.exist;
161+
expect(span.querySelector("i")).to.be.exist;
162+
expect(span.querySelector(".helpText")).to.be.exist;
163+
expect(span.querySelector(".helpText").textContent).to.be.equal("Sample help");
140164
done();
141-
});
165+
})
142166
});
143167

144-
it("should be create a row and an input text field with empty value", () => {
145-
// check row
146-
let tr = el.getElementsByTagName("tr")[0];
147-
expect(tr).to.be.exist;
148-
expect(tr.classList.length).to.be.equal(0);
168+
});
149169

150-
let tdCaption = tr.getElementsByTagName("td")[0];
151-
expect(tdCaption).to.be.exist;
152-
expect(tdCaption.textContent.trim()).to.be.equal("Name"); // TODO why need to trim?
153-
154-
let tdField = tr.getElementsByTagName("td")[1];
155-
expect(tdField).to.be.exist;
156-
157-
let input = tdField.getElementsByTagName("input")[0];
158-
expect(input).to.be.exist;
159-
expect(input.type).to.be.equal("text");
170+
describe("check form row field cell", () => {
171+
let tr, tdField;
172+
let schema = {
173+
fields: [
174+
{
175+
type: "text",
176+
label: "Name",
177+
model: "name",
178+
hint: "Hint text",
179+
errors: [],
180+
placeholder: "User's name"
181+
}
182+
]
183+
};
184+
185+
before( () => {
186+
createFormGenerator(schema);
187+
tr = el.getElementsByTagName("tr")[0];
188+
tdField = tr.getElementsByTagName("td")[1];
189+
});
190+
191+
it("should be a .field-wrap div", () => {
192+
expect(tdField.querySelector(".field-wrap")).to.be.exist;
193+
});
194+
195+
it("should be a hint div if hint is not null", () => {
196+
let hint = tdField.querySelector(".hint");
197+
expect(hint).to.be.exist;
198+
expect(hint.textContent).to.be.equal("Hint text");
160199
});
161200

162-
}); */
201+
it("should be .errors div if there are errors in fields", (done) => {
202+
vm.schema.fields[0].errors.push("Some error!", "Another error!");
203+
vm.$nextTick(() => {
204+
let div = tdField.querySelector(".errors");
205+
expect(div).to.be.exist;
206+
let errors = div.querySelectorAll("span");
207+
expect(errors.length).to.be.equal(2);
208+
expect(errors[0].textContent).to.be.equal("Some error!");
209+
expect(errors[1].textContent).to.be.equal("Another error!");
210+
done();
211+
});
212+
});
213+
214+
});
215+
163216

164217
});

0 commit comments

Comments
 (0)