Skip to content

Commit 16364fb

Browse files
committed
Merge branch 'master' of github.com:swagger-api/swagger-ui into bug/3596-permalink-encoding
2 parents 430e2a9 + c7cb902 commit 16364fb

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

src/core/components/response.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react"
22
import PropTypes from "prop-types"
33
import { fromJS, Seq } from "immutable"
4-
import { getSampleSchema } from "core/utils"
4+
import { getSampleSchema, fromJSOrdered } from "core/utils"
55

66
const getExampleComponent = ( sampleResponse, examples, HighlightCode ) => {
77
if ( examples && examples.size ) {
@@ -58,7 +58,6 @@ export default class Response extends React.Component {
5858
code,
5959
response,
6060
className,
61-
6261
fn,
6362
getComponent,
6463
specSelectors,
@@ -117,7 +116,7 @@ export default class Response extends React.Component {
117116
<ModelExample
118117
getComponent={ getComponent }
119118
specSelectors={ specSelectors }
120-
schema={ fromJS(schema, (key, value) => value.toOrderedMap() ) }
119+
schema={ fromJSOrdered(schema) }
121120
example={ example }/>
122121
) : null}
123122

test/components/response.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React from "react"
2+
import expect from "expect"
3+
import { shallow } from "enzyme"
4+
import { fromJS } from "immutable"
5+
import Response from "components/response"
6+
import ModelExample from "components/model-example"
7+
import { inferSchema } from "corePlugins/samples/fn"
8+
9+
describe("<Response />", function() {
10+
const dummyComponent = () => null
11+
const components = {
12+
headers: dummyComponent,
13+
highlightCode: dummyComponent,
14+
modelExample: ModelExample,
15+
Markdown: dummyComponent,
16+
operationLink: dummyComponent,
17+
contentType: dummyComponent
18+
}
19+
const props = {
20+
getComponent: c => components[c],
21+
specSelectors: {
22+
isOAS3() {
23+
return false
24+
}
25+
},
26+
fn: {
27+
inferSchema
28+
},
29+
contentType: "application/json",
30+
className: "for-test",
31+
response: fromJS({
32+
type: "object",
33+
properties: {
34+
// Note reverse order: c, b, a
35+
"c": {
36+
type: "integer"
37+
},
38+
"b": {
39+
type: "boolean"
40+
},
41+
"a": {
42+
type: "string"
43+
}
44+
}
45+
}),
46+
code: "200"
47+
}
48+
49+
it("renders the model-example schema properties in order", function() {
50+
const wrapper = shallow(<Response {...props}/>)
51+
const renderedModelExample = wrapper.find(ModelExample)
52+
expect(renderedModelExample.length).toEqual(1)
53+
54+
// Assert the schema's properties have maintained their order
55+
const modelExampleSchemaProperties = renderedModelExample.props().schema.toJS().properties
56+
expect( Object.keys(modelExampleSchemaProperties) ).toEqual(["c", "b", "a"])
57+
})
58+
})

0 commit comments

Comments
 (0)