-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: align tests with sample plugin changes
Refs #8577
- Loading branch information
Showing
4 changed files
with
302 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
}) | ||
}) |
Oops, something went wrong.