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:
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -780,4 +780,12 @@ export function stringify(thing) {
|
||||
}
|
||||
|
||||
return thing.toString()
|
||||
}
|
||||
|
||||
export function numberToString(thing) {
|
||||
if(typeof thing === "number") {
|
||||
return thing.toString()
|
||||
}
|
||||
|
||||
return thing
|
||||
}
|
||||
43
test/e2e/scenarios/bugs/4756.js
Normal file
43
test/e2e/scenarios/bugs/4756.js
Normal 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()
|
||||
})
|
||||
})
|
||||
51
test/e2e/specs/bugs/4756.yaml
Normal file
51
test/e2e/specs/bugs/4756.yaml
Normal 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}
|
||||
Reference in New Issue
Block a user