Skip to content

Commit 4d17bd8

Browse files
author
kevinq.qk
committedFeb 13, 2019
test: move the test to the right file
1 parent aa862ab commit 4d17bd8

File tree

3 files changed

+157
-132
lines changed

3 files changed

+157
-132
lines changed
 

‎test/NumberField_test.js

+77
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,82 @@ describe("NumberField", () => {
290290

291291
expect(node.querySelector("select").id).eql("root");
292292
});
293+
294+
it("should render a select element if set the enum.", () => {
295+
const schema = {
296+
type: "object",
297+
properties: {
298+
foo: {
299+
type: "number",
300+
enum: [0],
301+
},
302+
},
303+
};
304+
305+
const { node } = createFormComponent({
306+
schema,
307+
});
308+
309+
const selects = node.querySelectorAll("select");
310+
expect(selects).to.have.length.of(1);
311+
});
312+
313+
it("should render a select element and it's value is empty, if set the enum and the default value is undefined.", () => {
314+
const schema = {
315+
type: "object",
316+
properties: {
317+
foo: {
318+
type: "number",
319+
enum: [0],
320+
},
321+
},
322+
};
323+
324+
const { node } = createFormComponent({
325+
schema,
326+
});
327+
328+
const selects = node.querySelectorAll("select");
329+
expect(selects[0].value).eql("");
330+
});
331+
332+
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.", () => {
333+
const schema = {
334+
type: "object",
335+
properties: {
336+
foo: {
337+
type: "number",
338+
enum: [0],
339+
},
340+
},
341+
};
342+
343+
const { node } = createFormComponent({
344+
schema,
345+
});
346+
347+
const options = node.querySelectorAll("option");
348+
expect(options[0].innerHTML).eql("");
349+
});
350+
351+
it("should render a select element and it's first option is '0', if set the enum and the default value is 0.", () => {
352+
const schema = {
353+
type: "object",
354+
properties: {
355+
foo: {
356+
type: "number",
357+
enum: [0],
358+
default: 0,
359+
},
360+
},
361+
};
362+
363+
const { node } = createFormComponent({
364+
schema,
365+
});
366+
367+
const options = node.querySelectorAll("option");
368+
expect(options[0].innerHTML).eql("0");
369+
});
293370
});
294371
});

‎test/StringField_test.js

+80
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,86 @@ describe("StringField", () => {
350350

351351
expect(node.querySelector("#custom")).to.exist;
352352
});
353+
354+
it("should render a select element and it's first option is 'false', if set the enum and the default value is false.", () => {
355+
const schema = {
356+
type: "object",
357+
properties: {
358+
foo: {
359+
type: "string",
360+
enum: [false, true],
361+
default: false,
362+
},
363+
},
364+
};
365+
366+
const { node } = createFormComponent({
367+
schema,
368+
});
369+
370+
const options = node.querySelectorAll("option");
371+
expect(options[0].innerHTML).eql("false");
372+
});
373+
374+
it("should render a select element and the option's length is equal the enum's length, if set the enum.", () => {
375+
const schema = {
376+
type: "object",
377+
properties: {
378+
foo: {
379+
type: "string",
380+
enum: [false, true],
381+
default: false,
382+
},
383+
},
384+
};
385+
386+
const { node } = createFormComponent({
387+
schema,
388+
});
389+
390+
const options = node.querySelectorAll("option");
391+
expect(options.length).eql(2);
392+
});
393+
394+
it("should render a select element and the option's length is equal the enum's length, if set the enum and the default value is empty.", () => {
395+
const schema = {
396+
type: "object",
397+
properties: {
398+
foo: {
399+
type: "string",
400+
enum: ["", "1"],
401+
default: "",
402+
},
403+
},
404+
};
405+
406+
const { node } = createFormComponent({
407+
schema,
408+
});
409+
410+
const options = node.querySelectorAll("option");
411+
expect(options.length).eql(2);
412+
});
413+
414+
it("shouldn't render two empty options, when the default value is empty.", () => {
415+
const schema = {
416+
type: "object",
417+
properties: {
418+
foo: {
419+
type: "string",
420+
enum: [""],
421+
default: "",
422+
},
423+
},
424+
};
425+
426+
const { node } = createFormComponent({
427+
schema,
428+
});
429+
430+
const options = node.querySelectorAll("option");
431+
expect(options.length).eql(1);
432+
});
353433
});
354434

355435
describe("TextareaWidget", () => {

‎test/enum_test.js

-132
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.