|
1 | 1 | /* eslint-env mocha */ |
2 | 2 | import React from "react" |
3 | 3 | import expect, { createSpy } from "expect" |
4 | | -import { Select } from "components/layout-utils" |
| 4 | +import { Select, Input } from "components/layout-utils" |
5 | 5 | import { render } from "enzyme" |
6 | 6 | import * as JsonSchemaComponents from "core/json-schema-components" |
7 | 7 | import { JsonSchemaForm } from "core/json-schema-components" |
8 | 8 |
|
9 | | -const components = {...JsonSchemaComponents, Select} |
| 9 | +const components = {...JsonSchemaComponents, Select, Input} |
10 | 10 |
|
11 | 11 | const getComponentStub = (name) => { |
12 | | - return components[name] || (() => { |
13 | | - console.error(`Couldn't find "${name}"`) |
14 | | - return null |
15 | | - }) |
| 12 | + if(components[name]) return components[name] |
| 13 | + |
| 14 | + return null |
16 | 15 | } |
17 | 16 |
|
18 | 17 | describe("<JsonSchemaForm/>", function(){ |
@@ -108,4 +107,48 @@ describe("<JsonSchemaForm/>", function(){ |
108 | 107 | expect(wrapper.find("select option").first().text()).toEqual("true") |
109 | 108 | }) |
110 | 109 | }) |
| 110 | + describe("unknown types", function() { |
| 111 | + it("should render unknown types as strings", function(){ |
| 112 | + |
| 113 | + let props = { |
| 114 | + getComponent: getComponentStub, |
| 115 | + value: "yo", |
| 116 | + onChange: () => {}, |
| 117 | + keyName: "", |
| 118 | + fn: {}, |
| 119 | + schema: { |
| 120 | + type: "NotARealType" |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + let wrapper = render(<JsonSchemaForm {...props}/>) |
| 126 | + |
| 127 | + expect(wrapper.find("input").length).toEqual(1) |
| 128 | + // expect(wrapper.find("select input").length).toEqual(1) |
| 129 | + // expect(wrapper.find("select option").first().text()).toEqual("true") |
| 130 | + }) |
| 131 | + |
| 132 | + it("should render unknown types as strings when a format is passed", function(){ |
| 133 | + |
| 134 | + let props = { |
| 135 | + getComponent: getComponentStub, |
| 136 | + value: "yo", |
| 137 | + onChange: () => {}, |
| 138 | + keyName: "", |
| 139 | + fn: {}, |
| 140 | + schema: { |
| 141 | + type: "NotARealType", |
| 142 | + format: "NotARealFormat" |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + |
| 147 | + let wrapper = render(<JsonSchemaForm {...props}/>) |
| 148 | + |
| 149 | + expect(wrapper.find("input").length).toEqual(1) |
| 150 | + // expect(wrapper.find("select input").length).toEqual(1) |
| 151 | + // expect(wrapper.find("select option").first().text()).toEqual("true") |
| 152 | + }) |
| 153 | + }) |
111 | 154 | }) |
0 commit comments