@@ -7,35 +7,66 @@ import { fromJS } from "immutable"
77import Schemes from "components/schemes"
88
99describe ( "<Schemes/>" , function ( ) {
10- it ( "calls props.specActions.setScheme() when no operationScheme is selected" , function ( ) {
10+ it ( "calls props.specActions.setScheme() when no currentScheme is selected" , function ( ) {
11+
12+ let setSchemeSpy = createSpy ( )
1113
1214 // Given
1315 let props = {
1416 specActions : {
15- setScheme : createSpy ( )
17+ setScheme : setSchemeSpy
1618 } ,
1719 schemes : fromJS ( [
1820 "http" ,
1921 "https"
2022 ] ) ,
21- operationScheme : undefined ,
23+ currentScheme : undefined ,
2224 path : "/test" ,
2325 method : "get"
2426 }
25-
27+
2628 // When
2729 let wrapper = shallow ( < Schemes { ...props } /> )
2830
29- // Then operationScheme should default to first scheme in options list
31+ // Then currentScheme should default to first scheme in options list
3032 expect ( props . specActions . setScheme ) . toHaveBeenCalledWith ( "http" , "/test" , "get" )
3133
32- // When the operationScheme is no longer in the list of options
34+ // When the currentScheme is no longer in the list of options
3335 props . schemes = fromJS ( [
3436 "https"
3537 ] )
3638 wrapper . setProps ( props )
3739
38- // Then operationScheme should default to first scheme in options list
40+ // Then currentScheme should default to first scheme in options list, again
3941 expect ( props . specActions . setScheme ) . toHaveBeenCalledWith ( "https" , "/test" , "get" )
4042 } )
43+
44+ it ( "doesn't call props.specActions.setScheme() when schemes hasn't changed" , function ( ) {
45+
46+ let setSchemeSpy = createSpy ( )
47+
48+ // Given
49+ let props = {
50+ specActions : {
51+ setScheme : setSchemeSpy
52+ } ,
53+ schemes : fromJS ( [
54+ "http" ,
55+ "https"
56+ ] ) ,
57+ currentScheme : "https"
58+ }
59+
60+ // When
61+ let wrapper = shallow ( < Schemes { ...props } /> )
62+
63+ // Should be called initially, to set the global state
64+ expect ( setSchemeSpy . calls . length ) . toEqual ( 1 )
65+
66+ // After an update
67+ wrapper . instance ( ) . componentWillReceiveProps ( props )
68+
69+ // Should not be called again, since `currentScheme` is in schemes
70+ expect ( setSchemeSpy . calls . length ) . toEqual ( 1 )
71+ } )
4172} )
0 commit comments