diff --git a/packages/core/test/anyOf_test.js b/packages/core/test/anyOf_test.js index 5a4349456b..51e93d03d6 100644 --- a/packages/core/test/anyOf_test.js +++ b/packages/core/test/anyOf_test.js @@ -67,12 +67,17 @@ describe("anyOf", () => { }, }, { + $ref: "#/definitions/bar", + }, + ], + definitions: { + bar: { type: "object", properties: { foo: { type: "string", default: "defaultbar" }, }, }, - ], + }, }, }); sinon.assert.calledWithMatch(onChange.lastCall, { @@ -828,6 +833,46 @@ describe("anyOf", () => { expect(strInputs[1].value).eql("bar"); }); + it("should correctly set the label of the options", () => { + const schema = { + type: "object", + anyOf: [ + { + title: "Foo", + properties: { + foo: { type: "string" }, + }, + }, + { + properties: { + bar: { type: "string" }, + }, + }, + { + $ref: "#/definitions/baz", + }, + ], + definitions: { + baz: { + title: "Baz", + properties: { + baz: { type: "string" }, + }, + }, + }, + }; + + const { node } = createFormComponent({ + schema, + }); + + const $select = node.querySelector("select"); + + expect($select.options[0].text).eql("Foo"); + expect($select.options[1].text).eql("Option 2"); + expect($select.options[2].text).eql("Baz"); + }); + it("should correctly render mixed types for anyOf inside array items", () => { const schema = { type: "object", diff --git a/packages/core/test/oneOf_test.js b/packages/core/test/oneOf_test.js index 2060d99052..f606dfb689 100644 --- a/packages/core/test/oneOf_test.js +++ b/packages/core/test/oneOf_test.js @@ -66,13 +66,16 @@ describe("oneOf", () => { foo: { type: "string", default: "defaultfoo" }, }, }, - { + { $ref: "#/definitions/bar" }, + ], + definitions: { + bar: { type: "object", properties: { foo: { type: "string", default: "defaultbar" }, }, }, - ], + }, }, }); @@ -611,5 +614,45 @@ describe("oneOf", () => { expect($select.value).to.eql($select.options[1].value); }); + + it("should correctly set the label of the options", () => { + const schema = { + type: "object", + oneOf: [ + { + title: "Foo", + properties: { + foo: { type: "string" }, + }, + }, + { + properties: { + bar: { type: "string" }, + }, + }, + { + $ref: "#/definitions/baz", + }, + ], + definitions: { + baz: { + title: "Baz", + properties: { + baz: { type: "string" }, + }, + }, + }, + }; + + const { node } = createFormComponent({ + schema, + }); + + const $select = node.querySelector("select"); + + expect($select.options[0].text).eql("Foo"); + expect($select.options[1].text).eql("Option 2"); + expect($select.options[2].text).eql("Baz"); + }); }); });