@@ -1153,6 +1153,61 @@ test.describe('Actions', () => {
1153
1153
await expect ( page . locator ( 'pre.formdata2' ) ) . toHaveText ( JSON . stringify ( { message : 'hello' } ) ) ;
1154
1154
} ) ;
1155
1155
1156
+ test ( 'use:enhance with `enctype="application/x-www-form-urlencoded"` attribute in `<form>`' , async ( {
1157
+ page
1158
+ } ) => {
1159
+ await page . goto ( '/actions/enhance' ) ;
1160
+
1161
+ expect ( await page . textContent ( 'pre.formdata1' ) ) . toBe ( JSON . stringify ( null ) ) ;
1162
+ expect ( await page . textContent ( 'pre.formdata2' ) ) . toBe ( JSON . stringify ( null ) ) ;
1163
+
1164
+ await page . locator ( 'input[name="username_2"]' ) . fill ( 'foo' ) ;
1165
+ await page . locator ( 'button.form-enctype-submit' ) . click ( ) ;
1166
+
1167
+ await expect ( page . locator ( 'pre.formdata1' ) ) . toHaveText ( JSON . stringify ( { result : 'foo' } ) ) ;
1168
+ await expect ( page . locator ( 'pre.formdata2' ) ) . toHaveText ( JSON . stringify ( { result : 'foo' } ) ) ;
1169
+ await expect ( page . locator ( 'input[name="username_2"]' ) ) . toHaveValue ( '' ) ;
1170
+ } ) ;
1171
+
1172
+ test ( 'use:enhance with `enctype="multipart/form"` attribute in `<form>`' , async ( { page } ) => {
1173
+ await page . goto ( '/actions/enhance' ) ;
1174
+
1175
+ expect ( await page . textContent ( 'pre.formdata1' ) ) . toBe ( JSON . stringify ( null ) ) ;
1176
+ expect ( await page . textContent ( 'pre.formdata2' ) ) . toBe ( JSON . stringify ( null ) ) ;
1177
+
1178
+ const fileInput = page . locator ( 'input[type="file"].form-file-input' ) ;
1179
+
1180
+ await fileInput . setInputFiles ( {
1181
+ name : 'test-file.txt' ,
1182
+ mimeType : 'text/plain' ,
1183
+ buffer : Buffer . from ( 'this is test' )
1184
+ } ) ;
1185
+
1186
+ await page . locator ( 'button.form-file-submit' ) . click ( ) ;
1187
+
1188
+ await expect ( page . locator ( 'pre.formdata1' ) ) . toHaveText (
1189
+ JSON . stringify ( { result : 'file name:test-file.txt' } )
1190
+ ) ;
1191
+ await expect ( page . locator ( 'pre.formdata2' ) ) . toHaveText (
1192
+ JSON . stringify ( { result : 'file name:test-file.txt' } )
1193
+ ) ;
1194
+ await expect ( page . locator ( 'input[name=username]' ) ) . toHaveValue ( '' ) ;
1195
+ } ) ;
1196
+
1197
+ test ( 'use:enhance with defined `enctype` attribute for `<form>` element' , async ( { page } ) => {
1198
+ await page . goto ( '/actions/enhance' ) ;
1199
+
1200
+ expect ( await page . textContent ( 'pre.formdata1' ) ) . toBe ( JSON . stringify ( null ) ) ;
1201
+ expect ( await page . textContent ( 'pre.formdata2' ) ) . toBe ( JSON . stringify ( null ) ) ;
1202
+
1203
+ await page . locator ( 'input[name="username_2"]' ) . fill ( 'foo' ) ;
1204
+ await page . locator ( 'button.form-enctype-submit' ) . click ( ) ;
1205
+
1206
+ await expect ( page . locator ( 'pre.formdata1' ) ) . toHaveText ( JSON . stringify ( { result : 'foo' } ) ) ;
1207
+ await expect ( page . locator ( 'pre.formdata2' ) ) . toHaveText ( JSON . stringify ( { result : 'foo' } ) ) ;
1208
+ await expect ( page . locator ( 'input[name="username_2"]' ) ) . toHaveValue ( '' ) ;
1209
+ } ) ;
1210
+
1156
1211
test ( 'redirect' , async ( { page, javaScriptEnabled } ) => {
1157
1212
await page . goto ( '/actions/redirect' ) ;
1158
1213
0 commit comments