Skip to content

Commit

Permalink
test: align tests with sample plugin changes
Browse files Browse the repository at this point in the history
Refs #8577
  • Loading branch information
char0n committed May 31, 2023
1 parent 861218a commit ac2ca23
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 136 deletions.
2 changes: 1 addition & 1 deletion src/core/plugins/oas3/components/request-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const RequestBody = ({
}
if (type === "object" || useInitialValue) {
// TODO: what about example or examples from requestBody could be passed as exampleOverride
initialValue = getSampleSchema(prop, false, {
initialValue = fn.getSampleSchema(prop, false, {
includeWriteOnly: true
})
}
Expand Down
124 changes: 87 additions & 37 deletions test/unit/bugs/4557-default-parameter-values.jsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,128 @@

/**
* @prettier
*/
import React from "react"
import { List, fromJS } from "immutable"

import { render } from "enzyme"
import ParameterRow from "components/parameter-row"

describe("bug #4557: default parameter values", function(){
it("should apply a Swagger 2.0 default value", function(){
import ParameterRow from "components/parameter-row"
import {
memoizedSampleFromSchema,
memoizedCreateXMLExample,
} from "core/plugins/samples/fn/index"
import makeGetSampleSchema from "core/plugins/samples/fn/get-sample-schema"
import makeGetJsonSampleSchema from "core/plugins/samples/fn/get-json-sample-schema"
import makeGetYamlSampleSchema from "core/plugins/samples/fn/get-yaml-sample-schema"
import makeGetXmlSampleSchema from "core/plugins/samples/fn/get-xml-sample-schema"

describe("bug #4557: default parameter values", function () {
it("should apply a Swagger 2.0 default value", function () {
const paramValue = fromJS({
description: "a pet",
type: "string",
default: "MyDefaultValue"
default: "MyDefaultValue",
})

let props = {
getComponent: ()=> "div",
const getSystem = () => ({
getComponent: () => "div",
specSelectors: {
security(){},
parameterWithMetaByIdentity(){ return paramValue },
isOAS3(){ return false },
isSwagger2(){ return true }
security() {},
parameterWithMetaByIdentity() {
return paramValue
},
isOAS3() {
return false
},
isSwagger2() {
return true
},
},
getConfigs: () => {
return {}
},
fn: {
memoizedSampleFromSchema,
memoizedCreateXMLExample,
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
getSampleSchema: makeGetSampleSchema(getSystem),
},
fn: {},
operation: {get: ()=>{}},
})
const props = {
...getSystem(),
operation: { get: () => {} },
onChange: jest.fn(),
param: paramValue,
rawParam: paramValue,
onChangeConsumes: () => {},
pathMethod: [],
getConfigs: () => { return {} },
specPath: List([])
specPath: List([]),
}

render(<ParameterRow {...props}/>)
render(<ParameterRow {...props} />)

expect(props.onChange).toHaveBeenCalled()
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false)
expect(props.onChange).toHaveBeenCalledWith(
paramValue,
"MyDefaultValue",
false
)
})
it("should apply an OpenAPI 3.0 default value", function(){

it("should apply an OpenAPI 3.0 default value", function () {
const paramValue = fromJS({
description: "a pet",
schema: {
type: "string",
default: "MyDefaultValue"
}
default: "MyDefaultValue",
},
})

let props = {
getComponent: ()=> "div",
const getSystem = () => ({
getComponent: () => "div",
specSelectors: {
security(){},
parameterWithMetaByIdentity(){ return paramValue },
isOAS3(){ return true },
isSwagger2() { return false }
security() {},
parameterWithMetaByIdentity() {
return paramValue
},
isOAS3() {
return true
},
isSwagger2() {
return false
},
},
oas3Selectors: {
activeExamplesMember: () => null
activeExamplesMember: () => null,
},
fn: {},
operation: {get: ()=>{}},
getConfigs: () => {
return {}
},
fn: {
memoizedSampleFromSchema,
memoizedCreateXMLExample,
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
getSampleSchema: makeGetSampleSchema(getSystem),
},
})
const props = {
...getSystem(),
operation: { get: () => {} },
onChange: jest.fn(),
param: paramValue,
rawParam: paramValue,
onChangeConsumes: () => {},
pathMethod: [],
getConfigs: () => { return {} },
specPath: List([])
specPath: List([]),
}

render(<ParameterRow {...props}/>)
render(<ParameterRow {...props} />)

expect(props.onChange).toHaveBeenCalled()
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false)
expect(props.onChange).toHaveBeenCalledWith(
paramValue,
"MyDefaultValue",
false
)
})
})
Loading

0 comments on commit ac2ca23

Please sign in to comment.