Skip to content

Commit

Permalink
Integrated tests from PR #2245
Browse files Browse the repository at this point in the history
  • Loading branch information
NixBiks committed Mar 16, 2021
1 parent 54ce2ac commit 2bf49c0
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
47 changes: 46 additions & 1 deletion packages/core/test/anyOf_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ describe("anyOf", () => {
},
},
{
$ref: "#/definitions/bar",
},
],
definitions: {
bar: {
type: "object",
properties: {
foo: { type: "string", default: "defaultbar" },
},
},
],
},
},
});
sinon.assert.calledWithMatch(onChange.lastCall, {
Expand Down Expand Up @@ -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",
Expand Down
47 changes: 45 additions & 2 deletions packages/core/test/oneOf_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ describe("oneOf", () => {
foo: { type: "string", default: "defaultfoo" },
},
},
{
{ $ref: "#/definitions/bar" },
],
definitions: {
bar: {
type: "object",
properties: {
foo: { type: "string", default: "defaultbar" },
},
},
],
},
},
});

Expand Down Expand Up @@ -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");
});
});
});

0 comments on commit 2bf49c0

Please sign in to comment.