Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epicfaace committed Feb 23, 2019
1 parent 9153444 commit 5aaf863
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 44 deletions.
40 changes: 17 additions & 23 deletions test/NumberField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe("NumberField", () => {
expect(node.querySelector("select").id).eql("root");
});

it("should render a select element if set the enum.", () => {
it("should render a select element with a blank option, when default value is not set.", () => {
const schema = {
type: "object",
properties: {
Expand All @@ -307,16 +307,21 @@ describe("NumberField", () => {
});

const selects = node.querySelectorAll("select");
expect(selects).to.have.length.of(1);
expect(selects[0].value).eql("");

const options = node.querySelectorAll("option");
expect(options.length).eql(2);
expect(options[0].innerHTML).eql("");
});

it("should render a select element and it's value is empty, if set the enum and the default value is undefined.", () => {
it("should render a select element without a blank option, if a default value is set.", () => {
const schema = {
type: "object",
properties: {
foo: {
type: "number",
enum: [0],
enum: [2],
default: 2,
},
},
};
Expand All @@ -326,29 +331,14 @@ describe("NumberField", () => {
});

const selects = node.querySelectorAll("select");
expect(selects[0].value).eql("");
});

it("should render a select element and it's first option has an empty innerHTML, if set the enum and the default value is undefined.", () => {
const schema = {
type: "object",
properties: {
foo: {
type: "number",
enum: [0],
},
},
};

const { node } = createFormComponent({
schema,
});
expect(selects[0].value).eql("2");

const options = node.querySelectorAll("option");
expect(options[0].innerHTML).eql("");
expect(options.length).eql(1);
expect(options[0].innerHTML).eql("2");
});

it("should render a select element and it's first option is '0', if set the enum and the default value is 0.", () => {
it("should render a select element without a blank option, if the default value is 0.", () => {
const schema = {
type: "object",
properties: {
Expand All @@ -364,7 +354,11 @@ describe("NumberField", () => {
schema,
});

const selects = node.querySelectorAll("select");
expect(selects[0].value).eql("0");

const options = node.querySelectorAll("option");
expect(options.length).eql(1);
expect(options[0].innerHTML).eql("0");
});
});
Expand Down
25 changes: 4 additions & 21 deletions test/StringField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ describe("StringField", () => {
expect(node.querySelector("#custom")).to.exist;
});

it("should render a select element and it's first option is 'false', if set the enum and the default value is false.", () => {
it("should render a select element with first option 'false' if the default value is false", () => {
const schema = {
type: "object",
properties: {
Expand All @@ -369,25 +369,6 @@ describe("StringField", () => {

const options = node.querySelectorAll("option");
expect(options[0].innerHTML).eql("false");
});

it("should render a select element and the option's length is equal the enum's length, if set the enum.", () => {
const schema = {
type: "object",
properties: {
foo: {
type: "string",
enum: [false, true],
default: false,
},
},
};

const { node } = createFormComponent({
schema,
});

const options = node.querySelectorAll("option");
expect(options.length).eql(2);
});

Expand All @@ -408,10 +389,11 @@ describe("StringField", () => {
});

const options = node.querySelectorAll("option");
expect(options[0].innerHTML).eql("");
expect(options.length).eql(2);
});

it("shouldn't render two empty options, when the default value is empty.", () => {
it("should render only one empty option when the default value is empty.", () => {
const schema = {
type: "object",
properties: {
Expand All @@ -428,6 +410,7 @@ describe("StringField", () => {
});

const options = node.querySelectorAll("option");
expect(options[0].innerHTML).eql("");
expect(options.length).eql(1);
});
});
Expand Down

0 comments on commit 5aaf863

Please sign in to comment.