Fix global state issues with Schemes component
This commit is contained in:
@@ -9,10 +9,12 @@ import Schemes from "components/schemes"
|
||||
describe("<Schemes/>", function(){
|
||||
it("calls props.specActions.setScheme() when no operationScheme is selected", function(){
|
||||
|
||||
let setSchemeSpy = createSpy()
|
||||
|
||||
// Given
|
||||
let props = {
|
||||
specActions: {
|
||||
setScheme: createSpy()
|
||||
setScheme: setSchemeSpy
|
||||
},
|
||||
schemes: fromJS([
|
||||
"http",
|
||||
@@ -22,7 +24,7 @@ describe("<Schemes/>", function(){
|
||||
path: "/test",
|
||||
method: "get"
|
||||
}
|
||||
|
||||
|
||||
// When
|
||||
let wrapper = shallow(<Schemes {...props}/>)
|
||||
|
||||
@@ -38,4 +40,33 @@ describe("<Schemes/>", function(){
|
||||
// Then operationScheme should default to first scheme in options list
|
||||
expect(props.specActions.setScheme).toHaveBeenCalledWith("https", "/test", "get")
|
||||
})
|
||||
|
||||
it.only("doesn't call props.specActions.setScheme() when schemes hasn't changed", function(){
|
||||
|
||||
let setSchemeSpy = createSpy()
|
||||
|
||||
// Given
|
||||
let props = {
|
||||
specActions: {
|
||||
setScheme: setSchemeSpy
|
||||
},
|
||||
schemes: fromJS([
|
||||
"http",
|
||||
"https"
|
||||
]),
|
||||
operationScheme: "https"
|
||||
}
|
||||
|
||||
// When
|
||||
let wrapper = shallow(<Schemes {...props}/>)
|
||||
|
||||
// Should be called initially, to set the global state
|
||||
expect(setSchemeSpy.calls.length).toEqual(1)
|
||||
|
||||
// After an update
|
||||
wrapper.instance().componentWillReceiveProps(props)
|
||||
|
||||
// Should not be called again, since `operationScheme` is in schemes
|
||||
expect(setSchemeSpy.calls.length).toEqual(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user