Merge branch 'master' into remove-array-model-name
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,7 +41,7 @@ export function fromJSOrdered (js) {
|
|||||||
return !isObject(js) ? js :
|
return !isObject(js) ? js :
|
||||||
Array.isArray(js) ?
|
Array.isArray(js) ?
|
||||||
Im.Seq(js).map(fromJSOrdered).toList() :
|
Im.Seq(js).map(fromJSOrdered).toList() :
|
||||||
Im.Seq(js).map(fromJSOrdered).toOrderedMap()
|
Im.OrderedMap(js).map(fromJSOrdered)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bindToState(obj, state) {
|
export function bindToState(obj, state) {
|
||||||
|
|||||||
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")
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
import expect from "expect"
|
import expect from "expect"
|
||||||
import { fromJS } from "immutable"
|
import { fromJS } from "immutable"
|
||||||
import { mapToList, validateNumber, validateInteger, validateParam, validateFile } from "core/utils"
|
import { mapToList, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered } from "core/utils"
|
||||||
import win from "core/window"
|
import win from "core/window"
|
||||||
|
|
||||||
describe("utils", function(){
|
describe("utils", function() {
|
||||||
|
|
||||||
describe("mapToList", function(){
|
describe("mapToList", function(){
|
||||||
|
|
||||||
@@ -544,4 +544,31 @@ describe("utils", function(){
|
|||||||
expect( result ).toEqual( [] )
|
expect( result ).toEqual( [] )
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("fromJSOrdered", () => {
|
||||||
|
it("should create an OrderedMap from an object", () => {
|
||||||
|
const param = {
|
||||||
|
value: "test"
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = fromJSOrdered(param).toJS()
|
||||||
|
expect( result ).toEqual( { value: "test" } )
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not use an object's length property for Map size", () => {
|
||||||
|
const param = {
|
||||||
|
length: 5
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = fromJSOrdered(param).toJS()
|
||||||
|
expect( result ).toEqual( { length: 5 } )
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should create an OrderedMap from an array", () => {
|
||||||
|
const param = [1, 1, 2, 3, 5, 8]
|
||||||
|
|
||||||
|
const result = fromJSOrdered(param).toJS()
|
||||||
|
expect( result ).toEqual( [1, 1, 2, 3, 5, 8] )
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user