4
4
5
5
describe ( "OpenAPI 3.0 Validation for Required Request Body and Request Body Fields" , ( ) => {
6
6
describe ( "Request Body required bug/5181" , ( ) => {
7
- it ( "on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component" , ( ) => {
8
- cy . visit (
9
- "/?url=/documents/bugs/5181.yaml"
7
+ beforeEach ( ( ) => {
8
+ cy . intercept (
9
+ {
10
+ method : "POST" ,
11
+ url : "/anything/foos" ,
12
+ hostname : "httpbin.org" ,
13
+ } ,
14
+ { }
10
15
)
16
+ } )
17
+
18
+ it ( "on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component" , ( ) => {
19
+ cy . visit ( "/?url=/documents/bugs/5181.yaml" )
11
20
. get ( "#operations-default-post_foos" )
12
21
. click ( )
13
22
// Expand Try It Out
14
23
. get ( ".try-out__btn" )
15
24
. click ( )
16
25
// get input
17
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input" )
26
+ . get (
27
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input"
28
+ )
18
29
. should ( "not.have.class" , "invalid" )
19
30
// Execute
20
31
. get ( ".execute.opblock-control__btn" )
21
32
. click ( )
22
33
// class "invalid" should now exist (and render red, which we won't check)
23
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input" )
34
+ . get (
35
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input"
36
+ )
24
37
. should ( "have.class" , "invalid" )
25
38
// cURL component should not exist
26
39
. get ( ".responses-wrapper .curl-command" )
27
40
. should ( "not.exist" )
28
41
} )
29
42
it ( "on execute, if value exists, should NOT render class 'invalid' and SHOULD render cURL component" , ( ) => {
30
- cy . visit (
31
- "/?url=/documents/bugs/5181.yaml"
32
- )
43
+ cy . visit ( "/?url=/documents/bugs/5181.yaml" )
33
44
. get ( "#operations-default-post_foos" )
34
45
. click ( )
35
46
// Expand Try It Out
36
47
. get ( ".try-out__btn" )
37
48
. click ( )
38
49
// get input
39
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input" )
50
+ . get (
51
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input"
52
+ )
40
53
. type ( "abc" )
41
54
// Execute
42
55
. get ( ".execute.opblock-control__btn" )
43
56
. click ( )
44
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input" )
57
+ . get (
58
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input"
59
+ )
45
60
. should ( "not.have.class" , "invalid" )
46
61
// cURL component should exist
47
62
. get ( ".responses-wrapper .curl-command" )
@@ -51,45 +66,49 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
51
66
52
67
describe ( "Request Body required fields - application/json" , ( ) => {
53
68
it ( "on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component" , ( ) => {
54
- cy . visit (
55
- "/?url=/documents/features/petstore-only-pet.openapi.yaml"
56
- )
69
+ cy . visit ( "/?url=/documents/features/petstore-only-pet.openapi.yaml" )
57
70
. get ( "#operations-pet-addPet" )
58
71
. click ( )
59
72
// Expand Try It Out
60
73
. get ( ".try-out__btn" )
61
74
. click ( )
62
75
// get and clear textarea
63
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea" )
76
+ . get (
77
+ ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
78
+ )
64
79
. should ( "not.have.class" , "invalid" )
65
80
. clear ( )
66
81
// Execute
67
82
. get ( ".execute.opblock-control__btn" )
68
83
. click ( )
69
84
// class "invalid" should now exist (and render red, which we won't check)
70
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea" )
85
+ . get (
86
+ ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
87
+ )
71
88
. should ( "have.class" , "invalid" )
72
89
// cURL component should not exist
73
90
. get ( ".responses-wrapper .curl-command" )
74
91
. should ( "not.exist" )
75
92
} )
76
93
it ( "on execute, if value exists, even if just single space, should NOT render class 'invalid' and SHOULD render cURL component that contains the single space" , ( ) => {
77
- cy . visit (
78
- "/?url=/documents/features/petstore-only-pet.openapi.yaml"
79
- )
94
+ cy . visit ( "/?url=/documents/features/petstore-only-pet.openapi.yaml" )
80
95
. get ( "#operations-pet-addPet" )
81
96
. click ( )
82
97
// Expand Try It Out
83
98
. get ( ".try-out__btn" )
84
99
. click ( )
85
100
// get, clear, then modify textarea
86
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea" )
101
+ . get (
102
+ ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
103
+ )
87
104
. clear ( )
88
105
. type ( " " )
89
106
// Execute
90
107
. get ( ".execute.opblock-control__btn" )
91
108
. click ( )
92
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea" )
109
+ . get (
110
+ ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
111
+ )
93
112
. should ( "not.have.class" , "invalid" )
94
113
// cURL component should exist
95
114
. get ( ".responses-wrapper .curl-command" )
@@ -99,57 +118,67 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
99
118
} )
100
119
} )
101
120
102
- /*
103
- petstore ux notes:
121
+ /*
122
+ petstore ux notes:
104
123
- required field, but if example value exists, will populate the field. So this test will clear the example value.
105
124
- "add item" will insert an empty array, and display an input text box. This establishes a value for the field.
106
125
*/
107
126
describe ( "Request Body required fields - application/x-www-form-urlencoded" , ( ) => {
108
127
it ( "on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component" , ( ) => {
109
- cy . visit (
110
- "/?url=/documents/features/petstore-only-pet.openapi.yaml"
111
- )
128
+ cy . visit ( "/?url=/documents/features/petstore-only-pet.openapi.yaml" )
112
129
. get ( "#operations-pet-addPet" )
113
130
. click ( )
114
- . get ( ".opblock-section .opblock-section-request-body .body-param-content-type > select" )
131
+ . get (
132
+ ".opblock-section .opblock-section-request-body .body-param-content-type > select"
133
+ )
115
134
. select ( "application/x-www-form-urlencoded" )
116
135
// Expand Try It Out
117
136
. get ( ".try-out__btn" )
118
137
. click ( )
119
138
// get and clear input populated from example value
120
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input" )
139
+ . get (
140
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
141
+ )
121
142
. clear ( )
122
143
// Execute
123
144
. get ( ".execute.opblock-control__btn" )
124
145
. click ( )
125
146
// class "invalid" should now exist (and render red, which we won't check)
126
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input" )
147
+ . get (
148
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
149
+ )
127
150
. should ( "have.class" , "invalid" )
128
151
// cURL component should not exist
129
152
. get ( ".responses-wrapper .curl-command" )
130
153
. should ( "not.exist" )
131
154
} )
132
155
it ( "on execute, if all values exist, even if array exists but is empty, should NOT render class 'invalid' and SHOULD render cURL component" , ( ) => {
133
- cy . visit (
134
- "/?url=/documents/features/petstore-only-pet.openapi.yaml"
135
- )
156
+ cy . visit ( "/?url=/documents/features/petstore-only-pet.openapi.yaml" )
136
157
. get ( "#operations-pet-addPet" )
137
158
. click ( )
138
- . get ( ".opblock-section .opblock-section-request-body .body-param-content-type > select" )
159
+ . get (
160
+ ".opblock-section .opblock-section-request-body .body-param-content-type > select"
161
+ )
139
162
. select ( "application/x-www-form-urlencoded" )
140
163
// Expand Try It Out
141
164
. get ( ".try-out__btn" )
142
165
. click ( )
143
166
// add item to get input
144
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button" )
167
+ . get (
168
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button"
169
+ )
145
170
. click ( )
146
171
// Execute
147
172
. get ( ".execute.opblock-control__btn" )
148
173
. click ( )
149
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input" )
174
+ . get (
175
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
176
+ )
150
177
. should ( "have.value" , "doggie" )
151
178
. should ( "not.have.class" , "invalid" )
152
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input" )
179
+ . get (
180
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input"
181
+ )
153
182
. should ( "have.value" , "string" )
154
183
. should ( "not.have.class" , "invalid" )
155
184
// cURL component should exist
@@ -160,58 +189,76 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
160
189
161
190
describe ( "Request Body: switching between Content Types" , ( ) => {
162
191
it ( "after application/json 'invalid' error, on switch content type to application/x-www-form-urlencoded, SHOULD be free of errors" , ( ) => {
163
- cy . visit (
164
- "/?url=/documents/features/petstore-only-pet.openapi.yaml"
165
- )
192
+ cy . visit ( "/?url=/documents/features/petstore-only-pet.openapi.yaml" )
166
193
. get ( "#operations-pet-addPet" )
167
194
. click ( )
168
195
// Expand Try It Out
169
196
. get ( ".try-out__btn" )
170
197
. click ( )
171
198
// get and clear textarea
172
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea" )
199
+ . get (
200
+ ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
201
+ )
173
202
. should ( "not.have.class" , "invalid" )
174
203
. clear ( )
175
204
// Execute
176
205
. get ( ".execute.opblock-control__btn" )
177
206
. click ( )
178
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea" )
207
+ . get (
208
+ ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
209
+ )
179
210
. should ( "have.class" , "invalid" )
180
211
// switch content type
181
- . get ( ".opblock-section .opblock-section-request-body .body-param-content-type > select" )
212
+ . get (
213
+ ".opblock-section .opblock-section-request-body .body-param-content-type > select"
214
+ )
182
215
. select ( "application/x-www-form-urlencoded" )
183
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input" )
216
+ . get (
217
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
218
+ )
184
219
. should ( "not.have.class" , "invalid" )
185
220
// add item to get input, just an extra confirmation of non-invalid class
186
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button" )
221
+ . get (
222
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button"
223
+ )
187
224
. click ( )
188
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input" )
225
+ . get (
226
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input"
227
+ )
189
228
. should ( "not.have.class" , "invalid" )
190
229
} )
191
230
it ( "after application/x-www-form-urlencoded 'invalid' error, on switch content type to application/json, SHOULD be free of errors" , ( ) => {
192
- cy . visit (
193
- "/?url=/documents/features/petstore-only-pet.openapi.yaml"
194
- )
231
+ cy . visit ( "/?url=/documents/features/petstore-only-pet.openapi.yaml" )
195
232
. get ( "#operations-pet-addPet" )
196
233
. click ( )
197
- . get ( ".opblock-section .opblock-section-request-body .body-param-content-type > select" )
234
+ . get (
235
+ ".opblock-section .opblock-section-request-body .body-param-content-type > select"
236
+ )
198
237
. select ( "application/x-www-form-urlencoded" )
199
238
// Expand Try It Out
200
239
. get ( ".try-out__btn" )
201
240
. click ( )
202
241
// get and clear input
203
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input" )
242
+ . get (
243
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
244
+ )
204
245
. clear ( )
205
246
// Execute
206
247
. get ( ".execute.opblock-control__btn" )
207
248
. click ( )
208
249
// class "invalid" should now exist (and render red, which we won't check)
209
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input" )
250
+ . get (
251
+ ".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input"
252
+ )
210
253
. should ( "have.class" , "invalid" )
211
254
// switch content type
212
- . get ( ".opblock-section .opblock-section-request-body .body-param-content-type > select" )
255
+ . get (
256
+ ".opblock-section .opblock-section-request-body .body-param-content-type > select"
257
+ )
213
258
. select ( "application/json" )
214
- . get ( ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea" )
259
+ . get (
260
+ ".opblock-body .opblock-section .opblock-section-request-body .body-param textarea"
261
+ )
215
262
. should ( "not.have.class" , "invalid" )
216
263
} )
217
264
} )
0 commit comments