Added Swagger
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
import { fromJS } from "immutable"
|
||||
import React from "react"
|
||||
import expect from "expect"
|
||||
import { configure, mount } from "enzyme"
|
||||
import Adapter from "enzyme-adapter-react-15"
|
||||
import AddForm from "src/standalone/topbar-insert/forms/components/AddForm"
|
||||
import FormChild from "src/standalone/topbar-insert/forms/components/FormChild"
|
||||
import FormDropdown from "src/standalone/topbar-insert/forms/components/FormDropdown"
|
||||
import FormInput from "src/standalone/topbar-insert/forms/components/FormInput"
|
||||
import FormInputWrapper from "src/standalone/topbar-insert/forms/components/FormInputWrapper"
|
||||
import FormMap from "src/standalone/topbar-insert/forms/components/FormMap"
|
||||
import InsertForm from "src/standalone/topbar-insert/forms/components/InsertForm"
|
||||
import InsertFormInput from "src/standalone/topbar-insert/forms/components/InsertFormInput"
|
||||
import InsertFormList from "src/standalone/topbar-insert/forms/components/InsertFormList"
|
||||
|
||||
configure({ adapter: new Adapter() })
|
||||
|
||||
describe("editor topbar insert form UI generation", function() {
|
||||
this.timeout(10 * 1000)
|
||||
let components, props
|
||||
|
||||
beforeEach(() => {
|
||||
components = {
|
||||
FormDropdown,
|
||||
AddForm,
|
||||
FormChild,
|
||||
FormInput,
|
||||
FormInputWrapper,
|
||||
FormMap,
|
||||
InsertForm,
|
||||
InsertFormInput,
|
||||
InsertFormList
|
||||
}
|
||||
|
||||
props = {
|
||||
getComponent: (c) => components[c]
|
||||
}
|
||||
})
|
||||
|
||||
it("should produce a valid form UI for a simple form object", () => {
|
||||
const form = fromJS({
|
||||
fielda: {
|
||||
value: "test value",
|
||||
isRequired: true,
|
||||
name: "field a",
|
||||
updateForm: () => null
|
||||
}
|
||||
})
|
||||
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(1)
|
||||
})
|
||||
|
||||
it("should produce a form ui with a dropdown", () => {
|
||||
const form = fromJS({
|
||||
fielda: {
|
||||
value: "",
|
||||
isRequired: true,
|
||||
name: "field a",
|
||||
options: ["optiona", "optionb"],
|
||||
updateForm: () => null
|
||||
}
|
||||
})
|
||||
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("select").length).toEqual(1)
|
||||
})
|
||||
|
||||
it("should produce a form ui with a list control", () => {
|
||||
const listControlItem = (updateForm, path) => fromJS({
|
||||
listItem: {
|
||||
value: "list item value",
|
||||
name: "List Item",
|
||||
updateForm: newForm => updateForm(newForm, path.concat(["listItem"]))
|
||||
}
|
||||
})
|
||||
|
||||
let path = []
|
||||
|
||||
const form = fromJS({
|
||||
fielda: {
|
||||
value: [listControlItem(() => null, path.concat(["fielda", "value", 0]))],
|
||||
isRequired: true,
|
||||
name: "field a",
|
||||
updateForm: () => null,
|
||||
defaultItem: i => listControlItem(() => null, path.concat(["fielda", "value", i]) )
|
||||
}
|
||||
})
|
||||
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(1)
|
||||
expect(wrapper.find("a").length).toEqual(1)
|
||||
})
|
||||
|
||||
it("should produce a form ui with a map", () => {
|
||||
const form = fromJS({
|
||||
fielda: {
|
||||
keyValue: "",
|
||||
value: {
|
||||
fieldb: {
|
||||
value: "test value",
|
||||
isRequired: true,
|
||||
name: "field b",
|
||||
updateForm: () => null
|
||||
}
|
||||
},
|
||||
isRequired: true,
|
||||
name: "field a",
|
||||
updateForm: () => null
|
||||
}
|
||||
})
|
||||
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(2)
|
||||
})
|
||||
|
||||
it("should not render an input that depends on an input with no value", () => {
|
||||
const form = fromJS({
|
||||
fielda: {
|
||||
value: "",
|
||||
isRequired: true,
|
||||
name: "field a",
|
||||
options: ["optiona", "optionb"],
|
||||
updateForm: () => null
|
||||
},
|
||||
fieldb: {
|
||||
dependsOn: ["fielda", "value"],
|
||||
updateOptions: () => { return ["option c", "option d"] },
|
||||
value: "",
|
||||
isRequired: true,
|
||||
name: "field a",
|
||||
options: [],
|
||||
updateForm: () => null
|
||||
},
|
||||
})
|
||||
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("select").length).toEqual(1)
|
||||
})
|
||||
|
||||
it("should render an input that depends on an input with a value", () => {
|
||||
const form = fromJS({
|
||||
fielda: {
|
||||
value: "optiona",
|
||||
isRequired: true,
|
||||
name: "field a",
|
||||
options: ["optiona", "optionb"],
|
||||
updateForm: () => null
|
||||
},
|
||||
fieldb: {
|
||||
dependsOn: ["fielda", "value"],
|
||||
updateOptions: () => { return ["option c", "option d"] },
|
||||
value: "",
|
||||
isRequired: true,
|
||||
name: "field a",
|
||||
options: [],
|
||||
updateForm: () => null
|
||||
},
|
||||
})
|
||||
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("select").length).toEqual(2)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,316 @@
|
||||
import expect from "expect"
|
||||
import React from "react"
|
||||
import { configure, mount } from "enzyme"
|
||||
import Adapter from "enzyme-adapter-react-15"
|
||||
import { fromJS, List } from "immutable"
|
||||
|
||||
import AddForm from "src/standalone/topbar-insert/forms/components/AddForm"
|
||||
import FormChild from "src/standalone/topbar-insert/forms/components/FormChild"
|
||||
import FormDropdown from "src/standalone/topbar-insert/forms/components/FormDropdown"
|
||||
import FormInput from "src/standalone/topbar-insert/forms/components/FormInput"
|
||||
import FormInputWrapper from "src/standalone/topbar-insert/forms/components/FormInputWrapper"
|
||||
import FormMap from "src/standalone/topbar-insert/forms/components/FormMap"
|
||||
import InsertForm from "src/standalone/topbar-insert/forms/components/InsertForm"
|
||||
import InsertFormInput from "src/standalone/topbar-insert/forms/components/InsertFormInput"
|
||||
import InsertFormList from "src/standalone/topbar-insert/forms/components/InsertFormList"
|
||||
|
||||
import { pathForm, pathObject } from "src/standalone/topbar-insert/forms/form-objects/path-object"
|
||||
import { operationForm, operationObject } from "src/standalone/topbar-insert/forms/form-objects/operation-object"
|
||||
import { infoForm, infoObject } from "src/standalone/topbar-insert/forms/form-objects/info-object"
|
||||
import { licenseForm} from "src/standalone/topbar-insert/forms/form-objects/license-object"
|
||||
import { contactForm } from "src/standalone/topbar-insert/forms/form-objects/contact-object"
|
||||
import { tagsForm, tagsObject } from "src/standalone/topbar-insert/forms/form-objects/tags-object"
|
||||
import { tagForm } from "src/standalone/topbar-insert/forms/form-objects/tag-object"
|
||||
import { serversForm, serversObject } from "src/standalone/topbar-insert/forms/form-objects/servers-object"
|
||||
import { serverVariableForm } from "src/standalone/topbar-insert/forms/form-objects/server-variable-object"
|
||||
import { externalDocumentationForm } from "src/standalone/topbar-insert/forms/form-objects/external-documentation-object"
|
||||
import { addOperationTagsForm, addOperationTagsObject } from "src/standalone/topbar-insert/forms/form-objects/add-operation-tags"
|
||||
import { selectOperationForm } from "src/standalone/topbar-insert/forms/form-objects/select-operation"
|
||||
import { selectResponseForm } from "src/standalone/topbar-insert/forms/form-objects/select-response"
|
||||
import { exampleObject, exampleForm } from "src/standalone/topbar-insert/forms/form-objects/example-value-object"
|
||||
|
||||
configure({ adapter: new Adapter() })
|
||||
|
||||
describe("editor topbar insert forms", function() {
|
||||
this.timeout(10 * 1000)
|
||||
let components, props
|
||||
|
||||
beforeEach(() => {
|
||||
components = {
|
||||
FormDropdown,
|
||||
AddForm,
|
||||
FormChild,
|
||||
FormInput,
|
||||
FormInputWrapper,
|
||||
FormMap,
|
||||
InsertForm,
|
||||
InsertFormInput,
|
||||
InsertFormList
|
||||
}
|
||||
|
||||
props = {
|
||||
getComponent: (c) => components[c]
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
describe("operation object", function () {
|
||||
let form = operationForm(null, [])
|
||||
|
||||
const tag = form.getIn(["tags", "defaultItem"])(null, [])
|
||||
|
||||
form = form
|
||||
.setIn(["path", "value"], "/testpath")
|
||||
.setIn(["summary", "value"], "test summary")
|
||||
.setIn(["description", "value"], "test description")
|
||||
.setIn(["operationid", "value"], "testid")
|
||||
.setIn(["tags", "value"], new List([tag.setIn(["tag", "value"], "test tag" )]))
|
||||
|
||||
const object = operationObject(form)
|
||||
|
||||
it("should correctly process the operation form into the operation object", () => {
|
||||
const expected = {
|
||||
summary: "test summary",
|
||||
description: "test description",
|
||||
operationId: "testid",
|
||||
tags: ["test tag"],
|
||||
responses: {
|
||||
default: {
|
||||
description: "Default error sample response"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect(object).toEqual(expected)
|
||||
})
|
||||
|
||||
it ("should correctly render the form UI for the form object", () => {
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(4)
|
||||
expect(wrapper.find("select").length).toEqual(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe("info object", () => {
|
||||
const license = licenseForm(null, [], null)
|
||||
.setIn(["value", "name", "value"], "test name")
|
||||
.setIn(["value", "url", "value"], "test url")
|
||||
|
||||
const contact = contactForm(null, [])
|
||||
.setIn(["value", "name", "value"], "test name")
|
||||
.setIn(["value", "url", "value"], "test url")
|
||||
.setIn(["value", "email", "value"], "testemail@test.com")
|
||||
|
||||
let form = infoForm(null, [])
|
||||
.setIn(["title", "value"], "test title")
|
||||
.setIn(["version", "value"], "test version")
|
||||
.setIn(["description", "value"], "test description")
|
||||
.setIn(["termsofservice", "value"], "testtermsofservice")
|
||||
.setIn(["license"], license)
|
||||
.setIn(["contact"], contact)
|
||||
|
||||
it("should correctly process the info form into the info object", () => {
|
||||
const object = infoObject(form)
|
||||
|
||||
const expected = {
|
||||
title: "test title",
|
||||
version: "test version",
|
||||
description: "test description",
|
||||
termsOfService: "testtermsofservice",
|
||||
license: {
|
||||
name: "test name",
|
||||
url: "test url"
|
||||
},
|
||||
contact: {
|
||||
name: "test name",
|
||||
url: "test url",
|
||||
email: "testemail@test.com"
|
||||
}
|
||||
}
|
||||
|
||||
expect(object).toEqual(expected)
|
||||
})
|
||||
|
||||
it ("should correctly render the form UI for the form object", () => {
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(4)
|
||||
})
|
||||
})
|
||||
|
||||
describe("path object", () => {
|
||||
let form = pathForm(null, [])
|
||||
|
||||
// Set some values as though the user had entered data
|
||||
form = form
|
||||
.setIn(["path", "value"], "/test")
|
||||
.setIn(["summary", "value"], "test summary")
|
||||
.setIn(["description", "value"], "test description")
|
||||
|
||||
it("should correctly process the path form into the path object", () => {
|
||||
const object = pathObject(form)
|
||||
const expected = {
|
||||
key: "/test",
|
||||
value: {
|
||||
summary: "test summary",
|
||||
description: "test description"
|
||||
}
|
||||
}
|
||||
expect(object).toEqual(expected)
|
||||
})
|
||||
|
||||
it ("should correctly render the form UI for the form object", () => {
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe("tag declarations object", () => {
|
||||
let form = tagsForm(null, [])
|
||||
|
||||
const externalDocs = externalDocumentationForm(null, [])
|
||||
.setIn(["url", "value"], "test url")
|
||||
.setIn(["description", "value"], "test description")
|
||||
|
||||
const tag = tagForm(null, [])
|
||||
.setIn(["name", "value"], "test tag name")
|
||||
.setIn(["description", "value"], "test description")
|
||||
.setIn(["externalDocs", "value"], externalDocs)
|
||||
|
||||
// Set some values as though the user had entered data
|
||||
form = form.setIn(["tags", "value"], new List([tag]))
|
||||
|
||||
it("should correctly process the tag declarations form into the tags object", () => {
|
||||
const object = tagsObject(form)
|
||||
const expected = [
|
||||
{
|
||||
name: "test tag name",
|
||||
description: "test description",
|
||||
externalDocs: {
|
||||
url: "test url",
|
||||
description: "test description"
|
||||
}
|
||||
}
|
||||
]
|
||||
expect(object).toEqual(expected)
|
||||
})
|
||||
|
||||
it ("should correctly render the form UI for the form object", () => {
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe("servers object", () => {
|
||||
let form = serversForm(null, [])
|
||||
const serverVariable = serverVariableForm(null, [])
|
||||
.setIn(["value", 0, "value", "default", "value"], "test default")
|
||||
.setIn(["value", 0, "value", "enum", "value"], fromJS([{ value: "test enum value"}]) )
|
||||
.setIn(["value", 0, "value", "vardescription", "value"], "test var description")
|
||||
.setIn(["value", 0, "keyValue"], "keyvalue")
|
||||
|
||||
form = form
|
||||
.setIn(["servers", "value", 0, "url", "value"], "test url")
|
||||
.setIn(["servers", "value", 0, "description", "value"], "test description")
|
||||
.setIn(["servers", "value", 0, "variables"], serverVariable)
|
||||
|
||||
it ("should correctly process the servers form into the servers object", () => {
|
||||
const object = serversObject(form)
|
||||
const expected = [
|
||||
{
|
||||
url: "test url",
|
||||
description: "test description",
|
||||
variables: {
|
||||
keyvalue: {
|
||||
default: "test default",
|
||||
description: "test var description",
|
||||
enum: [
|
||||
"test enum value"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
expect(object).toEqual(expected)
|
||||
})
|
||||
|
||||
it ("should correctly render the form UI for the form object", () => {
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(6)
|
||||
})
|
||||
})
|
||||
|
||||
describe("add tags object", () => {
|
||||
const selectOperation = selectOperationForm(null, [])
|
||||
.setIn(["path", "value"], "/test")
|
||||
.setIn(["operation", "value"], "GET")
|
||||
|
||||
let form = addOperationTagsForm(null, [])
|
||||
.setIn(["selectoperation", "value"], selectOperation)
|
||||
.setIn(["tags", "value", 0, "tag", "value"], "test tag")
|
||||
|
||||
it ("should correctly process the add tags to operation into the add tags object", () => {
|
||||
const object = addOperationTagsObject(form)
|
||||
|
||||
const expected = {
|
||||
selectedOperation: ["paths", "/test", "GET"],
|
||||
tags: [
|
||||
"test tag"
|
||||
]
|
||||
}
|
||||
|
||||
expect(object).toEqual(expected)
|
||||
})
|
||||
|
||||
it ("should correctly render the form UI for the form object", () => {
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(1)
|
||||
expect(wrapper.find("select").length).toEqual(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe("add example response object", () => {
|
||||
const selectResponse = selectResponseForm(null, [])
|
||||
.setIn(["path", "value"], "/test")
|
||||
.setIn(["operation", "value"], "GET")
|
||||
.setIn(["response", "value"], "200")
|
||||
.setIn(["mediatype", "value"], "application/json")
|
||||
|
||||
let form = exampleForm(null, [])
|
||||
.setIn(["selectresponse", "value"], selectResponse)
|
||||
.setIn(["exampleName", "value"], "sample example name")
|
||||
.setIn(["exampleValue", "value"], "sample example value")
|
||||
|
||||
it ("should correctly process the add example form into the form values object", () => {
|
||||
const object = exampleObject(form)
|
||||
|
||||
const expected = {
|
||||
responsePath: ["paths", "/test", "GET", "responses", "200", "content", "application/json", "examples"],
|
||||
exampleValue: "sample example value",
|
||||
exampleName: "sample example name"
|
||||
}
|
||||
|
||||
expect(object).toEqual(expected)
|
||||
})
|
||||
|
||||
it ("should correctly render the form UI for the form object", () => {
|
||||
const element = <InsertForm {...props} formData={form} />
|
||||
const wrapper = mount(element)
|
||||
|
||||
expect(wrapper.find("input").length).toEqual(1)
|
||||
expect(wrapper.find("select").length).toEqual(4)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,111 @@
|
||||
import { fromJS, OrderedMap, List } from "immutable"
|
||||
import expect from "expect"
|
||||
import {
|
||||
validateUrl,
|
||||
validateAlphaNum,
|
||||
checkForEmptyValue,
|
||||
checkForErrors
|
||||
} from "src/standalone/topbar-insert/forms/helpers/validation-helpers"
|
||||
|
||||
describe("editor topbar insert form validation", function() {
|
||||
this.timeout(10 * 1000)
|
||||
|
||||
it("should produce no errors for a valid form", () => {
|
||||
const form = fromJS({
|
||||
fielda: {
|
||||
value: "test value",
|
||||
isRequired: true,
|
||||
name: "field a"
|
||||
},
|
||||
fieldb: {
|
||||
value: [
|
||||
{ value: "value a", isRequired: false, isValid: () => true },
|
||||
{ value: "value b", isRequired: false, isValid: () => true }
|
||||
],
|
||||
isRequired: true
|
||||
},
|
||||
fieldc: {
|
||||
value: "",
|
||||
isRequired: false
|
||||
}
|
||||
})
|
||||
|
||||
const errors = checkForErrors(form)[1]
|
||||
const updatedForm = checkForErrors(form)[0]
|
||||
|
||||
expect(errors).toEqual(false)
|
||||
expect(updatedForm.getIn(["fielda", "value"])).toEqual("test value")
|
||||
expect(updatedForm.getIn(["fieldb", "hasErrors"])).toEqual(false)
|
||||
})
|
||||
|
||||
it("should produce errors for a form with an empty required value", () => {
|
||||
const form = fromJS({
|
||||
fielda: {
|
||||
value: "",
|
||||
isRequired: true,
|
||||
name: "field a"
|
||||
}
|
||||
})
|
||||
|
||||
const errors = checkForErrors(form)[1]
|
||||
const updatedForm = checkForErrors(form)[0]
|
||||
|
||||
expect(errors).toBeTruthy()
|
||||
expect(updatedForm.getIn(["fielda", "value"])).toEqual("")
|
||||
expect(updatedForm.getIn(["fielda", "hasErrors"])).toBeTruthy()
|
||||
})
|
||||
|
||||
it("should produce errors for a form with data that does not meet validation", () => {
|
||||
const form = fromJS({
|
||||
fielda: {
|
||||
value: "@#*&$*@)#$&@#*$",
|
||||
isRequired: false,
|
||||
name: "field a",
|
||||
isValid: () => false
|
||||
}
|
||||
})
|
||||
|
||||
const errors = checkForErrors(form)[1]
|
||||
const updatedForm = checkForErrors(form)[0]
|
||||
|
||||
expect(errors).toBeTruthy()
|
||||
expect(updatedForm.getIn(["fielda", "value"])).toEqual("@#*&$*@)#$&@#*$")
|
||||
expect(updatedForm.getIn(["fielda", "hasErrors"])).toBeTruthy()
|
||||
})
|
||||
|
||||
it("should correctly validate valid urls", () => {
|
||||
expect(validateUrl("https://petstore.swagger.io")).toBeTruthy()
|
||||
expect(validateUrl("https://www.bing.com/search?q=open+api&qs=n&form=QBLH&sp=-1&pq=open+api&sc=6-8&sk=&cvid=2B4FC1A0686B42FAA4DE3534FDA56A8B")).toBeTruthy()
|
||||
})
|
||||
|
||||
it ("should correctly validate invalid urls", () => {
|
||||
expect(validateUrl("")).toBeFalsy()
|
||||
expect(validateUrl("test")).toBeFalsy()
|
||||
})
|
||||
|
||||
it ("should correctly validate alphanumeric strings", () => {
|
||||
expect(validateAlphaNum("abcde12345")).toBeTruthy()
|
||||
expect(validateAlphaNum("42")).toBeTruthy()
|
||||
expect(validateAlphaNum("AaBbCc")).toBeTruthy()
|
||||
})
|
||||
|
||||
it ("should correctly validate invalid alphanumeric strings", () => {
|
||||
expect(validateAlphaNum("")).toBeFalsy()
|
||||
expect(validateAlphaNum("abc@123")).toBeFalsy()
|
||||
expect(validateAlphaNum("*")).toBeFalsy()
|
||||
})
|
||||
|
||||
it ("should correctly detect an empty value", () => {
|
||||
expect(checkForEmptyValue(new OrderedMap())).toBeTruthy()
|
||||
expect(checkForEmptyValue(" ")).toBeTruthy()
|
||||
expect(checkForEmptyValue([])).toBeTruthy()
|
||||
expect(checkForEmptyValue(new List())).toBeTruthy()
|
||||
expect(checkForEmptyValue("")).toBeTruthy()
|
||||
})
|
||||
|
||||
it ("should correclty detect a non-empty value", () => {
|
||||
expect(checkForEmptyValue("value")).toBeFalsy()
|
||||
expect(checkForEmptyValue(fromJS({ test: ""}))).toBeFalsy()
|
||||
expect(checkForEmptyValue(fromJS([""]))).toBeFalsy()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,136 @@
|
||||
import expect from "expect"
|
||||
import React from "react"
|
||||
import SwaggerUi from "swagger-ui"
|
||||
import insertPlugin from "src/standalone/topbar-insert"
|
||||
import { fromJS } from "immutable"
|
||||
import { configure, mount } from "enzyme"
|
||||
import Adapter from "enzyme-adapter-react-15"
|
||||
|
||||
configure({ adapter: new Adapter() })
|
||||
|
||||
function getSystem(spec) {
|
||||
return new Promise((resolve) => {
|
||||
const system = SwaggerUi({
|
||||
spec,
|
||||
domNode: null,
|
||||
presets: [
|
||||
SwaggerUi.plugins.SpecIndex,
|
||||
SwaggerUi.plugins.ErrIndex,
|
||||
SwaggerUi.plugins.DownloadUrl,
|
||||
SwaggerUi.plugins.SwaggerJsIndex,
|
||||
],
|
||||
initialState: {
|
||||
layout: undefined
|
||||
},
|
||||
plugins: [
|
||||
insertPlugin,
|
||||
() => ({
|
||||
statePlugins: {
|
||||
spec: {
|
||||
wrapSelectors: {
|
||||
isOAS3: () => () => true
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
() => ({
|
||||
statePlugins: {
|
||||
configs: {
|
||||
actions: {
|
||||
loaded: () => {
|
||||
return {
|
||||
type: "noop"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
resolve(system)
|
||||
})
|
||||
}
|
||||
|
||||
describe("editor topbar insert menu plugin", function() {
|
||||
this.timeout(10 * 1000)
|
||||
|
||||
it("should provide a `addToSpec` method as a spec action", async () => {
|
||||
const spec = {}
|
||||
const system = await getSystem(spec)
|
||||
expect(system.specActions.addToSpec).toBeA(Function)
|
||||
})
|
||||
|
||||
it("should provide an <InsertMenu /> component to render a menu option", async function(){
|
||||
const spec = {}
|
||||
const system = await getSystem(spec)
|
||||
const InsertMenu = system.getSystem().getComponents("TopbarInsert")
|
||||
let wrapper = mount(<InsertMenu {...system} getComponent={(c) => system.getSystem().getComponents(c)} />)
|
||||
expect(wrapper.find(".menu-item").length).toEqual(1)
|
||||
})
|
||||
|
||||
it("should correctly update the spec when addToSpec is called", async () => {
|
||||
const spec = {
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "My New Service"
|
||||
},
|
||||
"paths": {
|
||||
"/test": {
|
||||
"get": {
|
||||
"summary": "Sample endpoint for my awesome service.",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const toAdd = fromJS({
|
||||
"summary": "Sample endpoint for my awesome service.",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const expected = {
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "My New Service"
|
||||
},
|
||||
"paths": {
|
||||
"/test": {
|
||||
"get": {
|
||||
"summary": "Sample endpoint for my awesome service.",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"summary": "Sample endpoint for my awesome service.",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const system = await getSystem(spec)
|
||||
|
||||
system.specActions.addToSpec(["paths", "/test"], toAdd, "post")
|
||||
expect(system.specSelectors.specJson().toJS()).toEqual(expected)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user