@@ -1176,6 +1176,185 @@ describe("Scripting", function () {
1176
1176
} ) ;
1177
1177
} ) ;
1178
1178
1179
+ describe ( "AFSpecial_Keystroke" , function ( ) {
1180
+ it ( "should validate a zip code on a keystroke event" , async ( ) => {
1181
+ const refId = getId ( ) ;
1182
+ const data = {
1183
+ objects : {
1184
+ field : [
1185
+ {
1186
+ id : refId ,
1187
+ value : "" ,
1188
+ actions : {
1189
+ Keystroke : [ `AFSpecial_Keystroke(0);` ] ,
1190
+ } ,
1191
+ type : "text" ,
1192
+ } ,
1193
+ ] ,
1194
+ } ,
1195
+ appInfo : { language : "en-US" , platform : "Linux x86_64" } ,
1196
+ calculationOrder : [ ] ,
1197
+ dispatchEventName : "_dispatchMe" ,
1198
+ } ;
1199
+ sandbox . createSandbox ( data ) ;
1200
+
1201
+ let value = "" ;
1202
+ const changes = "12345" ;
1203
+ let i = 0 ;
1204
+
1205
+ for ( ; i < changes . length ; i ++ ) {
1206
+ const change = changes . charAt ( i ) ;
1207
+ await sandbox . dispatchEventInSandbox ( {
1208
+ id : refId ,
1209
+ value,
1210
+ change,
1211
+ name : "Keystroke" ,
1212
+ willCommit : false ,
1213
+ selStart : i ,
1214
+ selEnd : i ,
1215
+ } ) ;
1216
+ expect ( send_queue . has ( refId ) ) . toEqual ( false ) ;
1217
+ value += change ;
1218
+ }
1219
+
1220
+ await sandbox . dispatchEventInSandbox ( {
1221
+ id : refId ,
1222
+ value,
1223
+ change : "A" ,
1224
+ name : "Keystroke" ,
1225
+ willCommit : false ,
1226
+ selStart : i ,
1227
+ selEnd : i ,
1228
+ } ) ;
1229
+ expect ( send_queue . has ( refId ) ) . toEqual ( true ) ;
1230
+ expect ( send_queue . get ( refId ) ) . toEqual ( {
1231
+ id : refId ,
1232
+ value,
1233
+ selRange : [ i , i ] ,
1234
+ } ) ;
1235
+
1236
+ send_queue . delete ( refId ) ;
1237
+ } ) ;
1238
+
1239
+ it ( "should validate a US phone number (long) on a keystroke event" , async ( ) => {
1240
+ const refId = getId ( ) ;
1241
+ const data = {
1242
+ objects : {
1243
+ field : [
1244
+ {
1245
+ id : refId ,
1246
+ value : "" ,
1247
+ actions : {
1248
+ Keystroke : [ `AFSpecial_Keystroke(2);` ] ,
1249
+ } ,
1250
+ type : "text" ,
1251
+ } ,
1252
+ ] ,
1253
+ } ,
1254
+ appInfo : { language : "en-US" , platform : "Linux x86_64" } ,
1255
+ calculationOrder : [ ] ,
1256
+ dispatchEventName : "_dispatchMe" ,
1257
+ } ;
1258
+ sandbox . createSandbox ( data ) ;
1259
+
1260
+ let value = "" ;
1261
+ const changes = "(123) 456-7890" ;
1262
+ let i = 0 ;
1263
+
1264
+ for ( ; i < changes . length ; i ++ ) {
1265
+ const change = changes . charAt ( i ) ;
1266
+ await sandbox . dispatchEventInSandbox ( {
1267
+ id : refId ,
1268
+ value,
1269
+ change,
1270
+ name : "Keystroke" ,
1271
+ willCommit : false ,
1272
+ selStart : i ,
1273
+ selEnd : i ,
1274
+ } ) ;
1275
+ expect ( send_queue . has ( refId ) ) . toEqual ( false ) ;
1276
+ value += change ;
1277
+ }
1278
+
1279
+ await sandbox . dispatchEventInSandbox ( {
1280
+ id : refId ,
1281
+ value,
1282
+ change : "A" ,
1283
+ name : "Keystroke" ,
1284
+ willCommit : false ,
1285
+ selStart : i ,
1286
+ selEnd : i ,
1287
+ } ) ;
1288
+ expect ( send_queue . has ( refId ) ) . toEqual ( true ) ;
1289
+ expect ( send_queue . get ( refId ) ) . toEqual ( {
1290
+ id : refId ,
1291
+ value,
1292
+ selRange : [ i , i ] ,
1293
+ } ) ;
1294
+
1295
+ send_queue . delete ( refId ) ;
1296
+ } ) ;
1297
+
1298
+ it ( "should validate a US phone number (short) on a keystroke event" , async ( ) => {
1299
+ const refId = getId ( ) ;
1300
+ const data = {
1301
+ objects : {
1302
+ field : [
1303
+ {
1304
+ id : refId ,
1305
+ value : "" ,
1306
+ actions : {
1307
+ Keystroke : [ `AFSpecial_Keystroke(2);` ] ,
1308
+ } ,
1309
+ type : "text" ,
1310
+ } ,
1311
+ ] ,
1312
+ } ,
1313
+ appInfo : { language : "en-US" , platform : "Linux x86_64" } ,
1314
+ calculationOrder : [ ] ,
1315
+ dispatchEventName : "_dispatchMe" ,
1316
+ } ;
1317
+ sandbox . createSandbox ( data ) ;
1318
+
1319
+ let value = "" ;
1320
+ const changes = "123-4567" ;
1321
+ let i = 0 ;
1322
+
1323
+ for ( ; i < changes . length ; i ++ ) {
1324
+ const change = changes . charAt ( i ) ;
1325
+ await sandbox . dispatchEventInSandbox ( {
1326
+ id : refId ,
1327
+ value,
1328
+ change,
1329
+ name : "Keystroke" ,
1330
+ willCommit : false ,
1331
+ selStart : i ,
1332
+ selEnd : i ,
1333
+ } ) ;
1334
+ expect ( send_queue . has ( refId ) ) . toEqual ( false ) ;
1335
+ value += change ;
1336
+ }
1337
+
1338
+ await sandbox . dispatchEventInSandbox ( {
1339
+ id : refId ,
1340
+ value,
1341
+ change : "A" ,
1342
+ name : "Keystroke" ,
1343
+ willCommit : false ,
1344
+ selStart : i ,
1345
+ selEnd : i ,
1346
+ } ) ;
1347
+ expect ( send_queue . has ( refId ) ) . toEqual ( true ) ;
1348
+ expect ( send_queue . get ( refId ) ) . toEqual ( {
1349
+ id : refId ,
1350
+ value,
1351
+ selRange : [ i , i ] ,
1352
+ } ) ;
1353
+
1354
+ send_queue . delete ( refId ) ;
1355
+ } ) ;
1356
+ } ) ;
1357
+
1179
1358
describe ( "eMailValidate" , function ( ) {
1180
1359
it ( "should validate an e-mail address" , async ( ) => {
1181
1360
let value = await myeval ( `eMailValidate(123)` ) ;
0 commit comments