Merge pull request #3411 from owenconti/bug/3405-default-scheme-change
Fixes #3405 - Fixed selecting default scheme in schemes.jsx
This commit is contained in:
@@ -19,8 +19,9 @@ export default class Schemes extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if ( this.props.operationScheme && !nextProps.schemes.has(this.props.operationScheme) ) {
|
if ( !this.props.operationScheme || !nextProps.schemes.has(this.props.operationScheme) ) {
|
||||||
//fire 'change' event if our selected scheme is no longer an option
|
// if we don't have a selected operationScheme or if our selected scheme is no longer an option,
|
||||||
|
// then fire 'change' event and select the first scheme in the list of options
|
||||||
this.setScheme(nextProps.schemes.first())
|
this.setScheme(nextProps.schemes.first())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
test/components/schemes.js
Normal file
41
test/components/schemes.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
/* eslint-env mocha */
|
||||||
|
import React from "react"
|
||||||
|
import expect, { createSpy } from "expect"
|
||||||
|
import { shallow } from "enzyme"
|
||||||
|
import { fromJS } from "immutable"
|
||||||
|
import Schemes from "components/schemes"
|
||||||
|
|
||||||
|
describe("<Schemes/>", function(){
|
||||||
|
it("calls props.specActions.setScheme() when no operationScheme is selected", function(){
|
||||||
|
|
||||||
|
// Given
|
||||||
|
let props = {
|
||||||
|
specActions: {
|
||||||
|
setScheme: createSpy()
|
||||||
|
},
|
||||||
|
schemes: fromJS([
|
||||||
|
"http",
|
||||||
|
"https"
|
||||||
|
]),
|
||||||
|
operationScheme: undefined,
|
||||||
|
path: "/test",
|
||||||
|
method: "get"
|
||||||
|
}
|
||||||
|
|
||||||
|
// When
|
||||||
|
let wrapper = shallow(<Schemes {...props}/>)
|
||||||
|
|
||||||
|
// Then operationScheme should default to first scheme in options list
|
||||||
|
expect(props.specActions.setScheme).toHaveBeenCalledWith("http", "/test" , "get")
|
||||||
|
|
||||||
|
// When the operationScheme is no longer in the list of options
|
||||||
|
props.schemes = fromJS([
|
||||||
|
"https"
|
||||||
|
])
|
||||||
|
wrapper.setProps(props)
|
||||||
|
|
||||||
|
// Then operationScheme should default to first scheme in options list
|
||||||
|
expect(props.specActions.setScheme).toHaveBeenCalledWith("https", "/test", "get")
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user