Skip to content

Commit 0c28a50

Browse files
authored
Merge pull request #3411 from owenconti/bug/3405-default-scheme-change
Fixes #3405 - Fixed selecting default scheme in schemes.jsx
2 parents 94da83d + e64e438 commit 0c28a50

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/core/components/schemes.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export default class Schemes extends React.Component {
1919
}
2020

2121
componentWillReceiveProps(nextProps) {
22-
if ( this.props.operationScheme && !nextProps.schemes.has(this.props.operationScheme) ) {
23-
//fire 'change' event if our selected scheme is no longer an option
22+
if ( !this.props.operationScheme || !nextProps.schemes.has(this.props.operationScheme) ) {
23+
// if we don't have a selected operationScheme or if our selected scheme is no longer an option,
24+
// then fire 'change' event and select the first scheme in the list of options
2425
this.setScheme(nextProps.schemes.first())
2526
}
2627
}

test/components/schemes.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
/* eslint-env mocha */
3+
import React from "react"
4+
import expect, { createSpy } from "expect"
5+
import { shallow } from "enzyme"
6+
import { fromJS } from "immutable"
7+
import Schemes from "components/schemes"
8+
9+
describe("<Schemes/>", function(){
10+
it("calls props.specActions.setScheme() when no operationScheme is selected", function(){
11+
12+
// Given
13+
let props = {
14+
specActions: {
15+
setScheme: createSpy()
16+
},
17+
schemes: fromJS([
18+
"http",
19+
"https"
20+
]),
21+
operationScheme: undefined,
22+
path: "/test",
23+
method: "get"
24+
}
25+
26+
// When
27+
let wrapper = shallow(<Schemes {...props}/>)
28+
29+
// Then operationScheme should default to first scheme in options list
30+
expect(props.specActions.setScheme).toHaveBeenCalledWith("http", "/test" , "get")
31+
32+
// When the operationScheme is no longer in the list of options
33+
props.schemes = fromJS([
34+
"https"
35+
])
36+
wrapper.setProps(props)
37+
38+
// Then operationScheme should default to first scheme in options list
39+
expect(props.specActions.setScheme).toHaveBeenCalledWith("https", "/test", "get")
40+
})
41+
})

0 commit comments

Comments
 (0)