Skip to content

Commit b042072

Browse files
authored
Merge pull request #3825 from heldersepu/feature/validation_tooltips
Add validation error tooltips
2 parents 0432828 + b2c41e1 commit b042072

File tree

3 files changed

+86
-12
lines changed

3 files changed

+86
-12
lines changed

src/core/json-schema-components.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class JsonSchema_string extends Component {
5858
if ( enumValue ) {
5959
const Select = getComponent("Select")
6060
return (<Select className={ errors.length ? "invalid" : ""}
61+
title={ errors.length ? errors : ""}
6162
allowedValues={ enumValue }
6263
value={ value }
6364
allowEmptyValue={ !required }
@@ -67,10 +68,20 @@ export class JsonSchema_string extends Component {
6768
const isDisabled = schema["in"] === "formData" && !("FormData" in window)
6869
const Input = getComponent("Input")
6970
if (schema["type"] === "file") {
70-
return <Input type="file" className={ errors.length ? "invalid" : ""} onChange={ this.onChange } disabled={isDisabled}/>
71+
return (<Input type="file"
72+
className={ errors.length ? "invalid" : ""}
73+
title={ errors.length ? errors : ""}
74+
onChange={ this.onChange }
75+
disabled={isDisabled}/>)
7176
}
7277
else {
73-
return <Input type={ schema.format === "password" ? "password" : "text" } className={ errors.length ? "invalid" : ""} value={value} placeholder={description} onChange={ this.onChange } disabled={isDisabled}/>
78+
return (<Input type={ schema.format === "password" ? "password" : "text" }
79+
className={ errors.length ? "invalid" : ""}
80+
title={ errors.length ? errors : ""}
81+
value={value}
82+
placeholder={description}
83+
onChange={ this.onChange }
84+
disabled={isDisabled}/>)
7485
}
7586
}
7687
}
@@ -134,11 +145,12 @@ export class JsonSchema_array extends PureComponent {
134145
if ( enumValue ) {
135146
const Select = getComponent("Select")
136147
return (<Select className={ errors.length ? "invalid" : ""}
137-
multiple={ true }
138-
value={ value }
139-
allowedValues={ enumValue }
140-
allowEmptyValue={ !required }
141-
onChange={ this.onEnumChange }/>)
148+
title={ errors.length ? errors : ""}
149+
multiple={ true }
150+
value={ value }
151+
allowedValues={ enumValue }
152+
allowEmptyValue={ !required }
153+
onChange={ this.onEnumChange }/>)
142154
}
143155

144156
return (
@@ -175,6 +187,7 @@ export class JsonSchema_boolean extends Component {
175187
const Select = getComponent("Select")
176188

177189
return (<Select className={ errors.length ? "invalid" : ""}
190+
title={ errors.length ? errors : ""}
178191
value={ String(value) }
179192
allowedValues={ fromJS(["true", "false"]) }
180193
allowEmptyValue={ true }

test/e2e/pages/main.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ module.exports = {
9393
petAPIWrapperBar: {
9494
selector: ".swagger-ui .opblock-tag-section:nth-child(1) .opblock-tag"
9595
},
96+
9697
/**
9798
* Post pet/ api
9899
*/
@@ -141,6 +142,7 @@ module.exports = {
141142
petOperationPostStatus: {
142143
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-addPet pre.microlight span:nth-child(70)"
143144
},
145+
144146
/**
145147
* Put pet/ api
146148
*/
@@ -189,8 +191,9 @@ module.exports = {
189191
petOperationPutStatus: {
190192
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-updatePet pre.microlight span:nth-child(70)"
191193
},
194+
192195
/**
193-
* Get pet/
196+
* Get /pet/findByTags
194197
*/
195198
petOperationGetByTagContainer: {
196199
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-findPetsByTags"
@@ -237,6 +240,34 @@ module.exports = {
237240
petOperationGetByTagStatus: {
238241
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-findPetsByTags pre.microlight span:nth-child(70)"
239242
},
243+
244+
/**
245+
* Get /pet/{petId}
246+
*/
247+
petOperationGetByIdContainer: {
248+
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-getPetById"
249+
},
250+
petOperationGetByIdTitle: {
251+
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-getPetById .opblock-summary-get span.opblock-summary-path span"
252+
},
253+
petOperationGetByIdCollpase: {
254+
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-getPetById .opblock-summary-get"
255+
},
256+
petOperationGetByIdCollapseContainer: {
257+
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-getPetById .ReactCollapse--collapse"
258+
},
259+
petOperationGetByIdTryBtn: {
260+
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-getPetById button.try-out__btn"
261+
},
262+
petOperationGetByIdExecuteBtn: {
263+
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-getPetById button.execute"
264+
},
265+
petOperationGetByIdParameter: {
266+
selector: ".swagger-ui .opblock-tag-section:nth-child(3) div#operations-pet-getPetById div.parameters-col_description input"
267+
},
268+
petOperationGetByIdResultsBox: {
269+
selector: ".swagger-ui .opblock-tag-section:nth-child(1) div#operations-pet-getPetById pre.microlight"
270+
},
240271

241272
/**
242273
* Delete pet/
@@ -497,9 +528,5 @@ module.exports = {
497528
},
498529
}
499530
}
500-
501-
502-
503-
504531
}
505532
}

test/e2e/scenarios/operations/pet.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ describe("render pet api container", function () {
8484

8585
client.end()
8686
})
87+
8788
it("Testing put /pet api Mock data", function (client) {
8889
apiWrapper.waitForElementVisible("@petOperationPutContainer", 5000)
8990
.click("@petOperationPutCollpase")
@@ -137,6 +138,38 @@ describe("render pet api container", function () {
137138

138139
client.end()
139140
})
141+
142+
it("render get by ID /pet/{petId} api container", function (client) {
143+
apiWrapper.waitForElementVisible("@petOperationGetByIdContainer", 5000)
144+
.assert.containsText("@petOperationGetByIdTitle", "/pet/{petId}")
145+
.click("@petOperationGetByIdCollpase")
146+
.waitForElementVisible("@petOperationGetByIdCollapseContainer", 3000)
147+
.click("@petOperationGetByIdTryBtn")
148+
.waitForElementVisible("@petOperationGetByTagExecuteBtn", 1000)
149+
.click("@petOperationGetByTagTryBtn")
150+
.assert.cssClassNotPresent("@petOperationGetByTagTryBtn", "cancel")
151+
152+
client.end()
153+
})
154+
155+
it("render get by ID /pet/{petId} api Mock data", function (client) {
156+
apiWrapper.waitForElementVisible("@petOperationGetByIdContainer", 5000)
157+
.assert.containsText("@petOperationGetByIdTitle", "/pet/{petId}")
158+
.click("@petOperationGetByIdCollpase")
159+
.waitForElementVisible("@petOperationGetByIdCollapseContainer", 3000)
160+
.click("@petOperationGetByIdTryBtn")
161+
.waitForElementVisible("@petOperationGetByTagExecuteBtn", 1000)
162+
.setValue("@petOperationGetByIdParameter", "abc")
163+
.click("@petOperationGetByIdExecuteBtn")
164+
.waitForElementVisible("@petOperationGetByIdResultsBox")
165+
.assert.containsText("@petOperationGetByIdParameter", "abc")
166+
.assert.cssClassPresent("@petOperationGetByIdParameter", "invalid")
167+
.assert.attributeEquals("@petOperationGetByIdParameter", "title", "Value must be an integer")
168+
.click("@petOperationGetByTagTryBtn")
169+
.assert.cssClassNotPresent("@petOperationGetByTagTryBtn", "cancel")
170+
171+
client.end()
172+
})
140173

141174
it("render delete /pet api container", function (client) {
142175
apiWrapper.waitForElementVisible("@petOperationDeleteContainer")
@@ -150,6 +183,7 @@ describe("render pet api container", function () {
150183

151184
client.end()
152185
})
186+
153187
it("Testing delete /pet api Mock data", function (client) {
154188
apiWrapper.waitForElementVisible("@petOperationDeleteContainer", 3000)
155189
.click("@petOperationDeleteCollpase")

0 commit comments

Comments
 (0)