Merge branch 'master' into feature/spec-path
This commit is contained in:
154
test/components/json-schema-form.js
Normal file
154
test/components/json-schema-form.js
Normal file
@@ -0,0 +1,154 @@
|
||||
/* eslint-env mocha */
|
||||
import React from "react"
|
||||
import expect, { createSpy } from "expect"
|
||||
import { Select, Input } 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, Input}
|
||||
|
||||
const getComponentStub = (name) => {
|
||||
if(components[name]) return components[name]
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
describe("<JsonSchemaForm/>", 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(<JsonSchemaForm {...props}/>)
|
||||
|
||||
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(<JsonSchemaForm {...props}/>)
|
||||
|
||||
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(<JsonSchemaForm {...props}/>)
|
||||
|
||||
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(<JsonSchemaForm {...props}/>)
|
||||
|
||||
expect(wrapper.find("select").length).toEqual(1)
|
||||
expect(wrapper.find("select option").length).toEqual(1)
|
||||
expect(wrapper.find("select option").first().text()).toEqual("true")
|
||||
})
|
||||
})
|
||||
describe("unknown types", function() {
|
||||
it("should render unknown types as strings", function(){
|
||||
|
||||
let props = {
|
||||
getComponent: getComponentStub,
|
||||
value: "yo",
|
||||
onChange: () => {},
|
||||
keyName: "",
|
||||
fn: {},
|
||||
schema: {
|
||||
type: "NotARealType"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let wrapper = render(<JsonSchemaForm {...props}/>)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(1)
|
||||
// expect(wrapper.find("select input").length).toEqual(1)
|
||||
// expect(wrapper.find("select option").first().text()).toEqual("true")
|
||||
})
|
||||
|
||||
it("should render unknown types as strings when a format is passed", function(){
|
||||
|
||||
let props = {
|
||||
getComponent: getComponentStub,
|
||||
value: "yo",
|
||||
onChange: () => {},
|
||||
keyName: "",
|
||||
fn: {},
|
||||
schema: {
|
||||
type: "NotARealType",
|
||||
format: "NotARealFormat"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let wrapper = render(<JsonSchemaForm {...props}/>)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(1)
|
||||
// expect(wrapper.find("select input").length).toEqual(1)
|
||||
// expect(wrapper.find("select option").first().text()).toEqual("true")
|
||||
})
|
||||
})
|
||||
})
|
||||
68
test/components/object-model.js
Normal file
68
test/components/object-model.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import React from "react"
|
||||
import expect from "expect"
|
||||
import { shallow } from "enzyme"
|
||||
import { fromJS } from "immutable"
|
||||
import ObjectModel from "components/object-model"
|
||||
import ModelExample from "components/model-example"
|
||||
import Immutable from "immutable"
|
||||
import Model from "components/model"
|
||||
import ModelCollapse from "components/model-collapse"
|
||||
import { inferSchema } from "corePlugins/samples/fn"
|
||||
|
||||
describe("<ObjectModel />", function() {
|
||||
const dummyComponent = () => null
|
||||
const components = {
|
||||
"JumpToPath" : dummyComponent,
|
||||
"Markdown" : dummyComponent,
|
||||
"Model" : Model,
|
||||
"ModelCollapse" : ModelCollapse
|
||||
}
|
||||
const props = {
|
||||
getComponent: c => components[c],
|
||||
getConfigs: () => {
|
||||
return {
|
||||
showExtensions: true
|
||||
}
|
||||
},
|
||||
isRef : false,
|
||||
schema: Immutable.fromJS(
|
||||
{
|
||||
"properties": {
|
||||
// Note reverse order: c, b, a
|
||||
c: {
|
||||
type: "integer",
|
||||
name: "c"
|
||||
},
|
||||
b: {
|
||||
type: "boolean",
|
||||
name: "b"
|
||||
},
|
||||
a: {
|
||||
type: "string",
|
||||
name: "a"
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
specSelectors: {
|
||||
isOAS3(){
|
||||
return false
|
||||
}
|
||||
},
|
||||
className: "for-test"
|
||||
}
|
||||
it("renders a collapsible header", function(){
|
||||
const wrapper = shallow(<ObjectModel {...props}/>)
|
||||
const renderedModelCollapse = wrapper.find(ModelCollapse)
|
||||
expect(renderedModelCollapse.length).toEqual(1)
|
||||
})
|
||||
|
||||
it("renders the object properties in order", function() {
|
||||
const wrapper = shallow(<ObjectModel {...props}/>)
|
||||
const renderedModel = wrapper.find(Model)
|
||||
expect(renderedModel.length).toEqual(3)
|
||||
expect(renderedModel.get(0).props.schema.get("name")).toEqual("c")
|
||||
expect(renderedModel.get(1).props.schema.get("name")).toEqual("b")
|
||||
expect(renderedModel.get(2).props.schema.get("name")).toEqual("a")
|
||||
})
|
||||
})
|
||||
123
test/components/operations.js
Normal file
123
test/components/operations.js
Normal file
@@ -0,0 +1,123 @@
|
||||
/* eslint-env mocha */
|
||||
import React from "react"
|
||||
import expect, { createSpy } from "expect"
|
||||
import { render } from "enzyme"
|
||||
import { fromJS } from "immutable"
|
||||
import Operations from "components/operations"
|
||||
import {Collapse} from "components/layout-utils"
|
||||
|
||||
const components = {
|
||||
Collapse,
|
||||
OperationContainer: ({ path, method }) => <span className="mocked-op" id={`${path}-${method}`} />
|
||||
}
|
||||
|
||||
describe("<Operations/>", function(){
|
||||
it("should render a Swagger2 `get` method, but not a `trace` or `foo` method", function(){
|
||||
|
||||
let props = {
|
||||
fn: {},
|
||||
specActions: {},
|
||||
layoutActions: {},
|
||||
getComponent: (name)=> {
|
||||
return components[name] || null
|
||||
},
|
||||
getConfigs: () => {
|
||||
return {}
|
||||
},
|
||||
specSelectors: {
|
||||
isOAS3() { return false },
|
||||
taggedOperations() {
|
||||
return fromJS({
|
||||
"default": {
|
||||
"operations": [
|
||||
{
|
||||
"path": "/pets/{id}",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"path": "/pets/{id}",
|
||||
"method": "trace"
|
||||
},
|
||||
{
|
||||
"path": "/pets/{id}",
|
||||
"method": "foo"
|
||||
},
|
||||
]
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
layoutSelectors: {
|
||||
currentFilter() {
|
||||
return null
|
||||
},
|
||||
isShown() {
|
||||
return true
|
||||
},
|
||||
show() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let wrapper = render(<Operations {...props}/>)
|
||||
|
||||
expect(wrapper.find("span.mocked-op").length).toEqual(1)
|
||||
expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get")
|
||||
})
|
||||
|
||||
it("should render an OAS3 `get` and `trace` method, but not a `foo` method", function(){
|
||||
|
||||
let props = {
|
||||
fn: {},
|
||||
specActions: {},
|
||||
layoutActions: {},
|
||||
getComponent: (name)=> {
|
||||
return components[name] || null
|
||||
},
|
||||
getConfigs: () => {
|
||||
return {}
|
||||
},
|
||||
specSelectors: {
|
||||
isOAS3() { return true },
|
||||
taggedOperations() {
|
||||
return fromJS({
|
||||
"default": {
|
||||
"operations": [
|
||||
{
|
||||
"path": "/pets/{id}",
|
||||
"method": "get"
|
||||
},
|
||||
{
|
||||
"path": "/pets/{id}",
|
||||
"method": "trace"
|
||||
},
|
||||
{
|
||||
"path": "/pets/{id}",
|
||||
"method": "foo"
|
||||
},
|
||||
]
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
layoutSelectors: {
|
||||
currentFilter() {
|
||||
return null
|
||||
},
|
||||
isShown() {
|
||||
return true
|
||||
},
|
||||
show() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let wrapper = render(<Operations {...props}/>)
|
||||
|
||||
expect(wrapper.find("span.mocked-op").length).toEqual(2)
|
||||
expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get")
|
||||
expect(wrapper.find("span.mocked-op").eq(1).attr("id")).toEqual("/pets/{id}-trace")
|
||||
})
|
||||
})
|
||||
@@ -14,6 +14,9 @@ describe("<PrimitiveModel/>", function() {
|
||||
}
|
||||
const props = {
|
||||
getComponent: c => components[c],
|
||||
getConfigs: () => ({
|
||||
showExtensions: false
|
||||
}),
|
||||
name: "Name from props",
|
||||
depth: 1,
|
||||
schema: fromJS({
|
||||
@@ -46,4 +49,4 @@ describe("<PrimitiveModel/>", function() {
|
||||
})
|
||||
|
||||
})
|
||||
} )
|
||||
} )
|
||||
|
||||
Reference in New Issue
Block a user