Skip to content

Commit 2ce9d08

Browse files
committed
test: align tests with sample plugin changes
Refs #8577
1 parent 1ce9ce0 commit 2ce9d08

File tree

5 files changed

+306
-138
lines changed

5 files changed

+306
-138
lines changed

src/core/plugins/oas3/components/request-body.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const RequestBody = ({
175175
}
176176
if (type === "object" || useInitialValue) {
177177
// TODO: what about example or examples from requestBody could be passed as exampleOverride
178-
initialValue = getSampleSchema(prop, false, {
178+
initialValue = fn.getSampleSchema(prop, false, {
179179
includeWriteOnly: true
180180
})
181181
}
@@ -242,6 +242,7 @@ const RequestBody = ({
242242
requestBody,
243243
contentType,
244244
activeExamplesKey,
245+
fn,
245246
)
246247
let language = null
247248
let testValueForJson = getKnownSyntaxHighlighterLanguage(sampleRequestBody)

src/core/plugins/oas3/selectors.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const selectDefaultRequestBodyValue =
103103
}
104104

105105
export const hasUserEditedBody = onlyOAS3((state, path, method) => (system) => {
106-
const { oas3Selectors, specSelectors } = system
106+
const { oas3Selectors, specSelectors, fn } = system
107107

108108
let userHasEditedBody = false
109109
const currentMediaType = oas3Selectors.requestContentType(path, method)
@@ -147,7 +147,8 @@ export const hasUserEditedBody = onlyOAS3((state, path, method) => (system) => {
147147
method,
148148
"requestBody",
149149
"requestBody"
150-
)
150+
),
151+
fn
151152
)
152153
userHasEditedBody =
153154
!!userEditedRequestBody &&
Lines changed: 87 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,128 @@
1-
1+
/**
2+
* @prettier
3+
*/
24
import React from "react"
35
import { List, fromJS } from "immutable"
4-
56
import { render } from "enzyme"
6-
import ParameterRow from "components/parameter-row"
77

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

18+
describe("bug #4557: default parameter values", function () {
19+
it("should apply a Swagger 2.0 default value", function () {
1120
const paramValue = fromJS({
1221
description: "a pet",
1322
type: "string",
14-
default: "MyDefaultValue"
23+
default: "MyDefaultValue",
1524
})
16-
17-
let props = {
18-
getComponent: ()=> "div",
25+
const getSystem = () => ({
26+
getComponent: () => "div",
1927
specSelectors: {
20-
security(){},
21-
parameterWithMetaByIdentity(){ return paramValue },
22-
isOAS3(){ return false },
23-
isSwagger2(){ return true }
28+
security() {},
29+
parameterWithMetaByIdentity() {
30+
return paramValue
31+
},
32+
isOAS3() {
33+
return false
34+
},
35+
isSwagger2() {
36+
return true
37+
},
38+
},
39+
getConfigs: () => {
40+
return {}
41+
},
42+
fn: {
43+
memoizedSampleFromSchema,
44+
memoizedCreateXMLExample,
45+
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
46+
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
47+
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
48+
getSampleSchema: makeGetSampleSchema(getSystem),
2449
},
25-
fn: {},
26-
operation: {get: ()=>{}},
50+
})
51+
const props = {
52+
...getSystem(),
53+
operation: { get: () => {} },
2754
onChange: jest.fn(),
2855
param: paramValue,
2956
rawParam: paramValue,
3057
onChangeConsumes: () => {},
3158
pathMethod: [],
32-
getConfigs: () => { return {} },
33-
specPath: List([])
59+
specPath: List([]),
3460
}
3561

36-
render(<ParameterRow {...props}/>)
62+
render(<ParameterRow {...props} />)
3763

3864
expect(props.onChange).toHaveBeenCalled()
39-
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false)
65+
expect(props.onChange).toHaveBeenCalledWith(
66+
paramValue,
67+
"MyDefaultValue",
68+
false
69+
)
4070
})
41-
it("should apply an OpenAPI 3.0 default value", function(){
42-
71+
it("should apply an OpenAPI 3.0 default value", function () {
4372
const paramValue = fromJS({
4473
description: "a pet",
4574
schema: {
4675
type: "string",
47-
default: "MyDefaultValue"
48-
}
76+
default: "MyDefaultValue",
77+
},
4978
})
50-
51-
let props = {
52-
getComponent: ()=> "div",
79+
const getSystem = () => ({
80+
getComponent: () => "div",
5381
specSelectors: {
54-
security(){},
55-
parameterWithMetaByIdentity(){ return paramValue },
56-
isOAS3(){ return true },
57-
isSwagger2() { return false }
82+
security() {},
83+
parameterWithMetaByIdentity() {
84+
return paramValue
85+
},
86+
isOAS3() {
87+
return true
88+
},
89+
isSwagger2() {
90+
return false
91+
},
5892
},
5993
oas3Selectors: {
60-
activeExamplesMember: () => null
94+
activeExamplesMember: () => null,
6195
},
62-
fn: {},
63-
operation: {get: ()=>{}},
96+
getConfigs: () => {
97+
return {}
98+
},
99+
fn: {
100+
memoizedSampleFromSchema,
101+
memoizedCreateXMLExample,
102+
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
103+
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
104+
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
105+
getSampleSchema: makeGetSampleSchema(getSystem),
106+
},
107+
})
108+
const props = {
109+
...getSystem(),
110+
operation: { get: () => {} },
64111
onChange: jest.fn(),
65112
param: paramValue,
66113
rawParam: paramValue,
67114
onChangeConsumes: () => {},
68115
pathMethod: [],
69-
getConfigs: () => { return {} },
70-
specPath: List([])
116+
specPath: List([]),
71117
}
72118

73-
render(<ParameterRow {...props}/>)
119+
render(<ParameterRow {...props} />)
74120

75121
expect(props.onChange).toHaveBeenCalled()
76-
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false)
122+
expect(props.onChange).toHaveBeenCalledWith(
123+
paramValue,
124+
"MyDefaultValue",
125+
false
126+
)
77127
})
78128
})

0 commit comments

Comments
 (0)