From 2c35ba2c8f0dd4ce373a70b2b692b45f83abcb47 Mon Sep 17 00:00:00 2001 From: Owen Conti Date: Tue, 18 Jul 2017 19:58:02 -0600 Subject: [PATCH 1/2] Fixes #3405 - Changed logic for schemes.jsx component to select default scheme when there is no selected scheme. Added test for functionality. --- src/core/components/schemes.jsx | 5 ++-- test/components/schemes.js | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/components/schemes.js diff --git a/src/core/components/schemes.jsx b/src/core/components/schemes.jsx index 8be4180a..f9fe8f81 100644 --- a/src/core/components/schemes.jsx +++ b/src/core/components/schemes.jsx @@ -19,8 +19,9 @@ export default class Schemes extends React.Component { } componentWillReceiveProps(nextProps) { - if ( this.props.operationScheme && !nextProps.schemes.has(this.props.operationScheme) ) { - //fire 'change' event if our selected scheme is no longer an option + if ( !this.props.operationScheme || !nextProps.schemes.has(this.props.operationScheme) ) { + // 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()) } } diff --git a/test/components/schemes.js b/test/components/schemes.js new file mode 100644 index 00000000..a21c0628 --- /dev/null +++ b/test/components/schemes.js @@ -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("", 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() + + // 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") + }) +}) From 25c63b5f76128d177d59f932da0befe875d96598 Mon Sep 17 00:00:00 2001 From: Leon Weidauer Date: Thu, 20 Jul 2017 12:01:00 +0200 Subject: [PATCH 2/2] Fix length issue in OrderedMaps Previously, a definiton with a 'length' property with numeric value would result in an OrderedMap of that length. This is now fixed and covered by tests --- src/core/utils.js | 2 +- test/core/utils.js | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index 95771fb4..f2e28948 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -41,7 +41,7 @@ export function fromJSOrdered (js) { return !isObject(js) ? js : Array.isArray(js) ? Im.Seq(js).map(fromJSOrdered).toList() : - Im.Seq(js).map(fromJSOrdered).toOrderedMap() + Im.OrderedMap(js).map(fromJSOrdered) } export function bindToState(obj, state) { diff --git a/test/core/utils.js b/test/core/utils.js index a63da13d..fbfb24ab 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -1,10 +1,10 @@ /* eslint-env mocha */ import expect from "expect" 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" -describe("utils", function(){ +describe("utils", function() { describe("mapToList", function(){ @@ -306,4 +306,31 @@ describe("utils", function(){ expect( result ).toEqual( [{index: 0, error: "Value must be an integer"}, {index: 1, error: "Value must be an integer"}] ) }) }) + + 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] ) + }) + }) })