Skip to content

Commit df43e96

Browse files
authored
Merge branch 'master' into remove-array-model-name
2 parents ca937f4 + 0c28a50 commit df43e96

File tree

4 files changed

+74
-5
lines changed

4 files changed

+74
-5
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
}

src/core/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function fromJSOrdered (js) {
4141
return !isObject(js) ? js :
4242
Array.isArray(js) ?
4343
Im.Seq(js).map(fromJSOrdered).toList() :
44-
Im.Seq(js).map(fromJSOrdered).toOrderedMap()
44+
Im.OrderedMap(js).map(fromJSOrdered)
4545
}
4646

4747
export function bindToState(obj, state) {

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+
})

test/core/utils.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-env mocha */
22
import expect from "expect"
33
import { fromJS } from "immutable"
4-
import { mapToList, validateNumber, validateInteger, validateParam, validateFile } from "core/utils"
4+
import { mapToList, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered } from "core/utils"
55
import win from "core/window"
66

7-
describe("utils", function(){
7+
describe("utils", function() {
88

99
describe("mapToList", function(){
1010

@@ -544,4 +544,31 @@ describe("utils", function(){
544544
expect( result ).toEqual( [] )
545545
})
546546
})
547+
548+
describe("fromJSOrdered", () => {
549+
it("should create an OrderedMap from an object", () => {
550+
const param = {
551+
value: "test"
552+
}
553+
554+
const result = fromJSOrdered(param).toJS()
555+
expect( result ).toEqual( { value: "test" } )
556+
})
557+
558+
it("should not use an object's length property for Map size", () => {
559+
const param = {
560+
length: 5
561+
}
562+
563+
const result = fromJSOrdered(param).toJS()
564+
expect( result ).toEqual( { length: 5 } )
565+
})
566+
567+
it("should create an OrderedMap from an array", () => {
568+
const param = [1, 1, 2, 3, 5, 8]
569+
570+
const result = fromJSOrdered(param).toJS()
571+
expect( result ).toEqual( [1, 1, 2, 3, 5, 8] )
572+
})
573+
})
547574
})

0 commit comments

Comments
 (0)