How to use parseJSON method in Jest

Best JavaScript code snippet using jest

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

native.js

Source: native.js Github

copy
1GROUPING_POINT = '.';
2var DECIMAL_POINT = ',';
3var IE = false;
4var ENCODING = 'ISO-8859-1';
5var Bridge;
6
7
8Date.prototype.compareTo = function(value) {
9   if (!(value instanceof Date)) {
10      throw RuleException($mainform().getLocaleMessage("ERROR.IMCOMPATIBLE_TYPE"));
11   }
12
13   var compare;
14
15   if (this.valueOf() > value.valueOf()) {
16       compare = 1;
17   } else if (this.valueOf() < value.valueOf()) {
18       compare = -1;
19   } else {
20       compare = 0;
21   }
22
23   return compare;
24}
25
26Time.prototype.compareTo = function(value) {
27  if (!value instanceof Time) {
28     throw RuleException($mainform().getLocaleMessage("ERROR.IMCOMPATIBLE_TYPE"));
29  }
30
31  var compare;
32  var actualTime = new Time(this.getHour(), this.getMinute(), this.getSecond(), this.getMillisecond());
33  var compareTime = new Time(value.getHour(), value.getMinute(), value.getSecond(), value.getMillisecond());
34
35  if (actualTime.getDate().valueOf() > compareTime.getDate().valueOf()) {
36    compare = 1;
37  } else if (actualTime.getDate().valueOf() < compareTime.getDate().valueOf()) {
38    compare = -1;
39  } else {
40    compare = 0;
41  }
42
43  return compare;
44}
45
46if(top.platform == "ioshtml5"){
47  //Sobrescreve o alerta do Windows para remover o ".html" do título
48  window.alert = function(message) {top.getUtils().showAlert(" ",message);};
49  top.alert = function(message) {top.getUtils().showAlert(" ",message);};
50  window.Tracking = function () { top.getTracking();};
51}
52
53var EMPTY_MAP = new MakerMap();
54
55function checkError(erro) {
56
57  if(erro!=undefined)
58  {
59    var msg=erro+"";
60
61    if( msg.indexOf("foreign key constraint") >= 0) {
62      msg = "Erro ao tentar excluir o registro. Verifique se o registro possui dependências";
63      throw msg;
64    }
65  }
66
67  else if (window._runner_LastException) {
68
69    var msg = window._runner_LastException.toString();
70    if ( msg.indexOf("error code 19: constraint failed") >= 0 ||  erro.indexOf("error code 19: constraint failed") >= 0) {
71      msg = "Erro ao tentar Incluir novo registro. Verifique se o registro não é duplicado.";
72    }
73    if ( msg.indexOf("foreign key constraint") >= 0 ||  erro.indexOf("error code 19: constraint failed") >= 0) {
74      msg = "Erro ao tentar excluir o registro. Verifique se o registro não possui dependências.";
75    }
76    throw msg;
77  }
78};
79
80function IsNumeric(input) {
81  var x = ((input - 0) == input) && (input.length > 0 || input.length == undefined);
82  return x;
83}
84
85
86var AudioUtils = function(){ };
87
88AudioUtils.prototype.startRecord = function(format) {
89 return Bridge.exec('AudioUtils', 'startRecord', parseJSON([format]));
90}
91
92AudioUtils.prototype.stopRecord = function() {
93 return Bridge.exec('AudioUtils', 'stopRecord', parseJSON([]));
94}
95
96AudioUtils.prototype.startVoiceCapture = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams) {
97  return Bridge.exec('AudioUtils', 'startVoiceCapture', parseJSON([formGUID, onSuccess, onSuccessParams? onSuccessParams : new Array(), onFail, onFailParams? onFailParams : new Array()]));
98};
99
100function getAudioUtils() {
101  return new AudioUtils();
102}
103
104
105var A920Utils = function() { };
106
107A920Utils.prototype.toggleLight = function() {
108  Bridge.exec('A920Utils', 'toggleLight', parseJSON([]));
109}
110
111A920Utils.prototype.printText = function(text) {
112  Bridge.exec('A920Utils', 'printText', parseJSON([text]));
113}
114
115A920Utils.prototype.printQrCode = function(dir) {
116  Bridge.exec('A920Utils', 'printQrCode', parseJSON([dir]));
117}
118
119A920Utils.prototype.readIcc = function(onSuccess, onSuccessParams, onError, onErrorParams,formGUID) {
120  Bridge.exec('A920Utils', 'readIcc', parseJSON([formGUID, onSuccess, onSuccessParams, onError, onErrorParams]));
121}
122
123A920Utils.prototype.readMag = function(onSuccess, onSuccessParams, onError, onErrorParams, formGUID) {
124  Bridge.exec('A920Utils', 'readMag', parseJSON([formGUID, onSuccess, onSuccessParams, onError, onErrorParams]));
125}
126
127var Cursor = function(cursor) {
128  this.cursor = cursor;
129  this.row = new Object();
130};
131
132Cursor.prototype.handleSuccess = function() {
133}
134
135Cursor.prototype.handleError = function(e) {
136  // alert(e);
137}
138
139Cursor.prototype.next = function() {
140  row = Bridge.exec('Database', 'next', parseJSON([this.cursor.toString()]));
141  if (row) {
142    this.row = MakerMap.prototype.getInstance(JSON.parse(row));
143  } else {
144    this.row = EMPTY_MAP;
145  }
146}
147
148Cursor.prototype.field = function(name, type) {
149  if (this.row) {
150    if (typeof name == 'string') {
151      return this.row.get(name.toUpperCase());
152    } else {
153      return this.row.get(this.row.get('_metadata')[parseInt(name)-1]);
154    }
155  } else {
156    return null;
157  }
158}
159
160Cursor.prototype.previous = function() {
161  Bridge.exec('Database', 'previous', parseJSON([this.cursor.toString()]));
162}
163
164Cursor.prototype.last = function() {
165  Bridge.exec('Database', 'last', parseJSON([this.cursor.toString()]));
166}
167
168Cursor.prototype.first = function() {
169  Bridge.exec('Database', 'first', parseJSON([this.cursor.toString()]));
170}
171
172Cursor.prototype.close = function() {
173  Bridge.exec('Database', 'close', parseJSON([this.cursor.toString()]));
174}
175
176Cursor.prototype.hasdata = function() {
177  var result = Bridge.exec('Database', 'hasdata', parseJSON([this.cursor.toString()]));
178  return result.toString() === "true";
179}
180
181Cursor.prototype.getColumnCount = function() {
182  return Bridge.exec('Database', 'getColumnCount', parseJSON([this.cursor.toString()]));
183}
184
185var Database = function() {};
186
187Database.prototype.fixParameters = function(p) {
188  if (p != null) {
189    for ( var i = 0; i < p.length; i++) {
190      if (p[i] && ((p[i] instanceof Date) || (p[i].getTime))) {
191        p[i] = p[i].getTime();
192      };
193    }
194  }
195  return p;
196}
197
198Database.prototype.openOrCreateDatabase = function(databaseName) {
199  return Bridge.exec('Database', 'openOrCreateDatabase', parseJSON([databaseName]));
200};
201
202Database.prototype.execSQL = function(sql, bindParams) {
203  var output = Bridge.exec('Database', 'execSQL', parseJSON([top.databaseInstance.toString(), sql, this.fixParameters(bindParams)]));
204  return (output == "") ? null : output;
205};
206
207Database.prototype.rawQuery = function(sql, bindParams) {
208  return new Cursor(Bridge.exec('Database', 'rawQuery',  parseJSON([top.databaseInstance.toString(), sql, this.fixParameters(bindParams)])));
209};
210
211Database.prototype.beginTransaction = function() {
212  Bridge.exec('Database', 'beginTransaction', parseJSON([top.databaseInstance.toString()]));
213};
214
215Database.prototype.commitTransaction = function() {
216  Bridge.exec('Database', 'commitTransaction', parseJSON([top.databaseInstance.toString()]));
217};
218
219Database.prototype.rollbackTransaction = function() {
220  Bridge.exec('Database', 'rollbackTransaction', parseJSON([top.databaseInstance.toString()]));
221};
222
223
224var FirebaseDatabaseUtils = function() {};
225
226FirebaseDatabaseUtils.prototype.connect = function() {
227  Bridge.exec('FirebaseDatabaseUtils', 'connect', parseJSON([]));
228}
229
230FirebaseDatabaseUtils.prototype.onDisconnect = function(node, data) {
231  Bridge.exec('FirebaseDatabaseUtils', 'onDisconnect', parseJSON([node, data]));
232}
233
234FirebaseDatabaseUtils.prototype.writeData = function(node, udid, data, async, onSuccess, onSuccessParams, errorRule, errorParams) {
235  return Bridge.exec('FirebaseDatabaseUtils', 'writeData', parseJSON([node, udid, data,async ? async: false, onSuccess ? onSuccess : "", onSuccessParams ? onSuccessParams : new Array(), errorRule ? errorRule : "", errorParams ? errorParams : new Array() ]));
236}
237
238FirebaseDatabaseUtils.prototype.readData = function(formGUID, onSuccess, onSuccessParams, node, filter, orderType, orderData) {
239  Bridge.exec('FirebaseDatabaseUtils', 'readData', parseJSON([formGUID, onSuccess, onSuccessParams, node, filter, orderType, orderData]));
240}
241
242FirebaseDatabaseUtils.prototype.monitoring = function(formGUID, onSuccess, onSuccessParams, node, filter, orderType, orderData) {
243  Bridge.exec('FirebaseDatabaseUtils', 'monitoring', parseJSON([formGUID, onSuccess, onSuccessParams, node, filter, orderType, orderData]));
244}
245
246FirebaseDatabaseUtils.prototype.stopMonitoring = function(node) {
247  Bridge.exec('FirebaseDatabaseUtils', 'stopMonitoring', parseJSON([node]));
248}
249
250function getFirebaseDatabaseUtils() {
251  return new FirebaseDatabaseUtils();
252}
253
254var GeoFireUtils = function() {};
255
256function getGeoFireUtils() {
257  return new GeoFireUtils();
258}
259
260GeoFireUtils.prototype.setPosition = function(onSuccess, onSuccessParams, node, key, lat, lgt) {
261  Bridge.exec("GeoFireUtils", "setPosition", parseJSON(["{00000000-0000-0000-0000-000000000001}",  onSuccess ? onSuccess : "", onSuccessParams ? onSuccessParams : new Array(), node, key, lat, lgt]));
262};
263
264GeoFireUtils.prototype.watch = function(onSuccess, onSuccessParams, node, lat, lgt, radius) {
265    Bridge.exec("GeoFireUtils", "watch", parseJSON(["{00000000-0000-0000-0000-000000000001}", onSuccess ? onSuccess : "", onSuccessParams ? onSuccessParams : new Array(), node, lat, lgt, radius]));
266};
267
268GeoFireUtils.prototype.stopWatching = function() {
269    Bridge.exec("GeoFireUtils", "stopWatching", parseJSON([]));
270};
271
272
273var NetworkUtils = function() { this.headers = new Object(); };
274
275
276function getNetworkUtils() {
277  return new NetworkUtils();
278}
279
280NetworkUtils.prototype.setRequestHeader = function (paramName, paramValue) {
281  this.headers[paramName] = paramValue;
282}
283
284NetworkUtils.prototype.handleSuccess = function() {
285  window._runner_LastException = false;
286}
287
288NetworkUtils.prototype.setRuleOnConnect = function(rule, ruleParams) {
289 Bridge.exec('NetworkUtils', 'setRuleOnConnect', parseJSON([rule, ruleParams]));
290}
291
292NetworkUtils.prototype.setRuleOnDisconnect = function(rule, ruleParams) {
293 Bridge.exec('NetworkUtils', 'setRuleOnDisconnect', parseJSON([rule, ruleParams]));
294}
295
296NetworkUtils.prototype.handleError = function(e) {
297  var err = new Error(e);
298  window._runner_LastException = err;
299}
300
301NetworkUtils.prototype.postData = function(url, reqType, data, files) {
302    if (top.platform == "ioshtml5") {
303      var postHeader = this.headers;
304      this.headers = new Object();
305      if (files) {
306          return Bridge.exec('NetworkUtils', 'postFile', parseJSON([url, data, files]));
307      } else {
308          var code = parseInt(Math.random() * 99999).toString();
309          return Bridge.exec('NetworkUtils', 'postData', parseJSON([url, reqType, this.headers, data, code]));
310      }
311    } else {
312        return Bridge.exec('NetworkUtils', 'postData', parseJSON([url, reqType, this.headers, data, files]));
313    }
314};
315
316
317NetworkUtils.prototype.postDataAsync = function(url, data, files, onSuccess, onSuccessParams, onError, onErrorParams, formGUID) {
318  Bridge.exec('NetworkUtils', 'postFileAsync', parseJSON([url, data, files, formGUID, onSuccess, onSuccessParams? onSuccessParams : new Array(), onError, onErrorParams? onErrorParams : new Array()]));
319	
320};
321
322NetworkUtils.prototype.checkInternetConnection = function(success, successParams, fail, failParams) {
323  Bridge.exec('NetworkUtils', 'isOnline', parseJSON([success, successParams ? successParams:[], fail, failParams ? failParams : []]));
324};
325
326NetworkUtils.prototype.sendImageInBody = function(url, file) {
327  return Bridge.exec('NetworkUtils', 'sendImageInBody', parseJSON([url, file]));
328};
329
330NetworkUtils.prototype.sendEmail = function(remetente,conteudo,assunto) {
331  return Bridge.exec('NetworkUtils', 'sendEmail', parseJSON([conteudo,remetente,assunto]));
332};
333
334NetworkUtils.prototype.downloadStart = function(url,fileName) {
335  return Bridge.exec('NetworkUtils', 'downloadStart', parseJSON([url,fileName]));
336};
337
338NetworkUtils.prototype.postFile = function(url, params, fileField, filePath) {
339  return Bridge.exec('NetworkUtils', 'postFile', parseJSON([url, params, fileField, filePath]));
340
341};
342
343NetworkUtils.prototype.sendSoapMessage = function(urlVar, soapAction, content) {
344  return Bridge.exec('NetworkUtils', 'sendSoapMessage', parseJSON([urlVar, soapAction, content, "UTF-8"]));
345
346};
347
348
349NetworkUtils.prototype.postDataHttps = function(url, postData, contentType) {
350  return Bridge.exec('NetworkUtils', 'postDataHttps', parseJSON([url, postData, contentType]));
351};
352
353
354NetworkUtils.prototype.networkstatus = function() {
355  return Bridge.exec('NetworkUtils', 'networkstatus', parseJSON([]));
356};
357
358var FunctionsUtils = function() { this.headers = new Object(); };
359
360function getFunctionsUtils() {
361  return new FunctionsUtils();
362}
363
364FunctionsUtils.prototype.setRequestHeader = function (paramName, paramValue) {
365  this.headers[paramName] = paramValue;
366}
367
368FunctionsUtils.prototype.handleSuccess = function() {
369  window._runner_LastException = false;
370}
371
372FunctionsUtils.prototype.handleError = function(e) {
373  var err = new Error(e);
374  window._runner_LastException = err;
375}
376
377
378FunctionsUtils.prototype.startKeyBoard = function(e) {
379  return Bridge.exec('FunctionsUtils','startKeyBoard', parseJSON([]));
380}
381
382FunctionsUtils.prototype.closeKeyBoard = function(x,y) {
383  return Bridge.exec('FunctionsUtils', 'closeKeyBoard', parseJSON([x,y]));
384}
385
386var FileUtils = function() {
387};
388
389FileUtils.prototype.handleSuccess = function() {
390  // Success
391}
392
393FileUtils.prototype.handleError = function(e) {
394  alert(e);
395}
396
397FileUtils.prototype.openView = function (url) {
398  return Bridge.exec('App', 'openOtherApp', parseJSON([url]));
399}
400
401FileUtils.prototype.fileCopy = function(pathFile,newFile) {
402  return Bridge.exec('FileUtils','fileCopy', parseJSON([pathFile,newFile]));
403}
404
405FileUtils.prototype.fileMoveTo = function(pathFile,newFile) {
406  return Bridge.exec('FileUtils','fileMoveTo', parseJSON([pathFile,newFile]));
407}
408
409FileUtils.prototype.getExternalStorage = function(e) {
410  return Bridge.exec('FileUtils','getExternalStorage', parseJSON([]));
411}
412
413FileUtils.prototype.fileOpenReadOnly = function(fileName) {
414  return Bridge.exec('FileUtils','fileOpenReadOnly', parseJSON([ fileName ]));
415}
416
417FileUtils.prototype.fileOpenWrite = function(fileName, append) {
418  return Bridge.exec('FileUtils','fileOpenWrite', parseJSON([ fileName, append ]));
419}
420
421FileUtils.prototype.fileReadAllBytes = function(fileRef) {
422  return Bridge.exec('FileUtils','fileReadAllBytes', parseJSON([ fileRef ]));
423};
424
425FileUtils.prototype.fileReadAllText = function(fileRef) {
426  return Bridge.exec('FileUtils','fileReadAllText', parseJSON([ fileRef ]));
427};
428
429FileUtils.prototype.fileReadLine = function(fileRef) {
430  return Bridge.exec('FileUtils','fileReadLine', parseJSON([ fileRef ]));
431};
432
433FileUtils.prototype.fileEoF = function(fileRef) {
434  return Bridge.exec('FileUtils','fileEoF', parseJSON([ fileRef ]));
435};
436
437FileUtils.prototype.fileAppend = function(fileRef, content) {
438  return Bridge.exec('FileUtils','fileAppend', parseJSON([ fileRef, content ]));
439};
440
441FileUtils.prototype.fileReadLine = function(fileRef) {
442  return Bridge.exec('FileUtils','fileReadLine', parseJSON([ fileRef ]));
443};
444
445FileUtils.prototype.fileEoF = function(fileRef) {
446  return Bridge.exec('FileUtils','fileEoF', parseJSON([ fileRef ]));
447};
448
449FileUtils.prototype.fileClose = function(fileRef) {
450  return Bridge.exec('FileUtils','fileClose', parseJSON([ fileRef ]));
451};
452
453FileUtils.prototype.fileDataDir = function() {
454  return Bridge.exec('FileUtils', 'fileDataDir', parseJSON([]));
455};
456
457FileUtils.prototype.fileBase64ToBinary = function(content) {
458  return Bridge.exec('FileUtils', 'Base64ToBinary', parseJSON([content]));
459};
460
461FileUtils.prototype.binaryToBase64 = function(content) {
462  return Bridge.exec('FileUtils', 'binaryToBase64', parseJSON([content]));
463};
464
465FileUtils.prototype.fileRename = function(oldPath, newPath) {
466  return Bridge.exec('FileUtils', 'fileRename', parseJSON([oldPath, newPath]));
467};
468
469FileUtils.prototype.showAlert = function(title, message) {
470  Bridge.exec('Utils', 'showAlert', parseJSON([title,message]));
471};
472
473FileUtils.prototype.openfilechosser = function(Sucess,Fail,formGUID) {
474
475  Bridge.exec('FileUtils', 'openfilechosser', parseJSON([Sucess,Fail,formGUID]));
476};
477
478
479FileUtils.prototype.confirmshow = function(orderOK, title, message, rule, args, formGUID) {
480  Bridge.exec('FileUtils', 'confirmshow', parseJSON([orderOK,title, message, rule, args, formGUID]));
481};
482
483var PinpadUtils = function() {
484};
485
486function getPinpadUtils() {
487  return new PinpadUtils();
488}
489
490PinpadUtils.prototype.handleSuccess = function() {
491  window._runner_LastException = false;
492}
493
494PinpadUtils.prototype.handleError = function(e) {
495  var err = new Error(e);
496  window._runner_LastException = err;
497}
498
499PinpadUtils.prototype.connection = function(serverIP, serverPORT) {
500  return Bridge.exec('PinpadUtils', 'connection', parseJSON([serverIP, serverPORT]));
501};
502
503PinpadUtils.prototype.verifyConnection = function() {
504  return Bridge.exec('PinpadUtils', 'verifyConnection', parseJSON([]));
505};
506
507PinpadUtils.prototype.disConnect = function() {
508  return Bridge.exec('PinpadUtils', 'disConnect', parseJSON([]));
509};
510
511PinpadUtils.prototype.sendMessage = function(message) {
512  return Bridge.exec('PinpadUtils', 'sendMessage', parseJSON([message]));
513};
514
515PinpadUtils.prototype.awaitingResponse = function(onSuccess, onError) {
516  return Bridge.exec('PinpadUtils', 'awaitingResponse',parseJSON([onSuccess, onError]));
517};
518
519
520var WirelessUtils = function() {
521};
522
523WirelessUtils.prototype.handleSuccess = function() {
524  window._runner_LastException = false;
525}
526
527WirelessUtils.prototype.handleError = function(e) {
528  var err = new Error(e);
529  window._runner_LastException = err;
530}
531
532
533
534WirelessUtils.prototype.sendFile = function(fileName, mimeType) {
535  return Bridge.exec('WirelessUtils', 'sendFile', parseJSON([fileName, mimeType]));
536};
537
538WirelessUtils.prototype.sendText = function(title, text) {
539  return Bridge.exec('WirelessUtils', 'sendText', parseJSON([title, text]));
540};
541
542WirelessUtils.prototype.btExists = function() {
543  return Bridge.exec('WirelessUtils', 'btExists', parseJSON([]));
544};
545
546WirelessUtils.prototype.btIsActive = function() {
547  return Bridge.exec('WirelessUtils', 'btIsActive', parseJSON([]));
548};
549
550WirelessUtils.prototype.btActivate = function(force) {
551  return Bridge.exec('WirelessUtils', 'btActivate', parseJSON([force]));
552};
553
554WirelessUtils.prototype.btDeactivate = function(force) {
555  return Bridge.exec('WirelessUtils', 'btDeactivate', parseJSON([force]));
556};
557
558WirelessUtils.prototype.btMakeDiscoverable = function() {
559  return Bridge.exec('WirelessUtils', 'btDiscoverable', parseJSON([]));
560};
561
562WirelessUtils.prototype.btGetPairedDevices = function() {
563  return Bridge.exec('WirelessUtils', 'btPairedDevices', parseJSON([]));
564};
565
566WirelessUtils.prototype.btSetup = function() {
567  return Bridge.exec('WirelessUtils', 'btSetup', parseJSON([]));
568};
569
570function getWirelessUtils() {
571  return new WirelessUtils();
572}
573
574var BarcodeUtils = function() {
575};
576
577BarcodeUtils.prototype.handleSuccess = function() {
578}
579
580BarcodeUtils.prototype.handleError = function() {
581}
582
583BarcodeUtils.prototype.scan = function(onSuccess, onError, bTypes, formreference) {
584  Bridge.exec('BarcodeUtils', 'scan', parseJSON([bTypes, onSuccess, onError, formreference]));
585};
586
587BarcodeUtils.prototype.generate = function(bTypes) {
588 return Bridge.exec('BarcodeUtils', 'generate', parseJSON([bTypes]));
589};
590
591function getBarcodeUtils() {
592  return new BarcodeUtils();
593}
594
595var CameraUtils = function() {
596};
597
598CameraUtils.prototype.handleSuccess = function() {
599}
600
601CameraUtils.prototype.handleError = function(e) {
602  alert(e);
603}
604
605CameraUtils.prototype.open = function(sucess,fail,quality,form, options) {
606  Bridge.exec('CameraUtils', 'open', parseJSON([sucess,fail,quality,form, options]));
607};
608
609CameraUtils.prototype.sendImage = function(obj, form) {
610  Bridge.exec('CameraUtils', 'sendImage', parseJSON([obj.id, form]));
611};
612
613CameraUtils.prototype.scanCard = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams) {
614  Bridge.exec('CameraUtils', 'scanCard', parseJSON([formGUID, onSuccess, onSuccessParams, onFail, onFailParams]));
615};
616
617CameraUtils.prototype.close = function() {
618  Bridge.exec('CameraUtils', 'close', parseJSON([]));
619};
620
621function getCameraUtils() {
622  return new CameraUtils();
623}
624
625var AppUtils = function() {
626};
627
628AppUtils.prototype.handleSuccess = function() {
629}
630
631AppUtils.prototype.handleError = function(e) {
632  alert(e);
633}
634
635AppUtils.prototype.openMap = function(latitude, longitude) {
636  document.location = 'geo:'+latitude+','+longitude+'?q=('+latitude+','+longitude+')';
637};
638
639AppUtils.prototype.openYouTube = function(code) {
640  document.location = 'vnd.youtube://'+code;
641};
642
643function getAppUtils() {
644  return new AppUtils();
645}
646
647var AuthUtils = function() {
648};
649
650AuthUtils.prototype.authSMS = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams, phone) {
651  Bridge.exec('AuthUtils', 'authSMS', parseJSON([formGUID, onSuccess, onSuccessParams, onFail, onFailParams, phone]));
652};
653
654AuthUtils.prototype.emailLogin = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams, email, password) {
655  Bridge.exec('AuthUtils', 'emailLogin', parseJSON([formGUID, onSuccess, onSuccessParams, onFail, onFailParams, email, password]));
656};
657
658AuthUtils.prototype.tokenLogin = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams, token) {
659  Bridge.exec('AuthUtils', 'tokenLogin', parseJSON([formGUID, onSuccess, onSuccessParams? onSuccessParams : new Array(), onFail, onFailParams? onFailParams :  new Array(), token]));
660};
661
662
663AuthUtils.prototype.isUserLoggedIn = function() {
664  return Bridge.exec('AuthUtils', 'isUserLoggedIn', parseJSON([]));
665};
666
667AuthUtils.prototype.facebookLogin = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams, facebookParams) {
668  Bridge.exec('AuthUtils', 'facebookLogin', parseJSON([formGUID, onSuccess, onSuccessParams, onFail, onFailParams, facebookParams]));
669};
670
671AuthUtils.prototype.googleLogin = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams) {
672  Bridge.exec('AuthUtils', 'googleLogin', parseJSON([formGUID, onSuccess, onSuccessParams, onFail, onFailParams]));
673};
674
675AuthUtils.prototype.onLogout = function() {
676  Bridge.exec('AuthUtils', 'onLogout', parseJSON([]));
677};
678
679AuthUtils.prototype.passwordReset = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams, email) {
680  Bridge.exec('AuthUtils', 'passwordReset', parseJSON([formGUID, onSuccess, onSuccessParams, onFail, onFailParams, email]));
681};
682
683AuthUtils.prototype.emailVerification = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams) {
684    Bridge.exec('AuthUtils', 'emailVerification', parseJSON([formGUID, onSuccess, onSuccessParams, onFail, onFailParams]));
685};
686
687function getAuthUtils() {
688  return new AuthUtils();
689};
690
691function capturePhoto(onPhotoDataSuccess, onFail, qualityValue) {
692  navigator.camera.getPicture(onPhotoDataSuccess, onFail, {destinationType: Camera.DestinationType.FILE_URI, quality: 25, targetWidth: 800, targetHeight: 600 });
693};
694
695var LocationUtils = function(){};
696
697LocationUtils.prototype.statusGPS = function() {
698  return parseBoolean(Bridge.exec('LocationUtils', 'statusGPS', parseJSON([])));
699};
700
701LocationUtils.prototype.enableGPS = function() {
702  return parseBoolean(Bridge.exec('LocationUtils', 'enableGPS', parseJSON([])));
703};
704
705LocationUtils.prototype.startLocationService = function(formGUID, successRule, succesParams, errorRule, errorParams) {
706  return Bridge.exec('LocationUtils', 'startLocationService', parseJSON([formGUID, successRule, succesParams, errorRule, errorParams]));
707};
708
709LocationUtils.prototype.getCurrentLocation = function() {
710  var json = Bridge.exec('LocationUtils', 'getCurrentLocation', parseJSON([]));
711  if(typeof json == 'string'){
712    return JSON.parse(json);
713  }else{
714    return json;
715  }
716};
717
718LocationUtils.prototype.getGPSLastCoords = function() {
719  return Bridge.exec('LocationUtils', 'getGPSLastCoords', parseJSON([]));
720};
721
722LocationUtils.prototype.startMonitoringGPS = function(formGUID, monitoringRule, monitoringParams, priority, interval, fastestInterval) {
723  return Bridge.exec('LocationUtils', 'startMonitoringGPS', parseJSON([priority, interval, fastestInterval, formGUID, monitoringRule, monitoringParams]));
724};
725
726LocationUtils.prototype.disconnect = function() {
727  return Bridge.exec('LocationUtils', 'disconnect', parseJSON([]));
728};
729
730function getPosition(formGUID, onPositionSuccess, onFail){
731    Bridge.exec('LocationUtils', 'currentLocation', parseJSON([formGUID, onPositionSuccess, onFail]));
732};
733
734function onSuccessGPS(winTarget, onPositionSuccess, result) {
735  list = result.split("|");
736  var map = new MakerMap();
737  if(!isNullOrEmpty(result)&& result != "-303"){
738    map.add(list[0],list[1]);
739    map.add(list[2],list[3]);
740    map.add(list[4],list[5]);
741    map.add(list[6],list[7]);
742    map.add(list[8],list[9]);
743    map.add(list[10],list[11]);
744    map.add(list[12],list[13]);
745    getWindow(winTarget).eval(onPositionSuccess).apply(this, [map]);
746  }
747};
748
749function updateViews(e) {
750  for (var i=0;i<views.length;i++) {
751    var viewFrame = views[i].getElementsByTagName("iframe")[0];
752
753    if (viewFrame.contentWindow.doResize) {
754      viewFrame.contentWindow.doResize(e);
755    }
756  }
757};
758
759var supportsOrientationChange = "onorientationchange" in window;
760var orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
761
762window.addEventListener(orientationEvent, function() {
763  if (Math.abs(window.orientation) == 90 && currentOrientation != 90) {
764    currentOrientation = 90;
765    updateViews();
766  }
767
768  if ((Math.abs(window.orientation) == 0 || Math.abs(window.orientation) == 180) && currentOrientation != 0) {
769    currentOrientation = 0;
770    updateViews();
771  }
772
773}, false);
774
775function init(mainView) {
776  if (window.innerWidth > window.innerHeight) {
777    currentOrientation = 90;
778  }
779  openView(mainView);
780}
781
782var PushNotification = function() {
783};
784
785PushNotification.prototype.handleSuccess = function() {
786};
787
788PushNotification.prototype.handleError = function(e) {
789  alert(e);
790}
791
792PushNotification.prototype.register = function(cod, appId, formGUID) {
793    if (top.platform == "ioshtml5") {
794        return Bridge.exec('PushPlugin', 'register', parseJSON([formGUID, cod, appId]));
795    } else {
796        return Bridge.exec('PushPlugin', 'register', parseJSON([cod, appId]));
797    }
798};
799
800PushNotification.prototype.unregister = function(cod) {
801  Bridge.exec('PushPlugin', 'unregister', parseJSON([cod]));
802};
803
804PushNotification.prototype.getPushId = function() {
805  return Bridge.exec('PushPlugin', 'getPushId', parseJSON([]));
806};
807
808function getPushNotification() {
809  return new PushNotification();
810};
811
812if(!window.plugins) {
813  window.plugins = {};
814}
815
816var Utils = function() {
817};
818
819Utils.prototype.OpenUrlOnNewTab = function(winURL) {
820    Bridge.exec('Utils', 'OpenUrlOnNewTab', top.parseJSON([winURL]));
821};
822
823Utils.prototype.returnNotification = function() {
824   Bridge.exec('Utils', 'returnNotification', parseJSON([]));
825};
826
827Utils.prototype.createNotification = function(notificationRule, notificationParams, notificationTitle, notificationText, autocancel, ongoing, notificationID) {
828  Bridge.exec('Utils', 'createNotification', parseJSON([notificationRule, notificationParams, notificationTitle, notificationText, autocancel, ongoing, notificationID]));
829};
830
831Utils.prototype.isInBackground = function() {
832  return parseBoolean(Bridge.exec('Utils', 'isInBackground', parseJSON([])));
833};
834
835Utils.prototype.handleSuccess = function() {
836};
837
838Utils.prototype.handleError = function(e) {
839  alert(e);
840};
841
842Utils.prototype.configureFirebase = function(path) {
843  Bridge.exec('Utils', 'configureFirebase', parseJSON([path]));
844};
845
846Utils.prototype.showAlert = function(title,message) {
847  Bridge.exec('Utils', 'showAlert', parseJSON([title,message]));
848};
849
850Utils.prototype.showConfirm = function(title,message) {
851  Bridge.exec('Utils', 'showConfirm', parseJSON([title,message,buttons]));
852};
853
854Utils.prototype.printTextBT = function(printerName,content) {
855  return Bridge.exec('Utils', 'printTextBT', parseJSON([printerName,content]));
856};
857
858Utils.prototype.createsharedpreferences = function(name,valor) {
859  return Bridge.exec('Utils', 'createsharedpreferences', parseJSON([name,valor]));
860};
861
862Utils.prototype.SetHardwareAccelerated = function(status) {
863  return Bridge.exec('Utils', 'SetHardwareAccelerated', parseJSON([status]));
864};
865
866Utils.prototype.getallpreferences = function(name) {
867  return Bridge.exec('Utils', 'getallpreferences', parseJSON([name]));
868};
869
870Utils.prototype.clearpreferences = function(name) {
871  return Bridge.exec('Utils', 'clearpreferences', parseJSON([name]));
872};
873
874Utils.prototype.startPlaying = function(media) {
875  return Bridge.exec('Utils', 'startPlaying', parseJSON([media.src]));
876};
877
878Utils.prototype.systemExit = function() {
879  if(navigator.app){
880    return navigator.app.exitApp();
881  } else {
882    return Bridge.exec('Utils', 'systemExit', parseJSON([]));
883  }
884};
885
886Utils.prototype.appBringToFront = function() {
887  return Bridge.exec('Utils', 'appBringToFront', parseJSON([]));
888};
889
890Utils.prototype.getAppVersion = function() {
891  return Bridge.exec('Utils', 'getAppVersion', parseJSON([]));
892};
893
894Utils.prototype.getDeviceInfo = function() {
895  if (top.platform === "ioshtml5"){
896    return Bridge.exec('Utils', 'getDeviceInfo', parseJSON([]))
897  }else{
898    return JSON.parse(Bridge.exec('Utils', 'getDeviceInfo', parseJSON([])));
899  }
900};
901
902function getUtils() {
903  return new Utils();
904};
905
906var Tracking = function() {
907};
908
909Tracking.prototype.setid = function(id) {
910  return Bridge.exec('Tracking', 'setID', parseJSON([id]));
911};
912
913Tracking.prototype.sendView = function(id) {
914  return Bridge.exec('Tracking', 'sendView', parseJSON([id]));
915};
916
917Tracking.prototype.sendEvent = function(id,rule,component) {
918  return Bridge.exec('Tracking', 'sendEvent', parseJSON([id,rule,component]));
919};
920
921Tracking.prototype.sendException = function(id) {
922  return Bridge.exec('Tracking', 'sendException', parseJSON([id]));
923};
924
925function getTracking() {
926  return new Tracking();
927};
928
929var FingerprintUtils = function() {
930};
931
932function getFingerprintUtils() {
933    return new FingerprintUtils();
934};
935
936FingerprintUtils.prototype.fingerprintValidation = function(formGUID, onSuccess, onSuccessParams, onFail, onFailParams) {
937    return Bridge.exec('FingerprintUtils', 'fingerprintValidation', parseJSON([formGUID, onSuccess, onSuccessParams, onFail, onFailParams]));
938};
939
940var WazeUtils = function(){ };
941
942WazeUtils.prototype.startSDK = function(endereco, latitude, longitude) {
943  Bridge.exec('WazeUtils', 'startSDK', parseJSON([endereco ? endereco:"", latitude, longitude]));
944}
945
946WazeUtils.prototype.searchRequestWithNavigation = function(endereco, latitude, longitude) {
947  Bridge.exec('WazeUtils', 'searchRequestWithNavigation', parseJSON([endereco ? endereco:"",latitude,longitude]));
948}
949
950WazeUtils.prototype.openWaze = function() {
951  Bridge.exec('WazeUtils', 'openWaze', parseJSON([]));
952}
953
954WazeUtils.prototype.terminateSDK = function() {
955  Bridge.exec('WazeUtils', 'terminateSDK', parseJSON([]));
956}
957
958WazeUtils.prototype.getWazebuildnumber = function() {
959 return Bridge.exec('WazeUtils', 'getWazebuildnumber', parseJSON([]));
960}
961
962WazeUtils.prototype.stopNavigationRequest = function() {
963  Bridge.exec('WazeUtils', 'stopNavigationRequest', parseJSON([]));
964}
965
966function getWazeUtils() {
967  return new WazeUtils();
968}
969
970
971function parseJSON(args) {
972  if (typeof JSON === "undefined") {
973    var s = "[";
974    var i, type, start, name, nameType, a;
975    for (i = 0; i < args.length; i++) {
976      if (args[i] !== null) {
977        if (i > 0) {
978          s = s + ",";
979        }
980        type = typeof args[i];
981        if ((type === "number") || (type === "boolean")) {
982          s = s + args[i];
983        } else if (args[i] instanceof Array) {
984          s = s + "[" + args[i] + "]";
985        } else if (args[i] instanceof Object) {
986          start = true;
987          s = s + '{';
988          for (name in args[i]) {
989            if (args[i][name] !== null) {
990              if (!start) {
991                s = s + ',';
992              }
993              s = s + '"' + name + '":';
994              nameType = typeof args[i][name];
995              if ((nameType === "number") || (nameType === "boolean")) {
996                s = s + args[i][name];
997              } else if ((typeof args[i][name]) === 'function') {
998                // don't copy the functions
999                s = s + '""';
1000              } else if (args[i][name] instanceof Object) {
1001                s = s + Bridge.stringify(args[i][name]);
1002              } else {
1003                s = s + '"' + args[i][name] + '"';
1004              }
1005              start = false;
1006            }
1007          }
1008          s = s + '}';
1009        } else {
1010          a = args[i].replace(/\\/g, '\\\\');
1011          a = a.replace(/"/g, '\\"');
1012          s = s + '"' + a + '"';
1013        }
1014      }
1015    }
1016    s = s + "]";
1017    return s;
1018  } else {
1019    return JSON.stringify(args);
1020  }
1021};
1022
1023function systemExit() {
1024  navigator.app.exitApp();
1025}
1026
1027function init(mainView) {
1028  if (window.innerWidth > window.innerHeight) {
1029    currentOrientation = 90;
1030  }
1031  document.addEventListener("orientationChanged", function(e) {
1032    currentOrientation = e.orientation;
1033    updateViews(e);
1034  });
1035  setSession("metadata", GetSystemProperties(), true);
1036  openView(mainView);
1037}
1038
Full Screen

deprecated.js

Source: deprecated.js Github

copy
1QUnit.module( "deprecated", { teardown: moduleTeardown } );
2
3
4QUnit.test( "bind/unbind", function( assert ) {
5	assert.expect( 4 );
6
7	var markup = jQuery(
8		"<div><p><span><b>b</b></span></p></div>"
9	);
10
11	markup
12		.find( "b" )
13		.bind( "click", { bindData: 19 }, function( e, trig ) {
14			assert.equal( e.type, "click", "correct event type" );
15			assert.equal( e.data.bindData, 19, "correct trigger data" );
16			assert.equal( trig, 42, "correct bind data" );
17			assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
18		} )
19		.trigger( "click", [ 42 ] )
20		.unbind( "click" )
21		.trigger( "click" )
22		.remove();
23} );
24
25QUnit.test( "delegate/undelegate", function( assert ) {
26	assert.expect( 2 );
27
28	var markup = jQuery(
29		"<div><p><span><b>b</b></span></p></div>"
30	);
31
32	markup
33		.delegate( "b", "click", function( e ) {
34			assert.equal( e.type, "click", "correct event type" );
35			assert.equal( e.target.nodeName.toLowerCase(), "b", "correct element" );
36		} )
37		.find( "b" )
38			.trigger( "click" )
39			.end()
40		.undelegate( "b", "click" )
41		.remove();
42} );
43
44QUnit.test( "jQuery.parseJSON", function( assert ) {
45	assert.expect( 20 );
46
47	assert.strictEqual( jQuery.parseJSON( null ), null, "primitive null" );
48	assert.strictEqual( jQuery.parseJSON( "0.88" ), 0.88, "Number" );
49	assert.strictEqual(
50		jQuery.parseJSON( "\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \"" ),
51		" \" \\ / \b \f \n \r \t ~ \u263A ",
52		"String escapes"
53	);
54	assert.deepEqual( jQuery.parseJSON( "{}" ), {}, "Empty object" );
55	assert.deepEqual( jQuery.parseJSON( "{\"test\":1}" ), { "test": 1 }, "Plain object" );
56	assert.deepEqual( jQuery.parseJSON( "[0]" ), [ 0 ], "Simple array" );
57
58	assert.deepEqual(
59		jQuery.parseJSON( "[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]" ),
60		[ "string", -4.2, 2.718, 0.314, {}, [], true, false, null ],
61		"Array of all data types"
62	);
63	assert.deepEqual(
64		jQuery.parseJSON( "{ \"string\": \"\", \"number\": 4.2e+1, \"object\": {}," +
65			"\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }" ),
66		{ string: "", number: 42, object: {}, array: [ [] ], "boolean": [ true, false ], "null": null },
67		"Dictionary of all data types"
68	);
69
70	assert.deepEqual( jQuery.parseJSON( "\n{\"test\":1}\t" ), { "test": 1 },
71		"Leading and trailing whitespace are ignored" );
72
73	assert.throws( function() {
74		jQuery.parseJSON();
75	}, null, "Undefined raises an error" );
76	assert.throws( function() {
77		jQuery.parseJSON( "" );
78	}, null, "Empty string raises an error" );
79	assert.throws( function() {
80		jQuery.parseJSON( "''" );
81	}, null, "Single-quoted string raises an error" );
82
83	assert.throws( function() {
84		var result = jQuery.parseJSON( "0101" );
85
86		// Support: IE <=9 only
87		// Ensure base-10 interpretation on browsers that erroneously accept leading-zero numbers
88		if ( result === 101 ) {
89			throw new Error( "close enough" );
90		}
91	}, null, "Leading-zero number raises an error or is parsed as decimal" );
92	assert.throws( function() {
93		jQuery.parseJSON( "{a:1}" );
94	}, null, "Unquoted property raises an error" );
95	assert.throws( function() {
96		jQuery.parseJSON( "{'a':1}" );
97	}, null, "Single-quoted property raises an error" );
98	assert.throws( function() {
99		jQuery.parseJSON( "[,]" );
100	}, null, "Array element elision raises an error" );
101	assert.throws( function() {
102		jQuery.parseJSON( "{},[]" );
103	}, null, "Comma expression raises an error" );
104	assert.throws( function() {
105		jQuery.parseJSON( "[]\n,{}" );
106	}, null, "Newline-containing comma expression raises an error" );
107	assert.throws( function() {
108		jQuery.parseJSON( "\"\"\n\"\"" );
109	}, null, "Automatic semicolon insertion raises an error" );
110
111	assert.strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" );
112} );
113
114QUnit.test( "jQuery.isArray", function( assert ) {
115	assert.expect( 1 );
116
117	assert.strictEqual( jQuery.isArray, Array.isArray, "Array.isArray equals jQuery.isArray" );
118} );
119
120QUnit.test( "jQuery.nodeName", function( assert ) {
121	assert.expect( 8 );
122
123	assert.strictEqual( typeof jQuery.nodeName, "function", "jQuery.nodeName is a function" );
124
125	assert.strictEqual(
126		jQuery.nodeName( document.createElement( "div" ), "div" ),
127		true,
128		"Basic usage (true)"
129	);
130
131	assert.strictEqual(
132		jQuery.nodeName( document.createElement( "div" ), "span" ),
133		false,
134		"Basic usage (false)"
135	);
136
137	assert.strictEqual(
138		jQuery.nodeName( document.createElement( "div" ), "DIV" ),
139		true,
140		"Ignores case in the name parameter"
141	);
142
143	assert.strictEqual(
144		jQuery.nodeName( document.createElement( "section" ), "section" ),
145		true,
146		"Works on HTML5 tags (true)"
147	);
148
149	assert.strictEqual(
150		jQuery.nodeName( document.createElement( "section" ), "article" ),
151		false,
152		"Works on HTML5 tags (false)"
153	);
154
155	assert.strictEqual(
156		jQuery.nodeName( document.createElement( "custom-element" ), "custom-element" ),
157		true,
158		"Works on custom elements (true)"
159	);
160
161	assert.strictEqual(
162		jQuery.nodeName( document.createElement( "custom-element" ), "my-element" ),
163		false,
164		"Works on custom elements (true)"
165	);
166} );
167
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Jest on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)