Skip to content

Commit aa862ab

Browse files
author
kevinq.qk
committedFeb 12, 2019
test: add enum test
1 parent 54091b1 commit aa862ab

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
 

‎test/enum_test.js

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { expect } from "chai";
2+
3+
import { createFormComponent, createSandbox } from "./test_utils";
4+
5+
describe("enum", () => {
6+
let sandbox;
7+
8+
beforeEach(() => {
9+
sandbox = createSandbox();
10+
});
11+
12+
afterEach(() => {
13+
sandbox.restore();
14+
});
15+
16+
it("should render a select element if set the enum.", () => {
17+
const schema = {
18+
type: "object",
19+
properties: {
20+
foo: {
21+
type: "string",
22+
enum: [0],
23+
},
24+
},
25+
};
26+
27+
const { node } = createFormComponent({
28+
schema,
29+
});
30+
31+
const selects = node.querySelectorAll("select");
32+
expect(selects).to.have.length.of(1);
33+
});
34+
35+
it("should render a select element and it's value is empty, if set the enum and the default value is undefined.", () => {
36+
const schema = {
37+
type: "object",
38+
properties: {
39+
foo: {
40+
type: "string",
41+
enum: [0],
42+
},
43+
},
44+
};
45+
46+
const { node } = createFormComponent({
47+
schema,
48+
});
49+
50+
const selects = node.querySelectorAll("select");
51+
expect(selects[0].value).eql("");
52+
});
53+
54+
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.", () => {
55+
const schema = {
56+
type: "object",
57+
properties: {
58+
foo: {
59+
type: "string",
60+
enum: [0],
61+
},
62+
},
63+
};
64+
65+
const { node } = createFormComponent({
66+
schema,
67+
});
68+
69+
const options = node.querySelectorAll("option");
70+
expect(options[0].innerHTML).eql("");
71+
});
72+
73+
it("should render a select element and it's first option is '0', if set the enum and the default value is 0.", () => {
74+
const schema = {
75+
type: "object",
76+
properties: {
77+
foo: {
78+
type: "string",
79+
enum: [0],
80+
default: 0,
81+
},
82+
},
83+
};
84+
85+
const { node } = createFormComponent({
86+
schema,
87+
});
88+
89+
const options = node.querySelectorAll("option");
90+
expect(options[0].innerHTML).eql("0");
91+
});
92+
93+
it("should render a select element and it's first option is 'false', if set the enum and the default value is false.", () => {
94+
const schema = {
95+
type: "object",
96+
properties: {
97+
foo: {
98+
type: "string",
99+
enum: [false, true],
100+
default: false,
101+
},
102+
},
103+
};
104+
105+
const { node } = createFormComponent({
106+
schema,
107+
});
108+
109+
const options = node.querySelectorAll("option");
110+
expect(options[0].innerHTML).eql("false");
111+
});
112+
113+
it("should render a select element and the option's length is equal the enum's length, if set the enum.", () => {
114+
const schema = {
115+
type: "object",
116+
properties: {
117+
foo: {
118+
type: "string",
119+
enum: [false, true],
120+
default: false,
121+
},
122+
},
123+
};
124+
125+
const { node } = createFormComponent({
126+
schema,
127+
});
128+
129+
const options = node.querySelectorAll("option");
130+
expect(options.length).eql(2);
131+
});
132+
});

0 commit comments

Comments
 (0)
Please sign in to comment.