fix(try-it-out): stringify numerical initial values in ParameterRow (#4767)

* add failing tests
* coerce initial values to string
* only convert numbers to strings when setting parameter values
This commit is contained in:
kyle
2018-07-27 01:17:36 -07:00
committed by GitHub
parent 8cde08bd83
commit 955352251b
4 changed files with 105 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ import { Map } from "immutable"
import PropTypes from "prop-types"
import ImPropTypes from "react-immutable-proptypes"
import win from "core/window"
import { getExtensions, getCommonExtensions } from "core/utils"
import { getExtensions, getCommonExtensions, numberToString } from "core/utils"
export default class ParameterRow extends Component {
static propTypes = {
@@ -53,7 +53,7 @@ export default class ParameterRow extends Component {
}
if ( value !== undefined && value !== paramValue ) {
this.onChangeWrapper(value)
this.onChangeWrapper(numberToString(value))
}
this.setDefaultValue()
@@ -88,7 +88,7 @@ export default class ParameterRow extends Component {
|| paramWithMeta.getIn(["schema", "default"])
}
if(newValue !== undefined) {
this.onChangeWrapper(newValue)
this.onChangeWrapper(numberToString(newValue))
}
}
}

View File

@@ -780,4 +780,12 @@ export function stringify(thing) {
}
return thing.toString()
}
export function numberToString(thing) {
if(typeof thing === "number") {
return thing.toString()
}
return thing
}

View File

@@ -0,0 +1,43 @@
describe("bug #4756: enum initial values", function () {
let mainPage
beforeEach(function (client, done) {
mainPage = client
.url("localhost:3230")
.page.main()
client.waitForElementVisible(".download-url-input:not([disabled])", 5000)
.pause(2000)
.clearValue(".download-url-input")
.setValue(".download-url-input", "http://localhost:3230/test-specs/bugs/4756.yaml")
.click("button.download-url-button")
.pause(1000)
done()
})
afterEach(function (client, done) {
done()
})
it("sets a required initial value based the first enum value", function (client) {
client.waitForElementVisible(".opblock-tag-section", 10000)
.click("#operations-default-post_zero")
.waitForElementVisible(".opblock.is-open", 5000)
.click("button.btn.try-out__btn")
.click("button.btn.execute")
.waitForElementVisible(".request-url", 2000)
.assert.containsText(".request-url > pre", "http://www.example.com/test/API/zero?one=0")
client.end()
})
it("sets a required initial value based on a default value", function (client) {
client.waitForElementVisible(".opblock-tag-section", 10000)
.click("#operations-default-post_one")
.waitForElementVisible(".opblock.is-open", 5000)
.click("button.btn.try-out__btn")
.click("button.btn.execute")
.waitForElementVisible(".request-url", 2000)
.assert.containsText(".request-url > pre", "http://www.example.com/test/API/one?one=1")
client.end()
})
})

View File

@@ -0,0 +1,51 @@
swagger: '2.0'
info:
title: test doc
description: 'test doc '
license:
name: Copyright @2018
version: 1.0.0
host: www.example.com
basePath: /test/API
tags:
- name: devices
description: devices
schemes:
- http
- https
consumes:
- application/x-www-form-urlencoded
produces:
- application/json
paths:
/zero:
post:
parameters:
- in: query
name: one
type: string
required: true
enum:
- 0
- 1
responses:
200:
description: 'response'
examples:
application/json: {"error":0}
/one:
post:
parameters:
- in: query
name: one
type: string
required: true
default: 1
enum:
- 0
- 1
responses:
200:
description: 'response'
examples:
application/json: {"error":0}