Skip to content

Commit 9553522

Browse files
authored
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
1 parent 8cde08b commit 9553522

File tree

4 files changed

+105
-3
lines changed

4 files changed

+105
-3
lines changed

src/core/components/parameter-row.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Map } from "immutable"
33
import PropTypes from "prop-types"
44
import ImPropTypes from "react-immutable-proptypes"
55
import win from "core/window"
6-
import { getExtensions, getCommonExtensions } from "core/utils"
6+
import { getExtensions, getCommonExtensions, numberToString } from "core/utils"
77

88
export default class ParameterRow extends Component {
99
static propTypes = {
@@ -53,7 +53,7 @@ export default class ParameterRow extends Component {
5353
}
5454

5555
if ( value !== undefined && value !== paramValue ) {
56-
this.onChangeWrapper(value)
56+
this.onChangeWrapper(numberToString(value))
5757
}
5858

5959
this.setDefaultValue()
@@ -88,7 +88,7 @@ export default class ParameterRow extends Component {
8888
|| paramWithMeta.getIn(["schema", "default"])
8989
}
9090
if(newValue !== undefined) {
91-
this.onChangeWrapper(newValue)
91+
this.onChangeWrapper(numberToString(newValue))
9292
}
9393
}
9494
}

src/core/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,4 +780,12 @@ export function stringify(thing) {
780780
}
781781

782782
return thing.toString()
783+
}
784+
785+
export function numberToString(thing) {
786+
if(typeof thing === "number") {
787+
return thing.toString()
788+
}
789+
790+
return thing
783791
}

test/e2e/scenarios/bugs/4756.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
describe("bug #4756: enum initial values", function () {
2+
let mainPage
3+
beforeEach(function (client, done) {
4+
mainPage = client
5+
.url("localhost:3230")
6+
.page.main()
7+
8+
client.waitForElementVisible(".download-url-input:not([disabled])", 5000)
9+
.pause(2000)
10+
.clearValue(".download-url-input")
11+
.setValue(".download-url-input", "http://localhost:3230/test-specs/bugs/4756.yaml")
12+
.click("button.download-url-button")
13+
.pause(1000)
14+
15+
done()
16+
})
17+
18+
afterEach(function (client, done) {
19+
done()
20+
})
21+
22+
it("sets a required initial value based the first enum value", function (client) {
23+
client.waitForElementVisible(".opblock-tag-section", 10000)
24+
.click("#operations-default-post_zero")
25+
.waitForElementVisible(".opblock.is-open", 5000)
26+
.click("button.btn.try-out__btn")
27+
.click("button.btn.execute")
28+
.waitForElementVisible(".request-url", 2000)
29+
.assert.containsText(".request-url > pre", "http://www.example.com/test/API/zero?one=0")
30+
client.end()
31+
})
32+
33+
it("sets a required initial value based on a default value", function (client) {
34+
client.waitForElementVisible(".opblock-tag-section", 10000)
35+
.click("#operations-default-post_one")
36+
.waitForElementVisible(".opblock.is-open", 5000)
37+
.click("button.btn.try-out__btn")
38+
.click("button.btn.execute")
39+
.waitForElementVisible(".request-url", 2000)
40+
.assert.containsText(".request-url > pre", "http://www.example.com/test/API/one?one=1")
41+
client.end()
42+
})
43+
})

test/e2e/specs/bugs/4756.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
swagger: '2.0'
2+
info:
3+
title: test doc
4+
description: 'test doc '
5+
license:
6+
name: Copyright @2018
7+
version: 1.0.0
8+
host: www.example.com
9+
basePath: /test/API
10+
tags:
11+
- name: devices
12+
description: devices
13+
schemes:
14+
- http
15+
- https
16+
consumes:
17+
- application/x-www-form-urlencoded
18+
produces:
19+
- application/json
20+
paths:
21+
/zero:
22+
post:
23+
parameters:
24+
- in: query
25+
name: one
26+
type: string
27+
required: true
28+
enum:
29+
- 0
30+
- 1
31+
responses:
32+
200:
33+
description: 'response'
34+
examples:
35+
application/json: {"error":0}
36+
/one:
37+
post:
38+
parameters:
39+
- in: query
40+
name: one
41+
type: string
42+
required: true
43+
default: 1
44+
enum:
45+
- 0
46+
- 1
47+
responses:
48+
200:
49+
description: 'response'
50+
examples:
51+
application/json: {"error":0}

0 commit comments

Comments
 (0)