Merge branch 'master' of github.com:swagger-api/swagger-ui into bug/3596-permalink-encoding
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { fromJS, Seq } from "immutable"
|
import { fromJS, Seq } from "immutable"
|
||||||
import { getSampleSchema } from "core/utils"
|
import { getSampleSchema, fromJSOrdered } from "core/utils"
|
||||||
|
|
||||||
const getExampleComponent = ( sampleResponse, examples, HighlightCode ) => {
|
const getExampleComponent = ( sampleResponse, examples, HighlightCode ) => {
|
||||||
if ( examples && examples.size ) {
|
if ( examples && examples.size ) {
|
||||||
@@ -58,7 +58,6 @@ export default class Response extends React.Component {
|
|||||||
code,
|
code,
|
||||||
response,
|
response,
|
||||||
className,
|
className,
|
||||||
|
|
||||||
fn,
|
fn,
|
||||||
getComponent,
|
getComponent,
|
||||||
specSelectors,
|
specSelectors,
|
||||||
@@ -117,7 +116,7 @@ export default class Response extends React.Component {
|
|||||||
<ModelExample
|
<ModelExample
|
||||||
getComponent={ getComponent }
|
getComponent={ getComponent }
|
||||||
specSelectors={ specSelectors }
|
specSelectors={ specSelectors }
|
||||||
schema={ fromJS(schema, (key, value) => value.toOrderedMap() ) }
|
schema={ fromJSOrdered(schema) }
|
||||||
example={ example }/>
|
example={ example }/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|||||||
58
test/components/response.js
Normal file
58
test/components/response.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import React from "react"
|
||||||
|
import expect from "expect"
|
||||||
|
import { shallow } from "enzyme"
|
||||||
|
import { fromJS } from "immutable"
|
||||||
|
import Response from "components/response"
|
||||||
|
import ModelExample from "components/model-example"
|
||||||
|
import { inferSchema } from "corePlugins/samples/fn"
|
||||||
|
|
||||||
|
describe("<Response />", function() {
|
||||||
|
const dummyComponent = () => null
|
||||||
|
const components = {
|
||||||
|
headers: dummyComponent,
|
||||||
|
highlightCode: dummyComponent,
|
||||||
|
modelExample: ModelExample,
|
||||||
|
Markdown: dummyComponent,
|
||||||
|
operationLink: dummyComponent,
|
||||||
|
contentType: dummyComponent
|
||||||
|
}
|
||||||
|
const props = {
|
||||||
|
getComponent: c => components[c],
|
||||||
|
specSelectors: {
|
||||||
|
isOAS3() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fn: {
|
||||||
|
inferSchema
|
||||||
|
},
|
||||||
|
contentType: "application/json",
|
||||||
|
className: "for-test",
|
||||||
|
response: fromJS({
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
// Note reverse order: c, b, a
|
||||||
|
"c": {
|
||||||
|
type: "integer"
|
||||||
|
},
|
||||||
|
"b": {
|
||||||
|
type: "boolean"
|
||||||
|
},
|
||||||
|
"a": {
|
||||||
|
type: "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
code: "200"
|
||||||
|
}
|
||||||
|
|
||||||
|
it("renders the model-example schema properties in order", function() {
|
||||||
|
const wrapper = shallow(<Response {...props}/>)
|
||||||
|
const renderedModelExample = wrapper.find(ModelExample)
|
||||||
|
expect(renderedModelExample.length).toEqual(1)
|
||||||
|
|
||||||
|
// Assert the schema's properties have maintained their order
|
||||||
|
const modelExampleSchemaProperties = renderedModelExample.props().schema.toJS().properties
|
||||||
|
expect( Object.keys(modelExampleSchemaProperties) ).toEqual(["c", "b", "a"])
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user