Skip to content

Commit 3be0cc8

Browse files
author
Rémy HUBSCHER
committed
Add test for readonly and disabled.
1 parent 386bb3d commit 3be0cc8

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/components/widgets/FileWidget.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ class FileWidget extends Component {
9494
};
9595

9696
render() {
97-
const {multiple, id} = this.props;
98-
const {readonly, filesInfo} = this.state;
97+
const {multiple, id, readonly, disabled} = this.props;
98+
const {filesInfo} = this.state;
9999
return (
100100
<div>
101101
<p>
102102
<input
103103
id={id}
104104
type="file"
105-
readOnly={readonly}
105+
disabled={readonly || disabled}
106106
onChange={this.onChange}
107107
defaultValue=""
108108
multiple={multiple} />

test/uiSchema_test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import { expect } from "chai";
23
import React from "react";
34
import { Simulate } from "react-addons-test-utils";
@@ -135,6 +136,22 @@ describe("uiSchema", () => {
135136
}
136137
};
137138

139+
describe("file", () => {
140+
const uiSchema = {
141+
foo: {
142+
"ui:widget": "file"
143+
}
144+
};
145+
146+
it("should accept a uiSchema object", () => {
147+
const {node} = createFormComponent({schema, uiSchema});
148+
149+
expect(node.querySelectorAll("input[type=file]"))
150+
.to.have.length.of(1);
151+
});
152+
});
153+
154+
138155
describe("textarea", () => {
139156
const uiSchema = {
140157
foo: {
@@ -149,6 +166,7 @@ describe("uiSchema", () => {
149166
.to.have.length.of(1);
150167
});
151168

169+
152170
it("should support formData", () => {
153171
const {node} = createFormComponent({schema, uiSchema, formData: {
154172
foo: "a"
@@ -883,6 +901,14 @@ describe("uiSchema", () => {
883901
{"ui:disabled": true});
884902
});
885903

904+
it("should disabled a file widget", () => {
905+
const {node} = createFormComponent({
906+
schema: {type: "string", format: "data-url"},
907+
uiSchema: {"ui:disabled": true}});
908+
expect(node.querySelector("input[type=file]").hasAttribute("disabled"))
909+
.eql(true);
910+
});
911+
886912
it("should disable a textarea widget", () => {
887913
shouldBeDisabled("textarea",
888914
{type: "string"},
@@ -1048,6 +1074,15 @@ describe("uiSchema", () => {
10481074
{"ui:readonly": true});
10491075
});
10501076

1077+
it("should mark as readonly a file widget", () => {
1078+
// We mark a file widget as readonly by disabling it.
1079+
const {node} = createFormComponent({
1080+
schema: {type: "string", format: "data-url"},
1081+
uiSchema: {"ui:readonly": true}});
1082+
expect(node.querySelector("input[type=file]").hasAttribute("disabled"))
1083+
.eql(true);
1084+
});
1085+
10511086
it("should mark as readonly a textarea widget", () => {
10521087
shouldBeReadonly("textarea",
10531088
{type: "string"},

0 commit comments

Comments
 (0)