123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- import React from "react"
- import { List, fromJS } from "immutable"
- import { render } from "enzyme"
- import ParameterRow from "components/parameter-row"
- describe("<ParameterRow/>", () => {
- const createProps = ({ param, isOAS3 }) => ({
- getComponent: () => "div",
- specSelectors: {
- parameterWithMetaByIdentity: () => param,
- isOAS3: () => isOAS3,
- isSwagger2: () => !isOAS3
- },
- oas3Selectors: { activeExamplesMember: () => {} },
- param,
- rawParam: param,
- pathMethod: [],
- getConfigs: () => ({})
- })
- it("Can render Swagger 2 parameter type with format", () => {
- const param = fromJS({
- name: "petUuid",
- in: "path",
- description: "UUID that identifies a pet",
- type: "string",
- format: "uuid"
- })
- const props = createProps({ param, isOAS3: false })
- const wrapper = render(<ParameterRow {...props}/>)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)")
- })
- it("Can render Swagger 2 parameter type without format", () => {
- const param = fromJS({
- name: "petId",
- in: "path",
- description: "ID that identifies a pet",
- type: "string"
- })
- const props = createProps({ param, isOAS3: false })
- const wrapper = render(<ParameterRow {...props}/>)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("string")
- })
- it("Can render OAS3 parameter type with format", () => {
- const param = fromJS({
- name: "petUuid",
- in: "path",
- description: "UUID that identifies a pet",
- schema: {
- type: "string",
- format: "uuid"
- }
- })
- const props = createProps({ param, isOAS3: true })
- const wrapper = render(<ParameterRow {...props}/>)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)")
- })
- it("Can render OAS3 parameter type without format", () => {
- const param = fromJS({
- name: "petId",
- in: "path",
- description: "ID that identifies a pet",
- schema: {
- type: "string"
- }
- })
- const props = createProps({ param, isOAS3: true })
- const wrapper = render(<ParameterRow {...props}/>)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("string")
- })
- })
- describe("bug #5573: zero default and example values", function () {
- it("should apply a Swagger 2.0 default value of zero", function () {
- const paramValue = fromJS({
- description: "a pet",
- type: "integer",
- default: 0
- })
- let props = {
- getComponent: () => "div",
- specSelectors: {
- security() { },
- parameterWithMetaByIdentity() { return paramValue },
- isOAS3() { return false },
- isSwagger2() { return true }
- },
- fn: {},
- operation: { get: () => { } },
- onChange: jest.fn(),
- param: paramValue,
- rawParam: paramValue,
- onChangeConsumes: () => { },
- pathMethod: [],
- getConfigs: () => { return {} },
- specPath: List([])
- }
- render(<ParameterRow {...props} />)
- expect(props.onChange).toHaveBeenCalled()
- expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
- })
- it("should apply a Swagger 2.0 example value of zero", function () {
- const paramValue = fromJS({
- description: "a pet",
- type: "integer",
- schema: {
- example: 0
- }
- })
- let props = {
- getComponent: () => "div",
- specSelectors: {
- security() { },
- parameterWithMetaByIdentity() { return paramValue },
- isOAS3() { return false },
- isSwagger2() { return true }
- },
- fn: {},
- operation: { get: () => { } },
- onChange: jest.fn(),
- param: paramValue,
- rawParam: paramValue,
- onChangeConsumes: () => { },
- pathMethod: [],
- getConfigs: () => { return {} },
- specPath: List([])
- }
- render(<ParameterRow {...props} />)
- expect(props.onChange).toHaveBeenCalled()
- expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
- })
- it("should apply an OpenAPI 3.0 default value of zero", function () {
- const paramValue = fromJS({
- description: "a pet",
- schema: {
- type: "integer",
- default: 0
- }
- })
- let props = {
- getComponent: () => "div",
- specSelectors: {
- security() { },
- parameterWithMetaByIdentity() { return paramValue },
- isOAS3() { return true },
- isSwagger2() { return false }
- },
- oas3Selectors: {
- activeExamplesMember: () => null
- },
- fn: {},
- operation: { get: () => { } },
- onChange: jest.fn(),
- param: paramValue,
- rawParam: paramValue,
- onChangeConsumes: () => { },
- pathMethod: [],
- getConfigs: () => { return {} },
- specPath: List([])
- }
- render(<ParameterRow {...props} />)
- expect(props.onChange).toHaveBeenCalled()
- expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
- })
- it("should apply an OpenAPI 3.0 example value of zero", function () {
- const paramValue = fromJS({
- description: "a pet",
- schema: {
- type: "integer",
- example: 0
- }
- })
- let props = {
- getComponent: () => "div",
- specSelectors: {
- security() { },
- parameterWithMetaByIdentity() { return paramValue },
- isOAS3() { return true },
- isSwagger2() { return false }
- },
- oas3Selectors: {
- activeExamplesMember: () => null
- },
- fn: {},
- operation: { get: () => { } },
- onChange: jest.fn(),
- param: paramValue,
- rawParam: paramValue,
- onChangeConsumes: () => { },
- pathMethod: [],
- getConfigs: () => { return {} },
- specPath: List([])
- }
- render(<ParameterRow {...props} />)
- expect(props.onChange).toHaveBeenCalled()
- expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
- })
- })
|