Skip to content

Commit a6976c6

Browse files
committed
Fixed fialing test.
1 parent 7cbc8f6 commit a6976c6

File tree

2 files changed

+57
-53
lines changed

2 files changed

+57
-53
lines changed

src/components/widgets/CheckboxesWidget.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { PropTypes } from "react";
44
function selectValue(value, selected, all) {
55
const at = all.indexOf(value);
66
const updated = selected.slice(0, at).concat(value, selected.slice(at));
7-
// As inserting values at predefined index positions doesn't work we empty
7+
// As inserting values at predefined index positions doesn't work with empty
88
// arrays, we need to reorder the updated selection to match the initial order
99
return updated.sort((a, b) => {
1010
const ai = all.findIndex(x => x === a);
@@ -20,14 +20,14 @@ function deselectValue(value, selected) {
2020
function CheckboxesWidget(props) {
2121
const {id, disabled, options, value, onChange} = props;
2222
return (
23-
<div id={id}>{
23+
<div className="checkboxes" id={id}>{
2424
options.map((option, index) => {
2525
const checked = value.indexOf(option.value) !== -1;
2626
return (
2727
<div key={index} className="checkbox">
2828
<label>
2929
<input type="checkbox"
30-
id={`${id}_${option.label}`}
30+
id={`${id}_${index}`}
3131
checked={checked}
3232
disabled={disabled}
3333
onChange={(event) => {

test/ArrayField_test.js

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -192,73 +192,77 @@ describe("ArrayField", () => {
192192
value: ["foo", "fuzz"]
193193
};
194194

195-
it("should be possible to specify a custom widget", () => {
196-
const uiSchema = {
197-
"ui:widget": "checkboxes"
198-
};
199-
const {node} = createFormComponent({schema, uiSchema});
200-
d(node);
195+
describe("Select multiple widget", () => {
196+
it("should render a select widget", () => {
197+
const {node} = createFormComponent({schema});
201198

202-
expect(node.querySelectorAll("select"))
203-
.to.have.length.of(1);
204-
});
199+
expect(node.querySelectorAll("select"))
200+
.to.have.length.of(1);
201+
});
205202

206-
it("should render a select widget", () => {
207-
const {node} = createFormComponent({schema});
203+
it("should render a select widget with a label", () => {
204+
const {node} = createFormComponent({schema});
208205

209-
expect(node.querySelectorAll("select"))
210-
.to.have.length.of(1);
211-
});
206+
expect(node.querySelector(".field label").textContent)
207+
.eql("My field");
208+
});
212209

213-
it("should render a select widget with a label", () => {
214-
const {node} = createFormComponent({schema});
210+
it("should render a select widget with multiple attribute", () => {
211+
const {node} = createFormComponent({schema});
215212

216-
expect(node.querySelector(".field label").textContent)
217-
.eql("My field");
218-
});
219-
220-
it("should render a select widget with multiple attribute", () => {
221-
const {node} = createFormComponent({schema});
213+
expect(node.querySelector(".field select").getAttribute("multiple"))
214+
.not.to.be.null;
215+
});
222216

223-
expect(node.querySelector(".field select").getAttribute("multiple"))
224-
.not.to.be.null;
225-
});
217+
it("should render options", () => {
218+
const {node} = createFormComponent({schema});
226219

227-
it("should render options", () => {
228-
const {node} = createFormComponent({schema});
220+
expect(node.querySelectorAll("select option"))
221+
.to.have.length.of(3);
222+
});
229223

230-
expect(node.querySelectorAll("select option"))
231-
.to.have.length.of(3);
232-
});
224+
it("should handle a change event", () => {
225+
const {comp, node} = createFormComponent({schema});
233226

234-
it("should handle a change event", () => {
235-
const {comp, node} = createFormComponent({schema});
227+
Simulate.change(node.querySelector(".field select"), {
228+
target: {options: [
229+
{selected: true, value: "foo"},
230+
{selected: true, value: "bar"},
231+
{selected: false, value: "fuzz"},
232+
]}
233+
});
236234

237-
Simulate.change(node.querySelector(".field select"), {
238-
target: {options: [
239-
{selected: true, value: "foo"},
240-
{selected: true, value: "bar"},
241-
{selected: false, value: "fuzz"},
242-
]}
235+
expect(comp.state.formData).eql(["foo", "bar"]);
243236
});
244237

245-
expect(comp.state.formData).eql(["foo", "bar"]);
246-
});
238+
it("should fill field with data", () => {
239+
const {node} = createFormComponent({schema, formData: ["foo", "bar"]});
247240

248-
it("should fill field with data", () => {
249-
const {node} = createFormComponent({schema, formData: ["foo", "bar"]});
241+
const options = node.querySelectorAll(".field select option");
242+
expect(options).to.have.length.of(3);
243+
expect(options[0].selected).eql(true); // foo
244+
expect(options[1].selected).eql(true); // bar
245+
expect(options[2].selected).eql(false); // fuzz
246+
});
247+
248+
it("should render the select widget with the expected id", () => {
249+
const {node} = createFormComponent({schema});
250250

251-
const options = node.querySelectorAll(".field select option");
252-
expect(options).to.have.length.of(3);
253-
expect(options[0].selected).eql(true); // foo
254-
expect(options[1].selected).eql(true); // bar
255-
expect(options[2].selected).eql(false); // fuzz
251+
expect(node.querySelector("select").id).eql("root");
252+
});
256253
});
257254

258-
it("should render the select widget with the expected id", () => {
259-
const {node} = createFormComponent({schema});
255+
describe("CheckboxesWidget", () => {
256+
const uiSchema = {
257+
"ui:widget": "checkboxes"
258+
};
260259

261-
expect(node.querySelector("select").id).eql("root");
260+
it("should be possible to specify a custom widget", () => {
261+
const {node} = createFormComponent({schema, uiSchema});
262+
263+
expect(node.querySelectorAll("[type=checkbox]"))
264+
.to.have.length.of(3);
265+
});
262266
});
263267
});
264268

0 commit comments

Comments
 (0)