From e17a5f40f58382b13d4485d209b178e33c0f62b9 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Wed, 29 Nov 2017 19:03:40 -0600 Subject: [PATCH] Add JsonSchemaForm tests, including one failing --- test/components/json-schema-form.js | 111 ++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 test/components/json-schema-form.js diff --git a/test/components/json-schema-form.js b/test/components/json-schema-form.js new file mode 100644 index 00000000..7bd528e7 --- /dev/null +++ b/test/components/json-schema-form.js @@ -0,0 +1,111 @@ +/* eslint-env mocha */ +import React from "react" +import expect, { createSpy } from "expect" +import { Select } from "components/layout-utils" +import { render } from "enzyme" +import * as JsonSchemaComponents from "core/json-schema-components" +import { JsonSchemaForm } from "core/json-schema-components" + +const components = {...JsonSchemaComponents, Select} + +const getComponentStub = (name) => { + return components[name] || (() => { + console.error(`Couldn't find "${name}"`) + return null + }) +} + +describe("", function(){ + describe("strings", function() { + it("should render the correct options for a string enum parameter", function(){ + + let props = { + getComponent: getComponentStub, + value: "", + onChange: () => {}, + keyName: "", + fn: {}, + schema: { + type: "string", + enum: ["one", "two"] + } + } + + let wrapper = render() + + expect(wrapper.find("select").length).toEqual(1) + expect(wrapper.find("select option").length).toEqual(3) + expect(wrapper.find("select option").eq(0).text()).toEqual("--") + expect(wrapper.find("select option").eq(1).text()).toEqual("one") + expect(wrapper.find("select option").eq(2).text()).toEqual("two") + }) + + it("should render the correct options for a required string enum parameter", function(){ + + let props = { + getComponent: getComponentStub, + value: "", + onChange: () => {}, + keyName: "", + fn: {}, + required: true, + schema: { + type: "string", + enum: ["one", "two"] + } + } + + let wrapper = render() + + expect(wrapper.find("select").length).toEqual(1) + expect(wrapper.find("select option").length).toEqual(2) + expect(wrapper.find("select option").eq(0).text()).toEqual("one") + expect(wrapper.find("select option").eq(1).text()).toEqual("two") + }) + }) + describe("booleans", function() { + it("should render the correct options for a boolean parameter", function(){ + + let props = { + getComponent: getComponentStub, + value: "", + onChange: () => {}, + keyName: "", + fn: {}, + schema: { + type: "boolean" + } + } + + let wrapper = render() + + expect(wrapper.find("select").length).toEqual(1) + expect(wrapper.find("select option").length).toEqual(3) + expect(wrapper.find("select option").eq(0).text()).toEqual("--") + expect(wrapper.find("select option").eq(1).text()).toEqual("true") + expect(wrapper.find("select option").eq(2).text()).toEqual("false") + }) + + it("should render the correct options for a required enum boolean parameter", function(){ + + let props = { + getComponent: getComponentStub, + value: "", + onChange: () => {}, + keyName: "", + fn: {}, + required: true, + schema: { + type: "boolean", + enum: ["true"] + } + } + + let wrapper = render() + + expect(wrapper.find("select").length).toEqual(1) + expect(wrapper.find("select option").length).toEqual(1) + expect(wrapper.find("select option").eq(1).text()).toEqual("true") + }) + }) +})