From 497620f95e6cb3a903996a60613b9a13ebd2238f Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Fri, 22 Apr 2016 10:07:47 +0200 Subject: [PATCH] Fixes #156: Propagate resolved schema definitions to field components. (#157) --- playground/samples/large.js | 23 +++++++++++++---------- src/components/fields/SchemaField.js | 4 ++-- test/Form_test.js | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/playground/samples/large.js b/playground/samples/large.js index e5ead45133..8e5150d6c3 100644 --- a/playground/samples/large.js +++ b/playground/samples/large.js @@ -8,6 +8,9 @@ function largeEnum(n) { module.exports = { schema: { + definitions: { + largeEnum: {type: "string", enum: largeEnum(100)} + }, title: "A rather large form", type: "object", properties: { @@ -15,16 +18,16 @@ module.exports = { type: "string", title: "Some string", }, - choice1: {type: "string", enum: largeEnum(100)}, - choice2: {type: "string", enum: largeEnum(100)}, - choice3: {type: "string", enum: largeEnum(100)}, - choice4: {type: "string", enum: largeEnum(100)}, - choice5: {type: "string", enum: largeEnum(100)}, - choice6: {type: "string", enum: largeEnum(100)}, - choice7: {type: "string", enum: largeEnum(100)}, - choice8: {type: "string", enum: largeEnum(100)}, - choice9: {type: "string", enum: largeEnum(100)}, - choice10: {type: "string", enum: largeEnum(100)}, + choice1: {$ref: "#/definitions/largeEnum"}, + choice2: {$ref: "#/definitions/largeEnum"}, + choice3: {$ref: "#/definitions/largeEnum"}, + choice4: {$ref: "#/definitions/largeEnum"}, + choice5: {$ref: "#/definitions/largeEnum"}, + choice6: {$ref: "#/definitions/largeEnum"}, + choice7: {$ref: "#/definitions/largeEnum"}, + choice8: {$ref: "#/definitions/largeEnum"}, + choice9: {$ref: "#/definitions/largeEnum"}, + choice10: {$ref: "#/definitions/largeEnum"}, } }, uiSchema: {}, diff --git a/src/components/fields/SchemaField.js b/src/components/fields/SchemaField.js index 0e3dd42b7e..0187e1035f 100644 --- a/src/components/fields/SchemaField.js +++ b/src/components/fields/SchemaField.js @@ -132,7 +132,7 @@ function SchemaField(props) { return ( ); } diff --git a/test/Form_test.js b/test/Form_test.js index df2ab310d0..2a1f3f2297 100644 --- a/test/Form_test.js +++ b/test/Form_test.js @@ -230,6 +230,23 @@ describe("Form", () => { expect(node.querySelectorAll("input[type=text]")) .to.have.length.of(2); }); + + it("should propagate and handle a resolved schema definition", () => { + const schema = { + definitions: { + enumDef: {type: "string", enum: ["a", "b"]} + }, + type: "object", + properties: { + name: {$ref: "#/definitions/enumDef"} + }, + }; + + const {node} = createFormComponent({schema}); + + expect(node.querySelectorAll("option")) + .to.have.length.of(2); + }); }); describe("Defaults array items default propagation", () => {