Skip to content

Commit f35a1dd

Browse files
committed
Added more tests.
1 parent a6976c6 commit f35a1dd

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

test/ArrayField_test.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,51 @@ describe("ArrayField", () => {
257257
"ui:widget": "checkboxes"
258258
};
259259

260-
it("should be possible to specify a custom widget", () => {
260+
it("should render the expected number of checkboxes", () => {
261261
const {node} = createFormComponent({schema, uiSchema});
262262

263263
expect(node.querySelectorAll("[type=checkbox]"))
264264
.to.have.length.of(3);
265265
});
266+
267+
it("should render the expected labels", () => {
268+
const {node} = createFormComponent({schema, uiSchema});
269+
270+
const labels = [].map.call(node.querySelectorAll(".checkbox label"),
271+
node => node.textContent);
272+
expect(labels).eql(["foo", "bar", "fuzz"]);
273+
});
274+
275+
it("should handle a change event", () => {
276+
const {comp, node} = createFormComponent({schema, uiSchema});
277+
278+
Simulate.change(node.querySelectorAll("[type=checkbox]")[0], {
279+
target: {checked: true}
280+
});
281+
Simulate.change(node.querySelectorAll("[type=checkbox]")[2], {
282+
target: {checked: true}
283+
});
284+
285+
expect(comp.state.formData).eql(["foo", "fuzz"]);
286+
});
287+
288+
it("should fill field with data", () => {
289+
const {node} = createFormComponent({
290+
schema,
291+
uiSchema,
292+
formData: ["foo", "fuzz"]
293+
});
294+
295+
const labels = [].map.call(node.querySelectorAll("[type=checkbox]"),
296+
node => node.checked);
297+
expect(labels).eql([true, false, true]);
298+
});
299+
300+
it("should render the widget with the expected id", () => {
301+
const {node} = createFormComponent({schema, uiSchema});
302+
303+
expect(node.querySelector(".checkboxes").id).eql("root");
304+
});
266305
});
267306
});
268307

0 commit comments

Comments
 (0)