|
1 | | - |
| 1 | +/** |
| 2 | + * @prettier |
| 3 | + */ |
2 | 4 | import React from "react" |
3 | 5 | import { List, fromJS } from "immutable" |
4 | | - |
5 | 6 | import { render } from "enzyme" |
6 | | -import ParameterRow from "components/parameter-row" |
7 | 7 |
|
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" |
10 | 17 |
|
| 18 | +describe("bug #4557: default parameter values", function () { |
| 19 | + it("should apply a Swagger 2.0 default value", function () { |
11 | 20 | const paramValue = fromJS({ |
12 | 21 | description: "a pet", |
13 | 22 | type: "string", |
14 | | - default: "MyDefaultValue" |
| 23 | + default: "MyDefaultValue", |
15 | 24 | }) |
16 | | - |
17 | | - let props = { |
18 | | - getComponent: ()=> "div", |
| 25 | + const getSystem = () => ({ |
| 26 | + getComponent: () => "div", |
19 | 27 | 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), |
24 | 49 | }, |
25 | | - fn: {}, |
26 | | - operation: {get: ()=>{}}, |
| 50 | + }) |
| 51 | + const props = { |
| 52 | + ...getSystem(), |
| 53 | + operation: { get: () => {} }, |
27 | 54 | onChange: jest.fn(), |
28 | 55 | param: paramValue, |
29 | 56 | rawParam: paramValue, |
30 | 57 | onChangeConsumes: () => {}, |
31 | 58 | pathMethod: [], |
32 | | - getConfigs: () => { return {} }, |
33 | | - specPath: List([]) |
| 59 | + specPath: List([]), |
34 | 60 | } |
35 | 61 |
|
36 | | - render(<ParameterRow {...props}/>) |
| 62 | + render(<ParameterRow {...props} />) |
37 | 63 |
|
38 | 64 | expect(props.onChange).toHaveBeenCalled() |
39 | | - expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false) |
| 65 | + expect(props.onChange).toHaveBeenCalledWith( |
| 66 | + paramValue, |
| 67 | + "MyDefaultValue", |
| 68 | + false |
| 69 | + ) |
40 | 70 | }) |
41 | | - it("should apply an OpenAPI 3.0 default value", function(){ |
42 | | - |
| 71 | + it("should apply an OpenAPI 3.0 default value", function () { |
43 | 72 | const paramValue = fromJS({ |
44 | 73 | description: "a pet", |
45 | 74 | schema: { |
46 | 75 | type: "string", |
47 | | - default: "MyDefaultValue" |
48 | | - } |
| 76 | + default: "MyDefaultValue", |
| 77 | + }, |
49 | 78 | }) |
50 | | - |
51 | | - let props = { |
52 | | - getComponent: ()=> "div", |
| 79 | + const getSystem = () => ({ |
| 80 | + getComponent: () => "div", |
53 | 81 | 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 | + }, |
58 | 92 | }, |
59 | 93 | oas3Selectors: { |
60 | | - activeExamplesMember: () => null |
| 94 | + activeExamplesMember: () => null, |
61 | 95 | }, |
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: () => {} }, |
64 | 111 | onChange: jest.fn(), |
65 | 112 | param: paramValue, |
66 | 113 | rawParam: paramValue, |
67 | 114 | onChangeConsumes: () => {}, |
68 | 115 | pathMethod: [], |
69 | | - getConfigs: () => { return {} }, |
70 | | - specPath: List([]) |
| 116 | + specPath: List([]), |
71 | 117 | } |
72 | 118 |
|
73 | | - render(<ParameterRow {...props}/>) |
| 119 | + render(<ParameterRow {...props} />) |
74 | 120 |
|
75 | 121 | expect(props.onChange).toHaveBeenCalled() |
76 | | - expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false) |
| 122 | + expect(props.onChange).toHaveBeenCalledWith( |
| 123 | + paramValue, |
| 124 | + "MyDefaultValue", |
| 125 | + false |
| 126 | + ) |
77 | 127 | }) |
78 | 128 | }) |
0 commit comments