Best JavaScript code snippet using testcafe
cacheStore2.js
Source:cacheStore2.js  
...148		_updateActivitiesSuccess: function(data, callback1, callback2){149			callback1 = ((callback1 === undefined) ? function(){} : callback1);150			callback2 = ((callback2 === undefined) ? function(){} : callback2);151			152			if(typeTest.isProperty(data, "activities")){153				iArray.forEach(154					data.activities,155					this._throttle,156					this._updateActivity,157					this158				).then(159					lang.hitch(this, callback1)160				);161			}162			163			if(typeTest.isProperty(data, "events")){164				iArray.forEach(165					data.events,166					this._throttle,167					this._updateEvent,168					this169				).then(170					lang.hitch(this, callback2)171				);172			}173		},174		175		_updateActivity: function(activity){176			try{177				if(typeTest.isProperty(activity, "id")){178					var item = this._convertActivityToDataItem(activity);179					var cItem = this.getActivity(item.id.toLowerCase());180					var callUpdate = false;181				182					if((item.isStub) && (cItem !== null)){183						item = lang.mixin(cItem, item);	184					}185				186					if(item.isStub){187						this._activityIdsToUpdate.push(item.id.toLowerCase());188					}else if(cItem !== null){189						if(this._needsUpdating(cItem, item)){190							this._activityIdsToUpdate.push(item.id.toLowerCase());191						}192					}193				194					var isStub = this._isActivityStub(item);195					item.isStub = isStub;196					item.data.isStub = isStub;197				198					this.activitesStore.put(item);199					topic.publish("/rcbc/pin/updateActivity", item.id.toLowerCase(), item);200					this._checkForServiceVenues(activity);201				}202			}catch(e){203				console.warn(e);204			}205		},206		207		_checkForServiceVenues: function(service){208			if(!typeTest.isProperty(service, "data")){209				service = service.data;210			}211			212			if(typeTest.isProperty(service, "venues")){213				array.forEach(service.venues, function(venueId){214					if(typeTest.isProperty(venueId, "venueId")){215						venueId = venueId.venueId;216					}217					if(typeTest.isString(venueId)){218						if(venueId.length == 32){219							var venue = this.venuesStore.get(venue.id.toLowerCase());220							if(typeTest.isBlank(venue)){221								this._venueIdsToUpdate.push(venueId);222							}223						}224					}225				}, this);226			}227		},228		229		_updateEvent: function(event){230			try{231				if(typeTest.isProperty(event,"id")){232					var item = this._convertEventToDataItem(event);233					var cItem = this.getEvent(item.id.toLowerCase());234					var callUpdate = false;235				236					if((item.isStub) && (cItem !== null)){237						item = lang.mixin(cItem, item);	238					}239				240					if(item.isStub){241						this._eventIdsToUpdate.push(item.id.toLowerCase());242					}else if(cItem !== null){243						if(this._needsUpdating(cItem, item)){244							this._eventIdsToUpdate.push(item.id.toLowerCase());245						}246					}247				248					var isStub = this._isActivityStub(item);249					item.isStub = isStub;250					item.data.isStub = isStub;251				252					this.eventsStore.put(item);253					topic.publish("/rcbc/pin/updateEvent", item.id.toLowerCase(), item);254					this._checkForServiceVenues(event)255				}256			}catch(e){257				console.warn(e);258			}259		},260		261		_convertEventToDataItem: function(event){262			event.id = event.id.toLowerCase();263			event.category1 = this._parseCategory(event, 1);264			event.category1 = this._arrayReplace(event.category1, " & ", " and ");265			event.isStub = ((typeTest.isProperty(event, "isStub")) ? event.isStub : true);266			event.tags = this._parseTags(event);267			268			return {269				"id": event.id,270				"type": "event",271				"data": event,272				"isStub": event.isStub273			}274		},275		276		_isActivityStub: function(obj){277			return (!typeTest.isProperty(obj.data, "description") && !typeTest.isProperty(obj.data, "contacts"));278		},279		280		_isActivityItem: function(item){281			if(typeTest.isProperty(item, "type") && typeTest.isProperty(item, "data")){282				if(typeTest.isEqual(item.type, "activity")){283					return true;284				}285			}286			287			return false;288		},289		290		_isEventItem: function(item){291			if(typeTest.isProperty(item, "type") && typeTest.isProperty(item, "data")){292				if(typeTest.isEqual(item.type, "event")){293					return true;294				}295			}296			297			return false;298		},299		300		_convertActivityToDataItem: function(activity){301			activity.id = activity.id.toLowerCase();302			activity.category1 = this._parseCategory(activity, 1);303			activity.category1 = this._arrayReplace(activity.category1, " & ", " and ");304			activity.isStub = ((typeTest.isProperty(activity, "isStub")) ? activity.isStub : true);305			activity.tags = this._parseTags(activity);306			307			return {308				"id": activity.id,309				"type": "activity",310				"data": activity,311				"isStub": activity.isStub312			}313		},314		315		_callVenuesUpdate: function(){316			var ids = new Array();317			for(var i = 0; ((i < this._serverThrottle) && (i < this._venueIdsToUpdate.length)); i++){318				ids.push(this._venueIdsToUpdate.shift());319			}320			321			if(!typeTest.isBlank(ids)){322				xhrManager.add({323					"url": "/pin.nsf/getVenue?openagent",324					"method": "post",325					"data": {326						"id": ids.join(",")327					}328				}).then(329					lang.hitch(this, this._updateVenueSuccess),330					lang.hitch(this, function(e){331						console.info("Failed to update venues - now working from cache", e);332					})333				)334			}335		},336		337		_updateVenueSuccess: function(data){338			if(typeTest.isProperty(data, "venues")){339				iArray.forEach(340					data.venues,341					this._throttle,342					this._updateVenue,343					function(){},344					this345				);346			}347		},348		349		_updateVenue: function(venue){350			var data = this._convertVenueToDataItem(venue);351			this.venuesStore.put(data);352			topic.publish("/rcbc/pin/updateVenue", data.id.toLowerCase(), data);353		},354		355		_convertVenueToDataItem: function(venue){356			venue.id = venue.id.toLowerCase();357			358			return {359				"id": venue.id,360				"type": "venue",361				"data": venue,362				"isStub": venue.isStub363			}364		},365		366		_callServicesUpdate: function(){367			var ids = new Array();368			369			for(var i = 0; ((i < this._serverThrottle) && (i < this._serviceIdsToUpdate.length)); i++){370				ids.push(this._serviceIdsToUpdate.shift());371			}372			373			this._callServicesUpdate2(ids);374		},375		376		_callServicesUpdate2: function(ids){377			if(!typeTest.isBlank(ids)){378				xhrManager.add({379					"url": "/pin.nsf/getService2?openagent&stub=false",380					"method": "post",381					"data": {382						"id": ids.join(",")383					}384				}).then(385					lang.hitch(this, this._updateServiceSuccess),386					lang.hitch(this, function(e){387						console.info("Failed to update services - now working from cache", e);388					})389				);390			}391		},392		393		_callStubsUpdate: function(){394			this._callServiceStubsUpdate();395			// TODO396			//this._callActivityStubsUpdate();397		},398		399		_callServiceStubsUpdate: function(){400			try{401			xhrManager.add({402				"url": "/servicesStub.json",403			}).then(404				lang.hitch(this, function(data){405					this._servicesData = data;406					this._servicesReady++;407					this.readyStubs(data);408					this._updateServiceSuccess(409						data,410						lang.hitch(this, this.readyStubs)411					);412				}),413				lang.hitch(this, function(e){414					console.info("Failed to refresh service stubs - now working off cache", e);415				})416			);417			}catch(e){418				console.info(e);419			}420		},421		422		_callActivityStubsUpdate: function(){423			xhrManager.add({424				"url": "/activitiesStub.json"425			}).then(426				lang.hitch(this, function(data){427					this._updateActivitiesSuccess(data);428				}),429				lang.hitch(this, function(e){430					console.info("Failed to refresh activity stubs - now working off cache", e);431				})432			);433		},434		435		_updateServiceSuccess: function(data, callback){436			callback = ((callback === undefined) ? function(){} : callback);437			438			if(typeTest.isProperty(data, "services")){439				iArray.forEach(440					data.services,441					this._throttle,442					this._updateService,443					this444				).then(445					lang.hitch(this, function(){446						var callback2 = lang.hitch(this, callback);447						callback2();448					})449				);450			}451		},452		453		_updateService: function(service){454			try{455				var item = this._convertServiceToDataItem(service);456				var cItem = this.getService(item.id.toLowerCase());457				var callUpdate = false;458				459				if((item.isStub) && (cItem !== null)){460					item = lang.mixin(cItem, item);461				}462				463				if(item.isStub){464					this._serviceIdsToUpdate.push(item.id.toLowerCase());465				}else if(this._needsUpdating(cItem, item)){466					this._serviceIdsToUpdate.push(item.id.toLowerCase());467				}468				469				var isStub = this._isServiceStub(item);470				item.isStub = isStub;471				item.data.isStub = isStub;472				473				if(typeTest.isProperty(item.data, "data")){474					delete item.data["data"];475				}476				this.servicesStore.put(item);477				478				if(!item.isStub){479					topic.publish("/rcbc/pin/updateService", item.id.toLowerCase(), item);480					this._checkForServiceVenues(service);481				}482			}catch(e){483				console.info("Failed to update service", e);484			}485		},486		487		_removeOldServices: function(data){488			var lookup = new Object();489			490			array.forEach(data.services, function(item){491				lookup[item.id.toLowerCase()] = true;492			}, this);493			494			var query = this.servicesStore.query({});495			array.forEach(query, function(item){496				if(!typeTest.isProperty(lookup, item.id.toLowerCase())){497					this.servicesStore.remove(item.id.toLowerCase());498				}499			}, this);500		},501		502		_needsUpdating: function(oldItem, newItem){503			return (oldItem.hash !== newItem.hash);504		},505		506		_isServiceStub: function(obj){507			return (!typeTest.isProperty(obj.data, "description") && !typeTest.isProperty(obj.data, "venues") && !typeTest.isProperty(obj.data, "contacts"));508		},509		510		_convertServiceToDataItem: function(service){511			service.id = service.id.toLowerCase();512			service.category1 = this._parseCategory(service, 1);513			service.category1 = this._arrayReplace(service.category1, " & ", " and ");514			service.category2 = this._parseCategory(service, 2);515			service.category2 = this._arrayReplace(service.category2, " & ", " and ");516			service.isStub = ((typeTest.isProperty(service, "isStub")) ? service.isStub : true);517			service.tags = this._parseTags(service);518			519			return {520				"id": service.id,521				"type": "service",522				"data": service,523				"isStub": service.isStub524			}525		},526		527		_arrayReplace: function(ary, from, to){528			array.forEach(ary, function(item, n){529				ary[n] = item.replace(from,to);530			}, this);531			532			return ary;533		},534		535		_parseCategory: function(service, categoryNum){536			var fieldName = "category" + categoryNum.toString();537			if(typeTest.isProperty(service, fieldName)){538				if(!typeTest.isArray(service[fieldName])){539					if(typeTest.isBlank(service[fieldName])){540						return new Array();541					}else{542						return this._trimArray(new Array(service[fieldName]));543					}544				}else{545					return this._trimArray(service[fieldName]);546				}547			}548			549			return new Array();550		},551		552		_trimArray: function(ary){553			var newAry = new Array();554			var lookup = new Object();555			556			array.forEach(ary, function(item){557				item = lang.trim(item);558				559				if(!typeTest.isBlank(item) && !typeTest.isProperty(lookup, item)){560					newAry.push(item);561					lookup[item] = true;562				}563			}, this);564			565			return newAry;566		},567		568		_parseTags: function(service){569			if(typeTest.isProperty(service, "tags")){570				if(!typeTest.isArray(service.tags)){571					return this._trimArray(service.tags.split(";"));572				}else{573					return this._trimArray(service.tags);574				}575			}576			577			return new Array();578		},579		580		_getStore: function(type, ready){581			ready = ((ready === undefined) ? function(){} : ready);582			583			return new Store({584				"sessionOnly": this.sessionOnly,585				//"sessionOnly": ((has("ie")) ? true : this.sessionOnly),586				"compress": ((has("ie")) ? false : this.compress),587				"encrypt": this.encrypt,588				"id": this.id.toLowerCase() + type,589				"ready": ready,590				"slicer": 50591			});592		},593		594		getSection: function(section){595			if(this._servicesReady >= 2){596				return this._cache.getCache(597					["getSection", section],598					lang.hitch(this, this._getSection, section)599				);600			}else{601				return this._getSection(section);602			}603		},604		605		_getSection: function(section){606			var fieldName = this._getCategoryFieldName(section);607			var query =  new Array();608			609			if(this._servicesReady >= 2){610				query = this.servicesStore.query(function(obj){611					if(!typeTest.isProperty(obj, "data")){612						obj.data = obj;613					}614					if(typeTest.isProperty(obj.data, fieldName)){615						return !typeTest.isBlank(obj.data[fieldName])616					}617				618					return false;619				});620			}else{621				query = array.filter(this._servicesData.services, function(obj){622					if(!typeTest.isProperty(obj, "data")){623						obj.data = obj;624					}625					if(typeTest.isProperty(obj.data, fieldName)){626						return !typeTest.isBlank(obj.data[fieldName])627					}628					629					return false;630				});631			}632			633			return this._serviceSort(query);634		},635		636		searchServices: function(search, section){637			var query = this._cache.getCache(638				["searchServices", section, search],639				lang.hitch(this, this._searchServices, search, section)640			);641			642			if(!typeTest.isBlank(query)){643				return query;644			}645			return new Array();646		},647		648		_searchServices: function(search, section){649			var query = null;650			if(search.length > 2){651				query = this._cache.getCache([652					"searchServices",653					section,654					search.substring(0, search.length - 1)655				]);656			}657			if(query === null){658				if(!typeTest.isBlank(section)){659					query = this.getSection(section);660				}else{661					query.servicesQuery.query({});662				}663			}664			665			var tests = this._parseSearch(search);666			query = array.filter(query, function(service){667				try{668					if(!typeTest.isProperty(service, "data")){669						service.data = service;670					}671					672					var searcher = JSON.stringify(service.data);673					return this._searchTest(searcher, tests);674				}catch(e){ }675				return false;676			}, this);677			678			return query;679		},680		681		_parseSearch: function(search){682			var words = search.split(" ");683			var tests = new Array();684			array.forEach(words, function(word){685				tests.push(new RegExp("\\W"+word,"i"));686			}, this);687			return tests;688		},689		690		_searchTest: function(query, tests){691			var found = true;692			693			array.every(tests, function(test){694				if(!test.test(query)){695					found = false;696					return false;697				}698				return true;699			}, this);700			701			return found;702		},703		704		getCategory: function(section, category){705			var query = new Array();706			if(/^[A-Fa-f0-9]{32,32}$/.test(category)){707				if(this._servicesReady >= 2){708					query = this._cache.getCache(709						["getCategory", section, category],710						lang.hitch(this, this._getIdCategory, section, category)711					);712				}else{713					query = this._getIdCategory(section, category);714				}715			}else{716				if(this._servicesReady >= 2){717					query = this._cache.getCache(718						["getCategory", section, category],719						lang.hitch(this, this._getCategory, section, category)720					);721				}else{722					query = this._getCategory(section, category);723				}724			}725			726			if(!typeTest.isBlank(query)){727				return query;728			}729			return new Array();730		},731		732		_getCategory: function(section, category){733			var query = this.getSection(section);734			735			query = array.filter(query, function(service){736				return this._itemHasCategory(service, section, category);737			}, this);738			739			return this._serviceSort(query);740		},741		742		_serviceSort: function(query){743			if(query.length > 0){744				if(!typeTest.isProperty(query[0], "data")){745					return query.sort(function(a, b){746						return (((a.serviceName + a.orgName) < (b.serviceName + b.orgName)) ? -1 : 1);747					});748				}749			}750			751			return query.sort(function(a, b){752				return (((a.data.serviceName + a.data.orgName) < (b.data.serviceName + b.data.orgName)) ? -1 : 1);753			});754		},755		756		_getIdCategory: function(section, category){757			if(this.servicesStore.get(category.toLowerCase())){758				var query = this.servicesStore.query(function(obj){759					if(!typeTest.isProperty(obj, "data")){760						obj.data = obj;761					}762					if(typeTest.isProperty(obj.data, "service")){763						return (obj.data.service.toLowerCase() === category.toLowerCase());764					}765					766					return false;767				});768				769				query = query.sort(function(a, b){770					return (((a.data.title) < (b.data.title)) ? -1 : 1);771				});772				773				return query;774			}else{775				return [];776			}777		},778		779		_isServiceItem: function(item){780			if(typeTest.isProperty(item, "type") && typeTest.isProperty(item, "data")){781				if(typeTest.isEqual(item.type, "service")){782					return true;783				}784			}785			786			return false;787		},788		789		_itemHasCategory: function(item, section, category){790			var found = false;791			var fieldName = this._getCategoryFieldName(section);792			if(!typeTest.isProperty(item, "data")){793				item.data = item;794			}795			796			array.every(item.data[fieldName], function(cCat){797				if(typeTest.isEqual(cCat, category)){798					found = true;799					return false;800				}801				return true;802			}, this);803			804			return found;805		},806		807		_getCategoryFieldName: function(section){808			if(!typeTest.isNumber(section)){809				section = (typeTest.isEqual(section,"Family Services")) ? 1 : 2;810			}811			812			return "category" + section.toString();813		},814		815		getCategoryList: function(section){816			if(this._servicesReady >= 2){817				return this._cache.getCache(818					["getCategoryList", section],819					lang.hitch(this, this._getCategoryList, section)820				);821			}else{822				return this._getCategoryList(section);823			}824		},825		826		_getCategoryList: function(section){827			var services = this.getSection(section);828			var categoryList = {};829			var fieldName = this._getCategoryFieldName(section);830			831			array.forEach(services, function(service){832				var categories = this._getCategoryValue(service, fieldName);833				834				array.forEach(categories, function(category){835					if(!typeTest.isBlank(category)){836						if(!typeTest.isProperty(categoryList, category)){837							categoryList[category] = true;838						}839					}840				}, this);841			}, this);842			843			return categoryList;844		},845		846		_getCategoryValue: function(service, fieldName){847			if(typeTest.isObject(service)){848				if(typeTest.isProperty(service, "data")){849					service = service.data;850				}851				852				if(typeTest.isObject(service)){853					if(typeTest.isProperty(service, fieldName)){854						var categories = service[fieldName];855						if(typeTest.isArray(categories)){856							return categories;857						}858					}859				}860			}861			862			return new Array();863		},864		865		getService: function(id){866			var service = this.servicesStore.get(id);867			if(!typeTest.isBlank(service)){868				if(typeTest.isProperty(service, "type")){869					if(service.type == "service"){870						return service;871					}872				}873			}874			875			return null;876		},877		878		getTag: function(section, category, tag){879			if(this._servicesReady >= 2){880				return this._cache.getCache(881					["getTag", section, category, tag],882					lang.hitch(this, this._getTag, section, category, tag)883				);884			}else{885				return this._getTag(section, category, tag);886			}887		},888		889		_getTag: function(section, category, tag){890			var query = this.getCategory(section, category);891			query = array.filter(query, function(service){892				return (this._itemHasTag(service, tag));893			}, this);894			895			return this._serviceSort(query);896		},897		898		_itemHasTag: function(item, tag){899			var found = false;900			if(!typeTest.isProperty(item, "data")){901				item = item.data;902			}903			904			if(typeTest.isString(item.data.tags)){905				item.data.tags = item.data.tags.split(";");906			}907			908			array.every(item.data.tags, function(cTag){909				if(typeTest.isEqual(cTag, tag)){910					found = true;911					return false;912				}913				return true;914			}, this);915			916			return found;917		},918		919		getTagsList: function(section, category){920			if(this._servicesReady >= 2){921				return this._cache.getCache(922					["getTagsList", section, category],923					lang.hitch(this, this._getTagsList, section, category)924				);925			}else{926				return this._getTagsList(section, category);927			}928		},929		930		_getTagsList: function(section, category){931			var services = this.getCategory(section, category);932			var tags = {};933			934			array.forEach(services, function(service){935				if(!typeTest.isProperty(service, "data")){936					service.data = service;937				}938				939				if(typeTest.isString(service.data.tags)){940					service.data.tags = service.data.tags.split(";");941				}942				array.forEach(service.data.tags, function(tag){943					if(!typeTest.isBlank(tag)){944						var cTags = tag.split(";");945						array.forEach(cTags, function(cTag){946							cTag = lang.trim(cTag);947							if(!typeTest.isBlank(cTag)){948								if(typeTest.isProperty(tags, cTag)){949									tags[cTag]++;950								}else{951									tags[cTag] = 1;952								}953							}954						},this);955					}956				}, this);957			}, this);958			959			return tags;960		},961		962		updateService: function(service){963			if(typeTest.isString(service)){964				if(service.length == 32){965					this._serviceIdsToUpdate.push(service);966					return true;967				}else{968					return false;969				}970			}else if(typeTest.isObject(service)){971				if(typeTest.isProperty(service, "id")){972					this._serviceIdsToUpdate.push(service.id.toLowerCase());973					return true;974				}else{975					return false;976				}977			}978				979			return false;980		},981		982		priorityUpdateService: function(service){983			if(typeTest.isString(service)){984				if(service.length == 32){985					this._callServicesUpdate2([service]);986					return true;987				}else{988					return false;989				}990			}else if(typeTest.isObject(service)){991				if(typeTest.isProperty(service, "id")){992					this._callServicesUpdate2([service.id.toLowerCase()]);993					return true;994				}else{995					return false;996				}997			}998				999			return false;1000		},1001		1002		getActivity: function(id){1003			var activity = this.activitiesStore.get(id);1004			if(!typeTest.isBlank(activity)){1005				if(typeTest.isProperty(activity, "type")){1006					if(activity.type == "activity"){1007						return activity;1008					}1009				}1010			}1011			1012			return null;1013		},1014		1015		getEvent: function(id){1016			var event = this.eventsStore.get(id);1017			if(!typeTest.isBlank(event)){1018				if(typeTest.isProperty(event, "type")){1019					if(event.type == "event"){1020						return event;1021					}1022				}1023			}1024			1025			return null;1026		},1027		1028		addToShortlist: function(id){1029			var shortlist = this.getShortlist();1030			1031			var found = false;1032			array.every(shortlist.services, function(serviceId){1033				if(typeTest.isEqual(serviceId, id)){1034					found = true;1035					return false;1036				}1037				return true;1038			}, this);1039			1040			if(!found){1041				if(typeTest.isProperty(shortlist, "services")){1042					shortlist.services.push(id);1043				}else{1044					shortlist.services = new Array(id);1045				}1046				this._updateShortlist(shortlist.services);1047			}1048		},1049		1050		_updateShortlist: function(ary){1051			var shortlist = this.getShortlist();1052			shortlist.services = ary;1053			this.settingsStore.put(shortlist);1054			topic.publish("/rcbc/pin/changeShortlist", shortlist);1055		},1056		1057		emptyShortlist: function(){1058			var shortlist = this._createBlankShortList();1059			this.settingsStore.get(shortlist);1060			topic.publish("/rcbc/pin/changeShortlist", shortlist);1061			1062			return shortlist;1063		},1064		1065		_createBlankShortList: function(){1066			return {1067				"type": "shortlist",1068				"id": "shortlist",1069				"services": new Array()1070			};1071		},1072		1073		getShortlist: function(){1074			var shortlist = this.settingsStore.get("shortlist");1075			if(typeTest.isBlank(shortlist)){1076				shortlist = this._createBlankShortList();1077				this.settingsStore.put(shortlist);1078				topic.publish("/rcbc/pin/changeShortlist", shortlist);1079			}1080			return this._sanitizeShortlist(shortlist);1081		},1082		1083		_sanitizeShortlist: function(shortlist){1084			var ids;1085			if(typeTest.isProperty(shortlist, "services")){1086				if(typeTest.isArray(shortlist.services)){1087					ids = shortlist.services;1088				}else{1089					return this._createBlankShortList();1090				}1091			}else{1092				if(typeTest.isArray(shortlist)){1093					ids = shortlist;1094				}else{1095					return this._createBlankShortList();1096				}1097			}1098			1099			var lookup = new Object();1100			array.forEach(ids, function(id){1101				if(/[A-Za-z0-9]{32,32}/.test(id)){1102					lookup[id.toLowerCase()] = true;1103				}1104			}, this);1105			1106			var ids = new Array();1107			for(var id in lookup){1108				ids.push(id);1109			}1110			1111			return {1112				"type": "shortlist",1113				"id": "shortlist",1114				"services": ids1115			};1116		},1117		1118		inShortlist: function(id){1119			var shortlist = this.getShortlist();1120			var found = false;1121			1122			if(typeTest.isProperty(shortlist, "services")){1123				array.every(shortlist.services, function(serviceId){1124					if(typeTest.isEqual(serviceId, id)){1125						found = true;1126						return false;1127					}1128					return true;1129				}, this);1130			}1131			1132			return found;1133		},1134		1135		removeFromShortlist: function(id){1136			var shortlist = this.getShortlist();1137			1138			var newList = new Array();1139			array.forEach(shortlist.services, function(serviceId){1140				if(!typeTest.isEqual(serviceId, id)){1141					newList.push(serviceId);1142				}1143			}, this);1144			1145			this._updateShortlist(newList);1146		},1147		1148		getVenue: function(id){1149			var venue = this.venuesStore.get(id);1150			1151			if(!typeTest.isBlank(venue)){1152				if(typeTest.isProperty(venue, "type")){1153					if(venue.type == "venue"){1154						return venue;1155					}1156				}1157			}1158			1159			return null;1160		},1161		1162		updateVenue: function(venue){1163			if(typeTest.isString(venue)){1164				if(venue.length == 32){1165					this._venueIdsToUpdate.push(venue);1166					return true;1167				}else{1168					return false;1169				}1170			}else if(typeTest.isObject(venue)){1171				if(typeTest.isProperty(venue, "id")){1172					this._venueIdsToUpdate.push(venue.id.toLowerCase());1173					return true;1174				}else{1175					return false;1176				}1177			}1178				1179			return false;1180		}1181	});1182	1183	return construct;...test-completions.js
Source:test-completions.js  
1/*******************************************************************************2 * Copyright (c) 2015 QNX Software Systems and others.3 * All rights reserved. This program and the accompanying materials4 * are made available under the terms of the Eclipse Public License v1.05 * which accompanies this distribution, and is available at6 * http://www.eclipse.org/legal/epl-v10.html7 *8 * Contributors:9 * QNX Software Systems - Initial API and implementation10 *******************************************************************************/11"use strict";1213var driver = require("./driver.js");14var test = driver.test;15var testCompletion = driver.testCompletion;16var assertCompletion = driver.assertCompletion;17var groupStart = driver.groupStart;18var groupEnd = driver.groupEnd;1920var group = exports.group = "Code Completion";21groupStart(group);2223// Local Directory Completions24testCompletion('My|', {25	start: { line: 0, ch: 0 },26	end: { line: 0, ch: 2 },27	isProperty: false,28	isObjectKey: false,29	completions: [{ name: "MyObject", type: "MyObject", origin: "MyObject.qml" }]30}, function (server) {31	server.addFile("MyObject.qml", "Button {}");32});3334testCompletion('import "./subdir/"\nSameDirTest {\n\t|\n}', {35	start: { line: 2, ch: 1 },36	end: { line: 2, ch: 1 },37	isProperty: false,38	isObjectKey: false,39	completions: [40		{ name: "obj", type: "?", origin: "subdir/Button.qml" },41		{ name: "Button", type: "Button", origin: "subdir/Button.qml" },42		{ name: "SameDirTest", type: "SameDirTest", origin: "subdir/SameDirTest.qml" }43	]44}, function (server) {45	server.addFile("subdir/SameDirTest.qml", "Button {}");46	server.addFile("subdir/Button.qml", "QtObject {property var obj}");47});4849testCompletion('MyObject {\n\t|\n}', {50	start: { line: 1, ch: 1 },51	end: { line: 1, ch: 1 },52	isProperty: false,53	isObjectKey: false,54	completions: [55		{ name: "width", type: "number", origin: "MyObject.qml" },56		{ name: "MyObject", type: "MyObject", origin: "MyObject.qml" }57	]58}, function (server) {59	server.addFile("MyObject.qml", "Button {\n\tproperty int width\n}");60});6162testCompletion('MyObject {\n\tid: obj\n\ts: obj.|\n}', {63	start: { line: 2, ch: 8 },64	end: { line: 2, ch: 8 },65	isProperty: true,66	isObjectKey: false,67	completions: [{ name: "width", type: "number", origin: "MyObject.qml" }]68}, function (server) {69	server.addFile("MyObject.qml", "Button {\n\tproperty int width\n}");70});7172testCompletion('Button {\n\t|\n}', {73	start: { line: 1, ch: 1 },74	end: { line: 1, ch: 1 },75	isProperty: false,76	isObjectKey: false,77	completions: [78		{ name: "onClicked", type: "Signal Handler", origin: "Button.qml" },79		{ name: "Button", type: "Button", origin: "Button.qml" }80	]81}, function (server) {82	server.addFile("Button.qml", "QtObject {\n\signal clicked(int mouseX, int mouseY)\n}");83});8485testCompletion('CButton {\n\t|\n}', {86	start: { line: 1, ch: 1 },87	end: { line: 1, ch: 1 },88	isProperty: false,89	isObjectKey: false,90	completions: [91		{ name: "height", type: "number", origin: "Button.qml" },92		{ name: "numClicks", type: "number", origin: "CButton.qml" },93		{ name: "text", type: "string", origin: "Button.qml" },94		{ name: "width", type: "number", origin: "Button.qml" },95		{ name: "Button", type: "Button", origin: "Button.qml" },96		{ name: "CButton", type: "CButton", origin: "CButton.qml" }97	]98}, function (server) {99	server.addFile("CButton.qml", "Button {\n\tproperty int numClicks\n}");100	server.addFile("Button.qml", "QtObject {\n\tproperty string text\n\tproperty int width\n\tproperty int height\n}");101});102103testCompletion('CButton {\n\tid:btn\n\ts: btn.|\n}', {104	start: { line: 2, ch: 8 },105	end: { line: 2, ch: 8 },106	isProperty: true,107	isObjectKey: false,108	completions: [109		{ name: "height", type: "number", origin: "Button.qml" },110		{ name: "numClicks", type: "number", origin: "CButton.qml" },111		{ name: "text", type: "string", origin: "Button.qml" },112		{ name: "width", type: "number", origin: "Button.qml" }113	]114}, function (server) {115	server.addFile("CButton.qml", "Button {\n\tproperty int numClicks\n}");116	server.addFile("Button.qml", "QtObject {\n\tproperty string text\n\tproperty int width\n\tproperty int height\n}");117});118119// Directory Import Completions120testCompletion('NotVisible {\n\t|\n}', {121	start: { line: 1, ch: 1 },122	end: { line: 1, ch: 1 },123	isProperty: false,124	isObjectKey: false,125	completions: []126}, function (server) {127	server.addFile("subdir/NotVisible.qml", "QtObject {\n\signal clicked(int mouseX, int mouseY)\n}");128});129130testCompletion('import "./subdir/"\nButton {\n\t|\n}', {131	start: { line: 2, ch: 1 },132	end: { line: 2, ch: 1 },133	isProperty: false,134	isObjectKey: false,135	completions: [136		{ name: "onClicked", type: "Signal Handler", origin: "subdir/Button.qml" },137		{ name: "Button", type: "Button", origin: "subdir/Button.qml" }138	]139}, function (server) {140	server.addFile("subdir/Button.qml", "QtObject {\n\signal clicked(int mouseX, int mouseY)\n}");141});142143testCompletion('import "./subdir/" as Controls\nControls.Button {\n\t|\n}', {144	start: { line: 2, ch: 1 },145	end: { line: 2, ch: 1 },146	isProperty: false,147	isObjectKey: false,148	completions: [149		{ name: "onClicked", type: "Signal Handler", origin: "subdir/Button.qml" },150		{ name: "Controls", type: "Controls", origin: "main.qml" }151	]152}, function (server) {153	server.addFile("subdir/Button.qml", "QtObject {\n\signal clicked(int mouseX, int mouseY)\n}");154});155156testCompletion('import "./subdir/" as Controls\nControls.|', {157	start: { line: 1, ch: 9 },158	end: { line: 1, ch: 9 },159	isProperty: false,160	isObjectKey: false,161	completions: [162		{ name: "Button", type: "Button", origin: "subdir/Button.qml" }163	]164}, function (server) {165	server.addFile("subdir/Button.qml", "QtObject {\n\signal clicked(int mouseX, int mouseY)\n}");166});167168testCompletion('import "./subdir/" as Controls\nControls.|.', {169	start: { line: 1, ch: 9 },170	end: { line: 1, ch: 9 },171	isProperty: false,172	isObjectKey: false,173	completions: [174		{ name: "Button", type: "Button", origin: "subdir/Button.qml" }175	]176}, function (server) {177	server.addFile("subdir/Button.qml", "QtObject {\n\signal clicked(int mouseX, int mouseY)\n}");178});179180testCompletion('import "./subdir/" as Controls\nControls..|', {181	start: { line: 1, ch: 10 },182	end: { line: 1, ch: 10 },183	isProperty: false,184	isObjectKey: false,185	completions: []186}, function (server) {187	server.addFile("subdir/Button.qml", "QtObject {\n\signal clicked(int mouseX, int mouseY)\n}");188});189190test("{Add File After Import}", function (server, callback, name) {191	var failed;192	assertCompletion(server, "", {193		start: { line: 0, ch: 0 },194		end: { line: 0, ch: 0 },195		isProperty: false,196		isObjectKey: false,197		completions: []198	}, 0, function (mis) {199		failed = mis;200	});201	if (failed) {202		return callback("fail", name, "- failed on initial file " + failed);203	}204	server.addFile("MyObject.qml", "QtObject {\n\tproperty var test\n}");205	assertCompletion(server, "", {206		start: { line: 0, ch: 0 },207		end: { line: 0, ch: 0 },208		isProperty: false,209		isObjectKey: false,210		completions: [{ name: "MyObject", type: "MyObject", origin: "MyObject.qml" }]211	}, 0, function (mis) {212		failed = mis;213	});214	if (failed) {215		return callback("fail", name, "- failed after adding file " + failed);216	}217	return callback("ok", name);218});219220// Cyclic Dependency Completions221testCompletion('Cyclic {\n\t|\n}', {222	start: { line: 1, ch: 1 },223	end: { line: 1, ch: 1 },224	isProperty: false,225	isObjectKey: false,226	completions: [227		{ name: "test", type: "?", origin: "Cyclic.qml" },228		{ name: "Cyclic", type: "Cyclic", origin: "Cyclic.qml" }229	]230}, function (server) {231	server.addFile("Cyclic.qml", "Cyclic {\n\property var test\n}");232});233234testCompletion('Cyclic2 {\n\t|\n}', {235	start: { line: 1, ch: 1 },236	end: { line: 1, ch: 1 },237	isProperty: false,238	isObjectKey: false,239	completions: [240		{ name: "test1", type: "?", origin: "Cyclic2.qml" },241		{ name: "test2", type: "?", origin: "OtherCyclic.qml" },242		{ name: "Cyclic2", type: "Cyclic2", origin: "Cyclic2.qml" },243		{ name: "OtherCyclic", type: "OtherCyclic", origin: "OtherCyclic.qml" }244	]245}, function (server) {246	server.addFile("Cyclic2.qml", "OtherCyclic {\n\property var test1\n}");247	server.addFile("OtherCyclic.qml", "Cyclic2 {\n\property var test2\n}");248});249250testCompletion('OtherCyclic {\n\t|\n}', {251	start: { line: 1, ch: 1 },252	end: { line: 1, ch: 1 },253	isProperty: false,254	isObjectKey: false,255	completions: [256		{ name: "test2", type: "?", origin: "OtherCyclic.qml" },257		{ name: "Cyclic", type: "Cyclic", origin: "Cyclic.qml" },258		{ name: "OtherCyclic", type: "OtherCyclic", origin: "OtherCyclic.qml" }259	]260}, function (server) {261	server.addFile("Cyclic.qml", "OtherCyclic {\n\property var test1\n}");262	server.addFile("OtherCyclic.qml", "Cyclic {\n\property var test2\n}");263});264265// QML Object Property Completions266testCompletion("Window {\n\tproperty int height\n\the|\n}", {267	start: { line: 2, ch: 1 },268	end: { line: 2, ch: 3 },269	isProperty: false,270	isObjectKey: false,271	completions: [{ name: "height", type: "number", origin: "main.qml" }]272});273274testCompletion("Window {\n\tproperty int height\n\tproperty int width\n\tproperty string text\n\t|\n}", {275	start: { line: 4, ch: 1 },276	end: { line: 4, ch: 1 },277	isProperty: false,278	isObjectKey: false,279	completions: [280		{ name: "height", type: "number", origin: "main.qml" },281		{ name: "text", type: "string", origin: "main.qml" },282		{ name: "width", type: "number", origin: "main.qml" }283	]284});285286testCompletion("Window {\n\tproperty int height\n\tObject {\n\t\t|\n\t}\n}", {287	start: { line: 3, ch: 2 },288	end: { line: 3, ch: 2 },289	isProperty: false,290	isObjectKey: false,291	completions: []292});293294testCompletion("Window {\n\tproperty var prop\n\tfunction test() {\n\t\t|\n\t}\n}", {295	start: { line: 3, ch: 2 },296	end: { line: 3, ch: 2 },297	isProperty: false,298	isObjectKey: false,299	completions: [300		{ name: "prop", type: "?", origin: "main.qml" },301		{ name: "test", type: "fn()", origin: "main.qml" }302	]303}, function (server) { server.jsDefs = []; });304305// QML ID Property Completions306testCompletion("Window {\n\tid: btn\n\t|\n}", {307	start: { line: 2, ch: 1 },308	end: { line: 2, ch: 1 },309	isProperty: false,310	isObjectKey: false,311	completions: []312});313314testCompletion("Window {\n\tButton {\n\t\tid: btn\n\t\tproperty int height\n\t}\n\ttest: btn.|\n}", {315	start: { line: 5, ch: 11 },316	end: { line: 5, ch: 11 },317	isProperty: true,318	isObjectKey: false,319	completions: [{ name: "height", type: "number", origin: "main.qml" }]320}, function (server) { server.jsDefs = []; });321322testCompletion("Window {\n\tproperty var btn\n\tButton {\n\t\tid: btn\n\t\tproperty int height\n\t}\n\ttest: btn.|\n}", {323	start: { line: 6, ch: 11 },324	end: { line: 6, ch: 11 },325	isProperty: true,326	isObjectKey: false,327	completions: [{ name: "height", type: "number", origin: "main.qml" }]328}, function (server) { server.jsDefs = []; });329330testCompletion("Window {\n\tButton {\n\t\tproperty var id\n\t\tid: btn\n\t}\n\ts: bt|\n}", {331	start: { line: 5, ch: 4 },332	end: { line: 5, ch: 6 },333	isProperty: false,334	isObjectKey: false,335	completions: [{ name: "btn", type: "Button", origin: "main.qml" }]336}, function (server) { server.jsDefs = []; });337338testCompletion("Window {\n\tButton {\n\t\tproperty var id\n\t\tid: btn\n\t\ts: i|\n\t}\n}", {339	start: { line: 4, ch: 5 },340	end: { line: 4, ch: 6 },341	isProperty: false,342	isObjectKey: false,343	completions: [{ name: "id", type: "?", origin: "main.qml" }]344}, function (server) { server.jsDefs = []; });345346testCompletion("Window {\n\tButton {\n\t\tproperty var id: 34\n\t\tid: btn\n\t\ts: i|\n\t}\n}", {347	start: { line: 4, ch: 5 },348	end: { line: 4, ch: 6 },349	isProperty: false,350	isObjectKey: false,351	completions: [{ name: "id", type: "number", origin: "main.qml" }]352}, function (server) { server.jsDefs = []; });353354testCompletion("Window {\n\tButton {\n\t\tproperty string id\n\t\tid: btn\n\t\ts: i|\n\t}\n}", {355	start: { line: 4, ch: 5 },356	end: { line: 4, ch: 6 },357	isProperty: false,358	isObjectKey: false,359	completions: [{ name: "id", type: "string", origin: "main.qml" }]360}, function (server) { server.jsDefs = []; });361362testCompletion("Window {\n\tButton {\n\t\tproperty var id\n\t\ts: i|\n\t}\n}", {363	start: { line: 3, ch: 5 },364	end: { line: 3, ch: 6 },365	isProperty: false,366	isObjectKey: false,367	completions: [{ name: "id", type: "?", origin: "main.qml" }]368}, function (server) { server.jsDefs = []; });369370testCompletion("Window {\n\tButton {\n\t\tproperty var id: 34\n\t\ts: i|\n\t}\n}", {371	start: { line: 3, ch: 5 },372	end: { line: 3, ch: 6 },373	isProperty: false,374	isObjectKey: false,375	completions: [{ name: "id", type: "number", origin: "main.qml" }]376}, function (server) { server.jsDefs = []; });377378testCompletion("Window {\n\tButton {\n\t\tproperty string id\n\t\ts: i|\n\t}\n}", {379	start: { line: 3, ch: 5 },380	end: { line: 3, ch: 6 },381	isProperty: false,382	isObjectKey: false,383	completions: [{ name: "id", type: "string", origin: "main.qml" }]384}, function (server) { server.jsDefs = []; });385386testCompletion("Window {\n\tid: wind\n\tfunction test() {\n\t\t|\n\t}\n}", {387	start: { line: 3, ch: 2 },388	end: { line: 3, ch: 2 },389	isProperty: false,390	isObjectKey: false,391	completions: [392		{ name: "test", type: "fn()", origin: "main.qml" },393		{ name: "wind", type: "Window", origin: "main.qml" }394	]395}, function (server) { server.jsDefs = []; });396397// JavaScript Completions398testCompletion("Window {\n\tproperty var test: |\n}", {399	start: { line: 1, ch: 20 },400	end: { line: 1, ch: 20 },401	isProperty: false,402	isObjectKey: false,403	completions: [404		{ name: "decodeURI", type: "fn(uri: string) -> string", origin: "ecma5" },405		{ name: "decodeURIComponent", type: "fn(uri: string) -> string", origin: "ecma5" },406		{ name: "encodeURI", type: "fn(uri: string) -> string", origin: "ecma5" },407		{ name: "encodeURIComponent", type: "fn(uri: string) -> string", origin: "ecma5" },408		{ name: "eval", type: "fn(code: string)", origin: "ecma5" },409		{ name: "isFinite", type: "fn(value: number) -> bool", origin: "ecma5" },410		{ name: "isNaN", type: "fn(value: number) -> bool", origin: "ecma5" },411		{ name: "parseFloat", type: "fn(string: string) -> number", origin: "ecma5" },412		{ name: "parseInt", type: "fn(string: string, radix?: number) -> number", origin: "ecma5" },413		{ name: "test", type: "?", origin: "main.qml" },414		{ name: "undefined", type: "?", origin: "ecma5" },415		{ name: "Array", type: "fn(size: number)", origin: "ecma5" },416		{ name: "Boolean", type: "fn(value: ?) -> bool", origin: "ecma5" },417		{ name: "Date", type: "fn(ms: number)", origin: "ecma5" },418		{ name: "Error", type: "fn(message: string)", origin: "ecma5" },419		{ name: "EvalError", type: "fn(message: string)", origin: "ecma5" },420		{ name: "Function", type: "fn(body: string) -> fn()", origin: "ecma5" },421		{ name: "Infinity", type: "number", origin: "ecma5" },422		{ name: "JSON", type: "JSON", origin: "ecma5" },423		{ name: "Math", type: "Math", origin: "ecma5" },424		{ name: "NaN", type: "number", origin: "ecma5" },425		{ name: "Number", type: "fn(value: ?) -> number", origin: "ecma5" },426		{ name: "Object", type: "fn()", origin: "ecma5" },427		{ name: "RangeError", type: "fn(message: string)", origin: "ecma5" },428		{ name: "ReferenceError", type: "fn(message: string)", origin: "ecma5" },429		{ name: "RegExp", type: "fn(source: string, flags?: string)", origin: "ecma5" },430		{ name: "String", type: "fn(value: ?) -> string", origin: "ecma5" },431		{ name: "SyntaxError", type: "fn(message: string)", origin: "ecma5" },432		{ name: "TypeError", type: "fn(message: string)", origin: "ecma5" },433		{ name: "URIError", type: "fn(message: string)", origin: "ecma5" }434	]435});436437testCompletion("Window {\n\ttest: |\n}", {438	start: { line: 1, ch: 7 },439	end: { line: 1, ch: 7 },440	isProperty: false,441	isObjectKey: false,442	completions: [443		{ name: "decodeURI", type: "fn(uri: string) -> string", origin: "ecma5" },444		{ name: "decodeURIComponent", type: "fn(uri: string) -> string", origin: "ecma5" },445		{ name: "encodeURI", type: "fn(uri: string) -> string", origin: "ecma5" },446		{ name: "encodeURIComponent", type: "fn(uri: string) -> string", origin: "ecma5" },447		{ name: "eval", type: "fn(code: string)", origin: "ecma5" },448		{ name: "isFinite", type: "fn(value: number) -> bool", origin: "ecma5" },449		{ name: "isNaN", type: "fn(value: number) -> bool", origin: "ecma5" },450		{ name: "parseFloat", type: "fn(string: string) -> number", origin: "ecma5" },451		{ name: "parseInt", type: "fn(string: string, radix?: number) -> number", origin: "ecma5" },452		{ name: "undefined", type: "?", origin: "ecma5" },453		{ name: "Array", type: "fn(size: number)", origin: "ecma5" },454		{ name: "Boolean", type: "fn(value: ?) -> bool", origin: "ecma5" },455		{ name: "Date", type: "fn(ms: number)", origin: "ecma5" },456		{ name: "Error", type: "fn(message: string)", origin: "ecma5" },457		{ name: "EvalError", type: "fn(message: string)", origin: "ecma5" },458		{ name: "Function", type: "fn(body: string) -> fn()", origin: "ecma5" },459		{ name: "Infinity", type: "number", origin: "ecma5" },460		{ name: "JSON", type: "JSON", origin: "ecma5" },461		{ name: "Math", type: "Math", origin: "ecma5" },462		{ name: "NaN", type: "number", origin: "ecma5" },463		{ name: "Number", type: "fn(value: ?) -> number", origin: "ecma5" },464		{ name: "Object", type: "fn()", origin: "ecma5" },465		{ name: "RangeError", type: "fn(message: string)", origin: "ecma5" },466		{ name: "ReferenceError", type: "fn(message: string)", origin: "ecma5" },467		{ name: "RegExp", type: "fn(source: string, flags?: string)", origin: "ecma5" },468		{ name: "String", type: "fn(value: ?) -> string", origin: "ecma5" },469		{ name: "SyntaxError", type: "fn(message: string)", origin: "ecma5" },470		{ name: "TypeError", type: "fn(message: string)", origin: "ecma5" },471		{ name: "URIError", type: "fn(message: string)", origin: "ecma5" }472	]473});474475testCompletion("Window {\n\ttest: {\n\t\t|\n\t}\n}", {476	start: { line: 2, ch: 2 },477	end: { line: 2, ch: 2 },478	isProperty: false,479	isObjectKey: false,480	completions: [481		{ name: "decodeURI", type: "fn(uri: string) -> string", origin: "ecma5" },482		{ name: "decodeURIComponent", type: "fn(uri: string) -> string", origin: "ecma5" },483		{ name: "encodeURI", type: "fn(uri: string) -> string", origin: "ecma5" },484		{ name: "encodeURIComponent", type: "fn(uri: string) -> string", origin: "ecma5" },485		{ name: "eval", type: "fn(code: string)", origin: "ecma5" },486		{ name: "isFinite", type: "fn(value: number) -> bool", origin: "ecma5" },487		{ name: "isNaN", type: "fn(value: number) -> bool", origin: "ecma5" },488		{ name: "parseFloat", type: "fn(string: string) -> number", origin: "ecma5" },489		{ name: "parseInt", type: "fn(string: string, radix?: number) -> number", origin: "ecma5" },490		{ name: "undefined", type: "?", origin: "ecma5" },491		{ name: "Array", type: "fn(size: number)", origin: "ecma5" },492		{ name: "Boolean", type: "fn(value: ?) -> bool", origin: "ecma5" },493		{ name: "Date", type: "fn(ms: number)", origin: "ecma5" },494		{ name: "Error", type: "fn(message: string)", origin: "ecma5" },495		{ name: "EvalError", type: "fn(message: string)", origin: "ecma5" },496		{ name: "Function", type: "fn(body: string) -> fn()", origin: "ecma5" },497		{ name: "Infinity", type: "number", origin: "ecma5" },498		{ name: "JSON", type: "JSON", origin: "ecma5" },499		{ name: "Math", type: "Math", origin: "ecma5" },500		{ name: "NaN", type: "number", origin: "ecma5" },501		{ name: "Number", type: "fn(value: ?) -> number", origin: "ecma5" },502		{ name: "Object", type: "fn()", origin: "ecma5" },503		{ name: "RangeError", type: "fn(message: string)", origin: "ecma5" },504		{ name: "ReferenceError", type: "fn(message: string)", origin: "ecma5" },505		{ name: "RegExp", type: "fn(source: string, flags?: string)", origin: "ecma5" },506		{ name: "String", type: "fn(value: ?) -> string", origin: "ecma5" },507		{ name: "SyntaxError", type: "fn(message: string)", origin: "ecma5" },508		{ name: "TypeError", type: "fn(message: string)", origin: "ecma5" },509		{ name: "URIError", type: "fn(message: string)", origin: "ecma5" }510	]511});512513testCompletion("Window {\n\tfunction test() {\n\t\t|\n\t}\n}", {514	start: { line: 2, ch: 2 },515	end: { line: 2, ch: 2 },516	isProperty: false,517	isObjectKey: false,518	completions: [519		{ name: "decodeURI", type: "fn(uri: string) -> string", origin: "ecma5" },520		{ name: "decodeURIComponent", type: "fn(uri: string) -> string", origin: "ecma5" },521		{ name: "encodeURI", type: "fn(uri: string) -> string", origin: "ecma5" },522		{ name: "encodeURIComponent", type: "fn(uri: string) -> string", origin: "ecma5" },523		{ name: "eval", type: "fn(code: string)", origin: "ecma5" },524		{ name: "isFinite", type: "fn(value: number) -> bool", origin: "ecma5" },525		{ name: "isNaN", type: "fn(value: number) -> bool", origin: "ecma5" },526		{ name: "parseFloat", type: "fn(string: string) -> number", origin: "ecma5" },527		{ name: "parseInt", type: "fn(string: string, radix?: number) -> number", origin: "ecma5" },528		{ name: "test", type: "fn()", origin: "main.qml" },529		{ name: "undefined", type: "?", origin: "ecma5" },530		{ name: "Array", type: "fn(size: number)", origin: "ecma5" },531		{ name: "Boolean", type: "fn(value: ?) -> bool", origin: "ecma5" },532		{ name: "Date", type: "fn(ms: number)", origin: "ecma5" },533		{ name: "Error", type: "fn(message: string)", origin: "ecma5" },534		{ name: "EvalError", type: "fn(message: string)", origin: "ecma5" },535		{ name: "Function", type: "fn(body: string) -> fn()", origin: "ecma5" },536		{ name: "Infinity", type: "number", origin: "ecma5" },537		{ name: "JSON", type: "JSON", origin: "ecma5" },538		{ name: "Math", type: "Math", origin: "ecma5" },539		{ name: "NaN", type: "number", origin: "ecma5" },540		{ name: "Number", type: "fn(value: ?) -> number", origin: "ecma5" },541		{ name: "Object", type: "fn()", origin: "ecma5" },542		{ name: "RangeError", type: "fn(message: string)", origin: "ecma5" },543		{ name: "ReferenceError", type: "fn(message: string)", origin: "ecma5" },544		{ name: "RegExp", type: "fn(source: string, flags?: string)", origin: "ecma5" },545		{ name: "String", type: "fn(value: ?) -> string", origin: "ecma5" },546		{ name: "SyntaxError", type: "fn(message: string)", origin: "ecma5" },547		{ name: "TypeError", type: "fn(message: string)", origin: "ecma5" },548		{ name: "URIError", type: "fn(message: string)", origin: "ecma5" }549	]550});551552// Signal and Signal Handler Completions553testCompletion("Window {\n\tsignal clicked(int mouseX, int mouseY)\n\t|\n}", {554	start: { line: 2, ch: 1 },555	end: { line: 2, ch: 1 },556	isProperty: false,557	isObjectKey: false,558	completions: [559		{ name: "onClicked", type: "Signal Handler", origin: "main.qml" }560	]561});562563testCompletion("Window {\n\tsignal clicked(int mouseX, int mouseY)\n\tButton {\n\t\t|\n\t}\n}", {564	start: { line: 3, ch: 2 },565	end: { line: 3, ch: 2 },566	isProperty: false,567	isObjectKey: false,568	completions: []569});570571testCompletion("Window {\n\tsignal clicked(int mouseX, int mouseY)\n\ts: |\n}", {572	start: { line: 2, ch: 4 },573	end: { line: 2, ch: 4 },574	isProperty: false,575	isObjectKey: false,576	completions: [577		{ name: "clicked", type: "fn(mouseX: number, mouseY: number)", origin: "main.qml" },578		{ name: "onClicked", type: "Signal Handler", origin: "main.qml" }579	]580}, function (server) { server.jsDefs = []; });581582testCompletion("Window {\n\tsignal error(string msg, boolean flag)\n\ts: |\n}", {583	start: { line: 2, ch: 4 },584	end: { line: 2, ch: 4 },585	isProperty: false,586	isObjectKey: false,587	completions: [588		{ name: "error", type: "fn(msg: string, flag: bool)", origin: "main.qml" },589		{ name: "onError", type: "Signal Handler", origin: "main.qml" }590	]591}, function (server) { server.jsDefs = []; });592593testCompletion("Window {\n\tid: wind\n\tsignal error(string msg, boolean flag)\n\ts: wind.|\n}", {594	start: { line: 3, ch: 9 },595	end: { line: 3, ch: 9 },596	isProperty: true,597	isObjectKey: false,598	completions: [599		{ name: "error", type: "fn(msg: string, flag: bool)", origin: "main.qml" },600		{ name: "onError", type: "Signal Handler", origin: "main.qml" }601	]602}, function (server) { server.jsDefs = []; });603604testCompletion("Window {\n\tsignal error(string msg, boolean flag)\n\tonError: |\n}", {605	start: { line: 2, ch: 10 },606	end: { line: 2, ch: 10 },607	isProperty: false,608	isObjectKey: false,609	completions: [610		{ name: "error", type: "fn(msg: string, flag: bool)", origin: "main.qml" },611		{ name: "flag", type: "bool", origin: "main.qml" },612		{ name: "msg", type: "string", origin: "main.qml" },613		{ name: "onError", type: "Signal Handler", origin: "main.qml" }614	]615}, function (server) { server.jsDefs = []; });616617testCompletion("Window {\n\tsignal error(string msg, boolean flag)\n\tonError: {\n\t\t|\n\t}\n}", {618	start: { line: 3, ch: 2 },619	end: { line: 3, ch: 2 },620	isProperty: false,621	isObjectKey: false,622	completions: [623		{ name: "error", type: "fn(msg: string, flag: bool)", origin: "main.qml" },624		{ name: "flag", type: "bool", origin: "main.qml" },625		{ name: "msg", type: "string", origin: "main.qml" },626		{ name: "onError", type: "Signal Handler", origin: "main.qml" }627	]628}, function (server) { server.jsDefs = []; });629630testCompletion("Window {\n\tproperty int msg\n\tsignal error(string msg, boolean flag)\n\tonError: {\n\t\t|\n\t}\n}", {631	start: { line: 4, ch: 2 },632	end: { line: 4, ch: 2 },633	isProperty: false,634	isObjectKey: false,635	completions: [636		{ name: "error", type: "fn(msg: string, flag: bool)", origin: "main.qml" },637		{ name: "flag", type: "bool", origin: "main.qml" },638		{ name: "msg", type: "string", origin: "main.qml" },639		{ name: "onError", type: "Signal Handler", origin: "main.qml" }640	]641}, function (server) { server.jsDefs = []; });642643// Function Declarations644testCompletion("Window {\n\tfunction test() {}\n\t|\n}", {645	start: { line: 2, ch: 1 },646	end: { line: 2, ch: 1 },647	isProperty: false,648	isObjectKey: false,649	completions: []650});651652testCompletion("Window {\n\tfunction test(a, b, c) {\n\t\t|\n\t}\n}", {653	start: { line: 2, ch: 2 },654	end: { line: 2, ch: 2 },655	isProperty: false,656	isObjectKey: false,657	completions: [658		{ name: "a", type: "?", origin: "main.qml" },659		{ name: "b", type: "?", origin: "main.qml" },660		{ name: "c", type: "?", origin: "main.qml" },661		{ name: "test", type: "fn(a: ?, b: ?, c: ?)", origin: "main.qml" }662	]663}, function (server) { server.jsDefs = []; });664665testCompletion("Window {\n\tfunction test(a) {\n\t\ta = 3\n\t\t|\n\t}\n}", {666	start: { line: 3, ch: 2 },667	end: { line: 3, ch: 2 },668	isProperty: false,669	isObjectKey: false,670	completions: [671		{ name: "a", type: "number", origin: "main.qml" },672		{ name: "test", type: "fn(a: number)", origin: "main.qml" }673	]674}, function (server) { server.jsDefs = []; });675676testCompletion('Window {\n\tfunction test(a) {\n\t\ttest("something")\n\t\t|\n\t}\n}', {677	start: { line: 3, ch: 2 },678	end: { line: 3, ch: 2 },679	isProperty: false,680	isObjectKey: false,681	completions: [682		{ name: "a", type: "string", origin: "main.qml" },683		{ name: "test", type: "fn(a: string)", origin: "main.qml" }684	]685}, function (server) { server.jsDefs = []; });686687testCompletion('Window {\n\tfunction test(a) {\n\t\t|\n\t\treturn 7\n\t}\n}', {688	start: { line: 2, ch: 2 },689	end: { line: 2, ch: 2 },690	isProperty: false,691	isObjectKey: false,692	completions: [693		{ name: "a", type: "?", origin: "main.qml" },694		{ name: "test", type: "fn(a: ?) -> number", origin: "main.qml" }695	]696}, function (server) { server.jsDefs = []; });697698// TODO: Uncomment once this is fixed.  The find defs version of this test does find the right definition699//       so it seems the problem is related to Tern and not the QML plugin.700//testCompletion('Window {\n\tproperty int a\n\tfunction test(a) {\n\t\t|\n\t}\n}', {701//	start: { line: 3, ch: 2 },702//	end: { line: 3, ch: 2 },703//	isProperty: false,704//	isObjectKey: false,705//	completions: [706//		{ name: "a", type: "?", origin: "main.qml" },707//		{ name: "test", type: "fn()", origin: "main.qml" }708//	]709//}, function (server) { server.jsDefs = []; });710
...get-user-infos.config.js
Source:get-user-infos.config.js  
1(function () {2    'use strict';3    angular.module('com.example.samplelibrary.view-components.get-user-infos')4        .config(function (rxViewComponentProvider) {5            rxViewComponentProvider.registerComponent([6                {7                    name: 'Get User Infos',8                    group: 'Sample Library Components',9                    icon: 'user',10                    type: 'com-example-samplelibrary-get-user-infos',11                    designType: 'com-example-samplelibrary-get-user-infos-design',12                    bundleId: 'com.example.samplelibrary',13                    propertiesByName: [14                        {15                            name: 'isBusinessAnalyst',16                            type: 'boolean',17                            isProperty: true18                        },19                        {20                            name: 'isTenantAdmin',21                            type: 'boolean',22                            isProperty: true23                        },24                        {25                            name: 'isSaasAdmin',26                            type: 'boolean',27                            isProperty: true28                        },29                        {30                            name: 'isAdministrator',31                            type: 'boolean',32                            isProperty: true33                        },34                        {35                            name: 'developerMode',36                            type: 'boolean',37                            isProperty: true38                        },39                        {40                            name: 'isDevelopmentEnvironment',41                            type: 'string',42                            isProperty: true43                        },44                        {45                            name: 'isDevelopmentAllowed',46                            type: 'boolean',47                            isProperty: true48                        },49                        {50                            name: 'isProductionEnvironment',51                            type: 'boolean',52                            isProperty: true53                        },54                        {55                            name: 'loginId',56                            type: 'string',57                            isProperty: true58                        },59                        {60                            name: 'name',61                            type: 'string',62                            isProperty: true63                        },64                        {65                            name: 'serverInstanceType',66                            type: 'string',67                            isProperty: true68                        },69                        {70                            name: 'developerId',71                            type: 'string',72                            isProperty: true73                        },74                        {75                            name: 'fullName',76                            type: 'string',77                            isProperty: true78                        },79                        {80                            name: 'preferredLocale',81                            type: 'string',82                            isProperty: true83                        },84                        {85                            name: 'preferredUserLocale',86                            type: 'string',87                            isProperty: true88                        },89                        {90                            name: 'personInstanceId',91                            type: 'string',92                            isProperty: true93                        },94                        {95                            name: 'userId',96                            type: 'string',97                            isProperty: true98                        }99                    ]100                }101            ]);102        });...test_yui_completion.js
Source:test_yui_completion.js  
1var util = require("./util");23exports['test YUI completion'] = function() {4  util.assertCompletion("Y", {5    "start":{"line":0,"ch":0},6	"end":{"line":0,"ch":1},7    "isProperty":false,8    "isObjectKey":false,9    "completions":[{"name":"YUI","type":"fn(config?: yui.config) -> yui.YUI", "origin":"yui3"},10                   {"name":"YUI_config","type":"yui.config","origin":"yui3"}]11  });12}1314exports['test AUI completion'] = function() {15  util.assertCompletion("AU", {16    "start":{"line":0,"ch":0},17    "end":{"line":0,"ch":2},18    "isProperty":false,19    "isObjectKey":false,20    "completions":[{"name":"AUI","type":"fn(config?: yui.config) -> yui.YUI","origin":"aui1.5.x"}]21  });22}2324exports['test YUI().use completion'] = function() {25  util.assertCompletion("YUI().u", {26    "start":{"line":0,"ch":6},27    "end":{"line":0,"ch":7},28    "isProperty":true,29    "isObjectKey":false,30    "completions":[{"name":"unsubscribe","type":"fn()","origin":"yui3"},31                   {"name":"unsubscribeAll","type":"fn(type: string)","origin":"yui3"},32                   {"name":"use","type":"fn(modules: string, callback?: fn(Y: ?))","origin":"yui3"}]33    });34}3536exports['test AUI().use completion'] = function() {37  util.assertCompletion("AUI().u", {38    "start":{"line":0,"ch":6},39    "end":{"line":0,"ch":7},40    "isProperty":true,41    "isObjectKey":false,42    "completions":[{"name":"unsubscribe","type":"fn()","origin":"yui3"},43                   {"name":"unsubscribeAll","type":"fn(type: string)","origin":"yui3"},44                   {"name":"use","type":"fn(modules: string, callback?: fn(Y: ?))","origin":"yui3"}]45    });46}4748exports['test Y.one completion'] = function() {49  util.assertCompletion("YUI().use('', function(Y) { Y.one", {50    "start":{"line":0,"ch":30},51    "end":{"line":0,"ch":33},52    "isProperty":true,53    "isObjectKey":false,54    "completions":[{"name":"one","type":"fn(node: string|Element) -> node.Node",55    "origin":"yui3"}]56  });57}5859exports['test !proto completion'] = function() {60  // check methods of Anim.anim61  util.assertCompletion("YUI().use('', function(Y) { var anim = new Y.Anim(); anim.p", {62      "start":{"line":0,"ch":58},63      "end":{"line":0,"ch":59},64      "isProperty":true,65      "isObjectKey":false,66      "completions":[{"name":"parseType","type":"fn(type: string, pre?: string) -> [?]","origin":"yui3"},67                     {"name":"pause","type":"fn()", "origin":"yui3"},68                     {"name":"propertyIsEnumerable","type":"fn(prop: string) -> bool", "origin":"ecma5"},69                     {"name":"publish","type":"fn(type: string, opts: {}) -> event_custom.CustomEvent", "origin":"yui3"}70                    ]71  });72  //  Anim.anim extends base.Base73  util.assertCompletion("YUI().use('', function(Y) { var anim = new Y.Anim(); anim.unpl", {74      "start":{"line":0,"ch":58},75      "end":{"line":0,"ch":62},76      "isProperty":true,77      "isObjectKey":false,78      "completions":[{"name":"unplug","type":"fn()", "origin":"yui3"}79                    ]80  });81  82  //  Anim.anim extends base.Base with 2 modules83  // see https://github.com/angelozerr/tern-yui3/issues/1284  util.assertCompletion("YUI().use('mod1','mod2', function(Y) { var anim = new Y.Anim(); anim.unpl", {85      "start":{"line":0,"ch":69},86      "end":{"line":0,"ch":73},87      "isProperty":true,88      "isObjectKey":false,89      "completions":[{"name":"unplug","type":"fn()", "origin":"yui3"}90                    ]91  });     92}9394exports['test Y.Anim completion'] = function() {95util.assertCompletion("YUI().use('', function(Y) { new Y.A", {96  "name":"Anim",97  "type":"fn()",98  "origin":"yui3"99}, "Anim");100}101102
...DataFields.js
Source:DataFields.js  
1import DataField from './DataField';2export class DataFields {3    static Type() { return "System.Data.DataField"; }4    GetType() { return "System.Data.DataField"; }5    constructor(data, fieldskey = "_fields", addproperty = true) {        6        this._data = data;7        this._bind = null;8        this._fieldsKey = fieldskey;9        let self = this;10        self = {};      11        if(addproperty)12           this.FieldsProperty(this._data, this._fieldsKey);       13    }14    Get(idorname, isproperty = false) {15        if (!isproperty) {16            let pyl = this._data.GetPylon(idorname);17            if (pyl !== null) {18                return this[pyl.PylonId];19            }20            else {21                let test = this[idorname.toLowerCase()];22                if (typeof (test) !== "undefined")23                    return this[idorname.toLowerCase()];24            }25        }26        else {27            return this[idorname.toLowerCase()];28        }29        return null;30    }31    Set(idorname, value, isproperty = false) {32        if (!isproperty) {33            let pyl = this._data.GetPylon(idorname);34            if (pyl !== null) {35                this[pyl.PylonId].Value = value;36                return this[pyl.PylonId];37            }38        }39        else {40            this[idorname].Value = value;41            return this[idorname];42        }43        return null;44    }45           46    Put(fieldid, value, isproperty = false, istier = true, obj = null) {47        let check = this[fieldid];48        if (typeof (check) !== "undefined") {49            if (value !== null)50                this[fieldid].Value = value;51            else if (obj !== null)52                this[fieldid].Value = obj;53        }54        else55            this.Add(fieldid, value, isproperty, istier, obj);56    }57    Add(fieldid, value, isproperty = false, istier = true, obj = null) {58        if (obj === null)59            obj = this._data;60        if (isproperty && value !== null) {61            let priv = fieldid.toLowerCase();62            let pub = fieldid;63            delete obj[fieldid];64            fieldid = priv;65            obj[priv] = value;66            let key = this._fieldsKey;67            this[fieldid] = new DataField(obj, fieldid, value, isproperty, istier);68            Object.defineProperty(obj, pub,69                {70                    get() { return obj[key][fieldid].Value; },71                    set(value) { obj[key][fieldid].Value = value; },72                    configurable: true,73                    enumerable: true74                });75        }76        else {77            if (value !== null)78                this[fieldid] = new DataField(obj, fieldid, value, isproperty, istier);   79            else if (obj !== null)80                this[fieldid] = new DataField(obj, 'value', obj, isproperty, istier);                 81        }82    }83    Remove(field) {84        delete this[field.FieldId];85    }86    Delete(fieldid) {87        delete this[fieldid];88    }89    FieldsProperty(obj, key) {90        Object.defineProperty(obj, "Fields",91            {92                get() { return obj[key]; },93                set(value) {94                    for (var i in value) {95                        obj[key].Put(i, value[i]);96                    }97                }98            });99    }...isProperty.test.js
Source:isProperty.test.js  
1import isProperty from './isProperty'2describe('isProperty', () => {3  test('returns true for plain prop', () => {4    expect(isProperty('foo')).toBe(true)5    expect(isProperty('bar-')).toBe(true)6    expect(isProperty('bar1')).toBe(true)7    expect(isProperty('1bar')).toBe(true)8  })9  test('returns true for numeric strings', () => {10    expect(isProperty('123')).toBe(true)11    expect(isProperty('-123')).toBe(true)12    expect(isProperty('0')).toBe(true)13  })14  test('returns true for Symbols', () => {15    expect(isProperty(Symbol('abc'))).toBe(true)16    expect(isProperty(Symbol.for('foo'))).toBe(true)17  })18  test('returns false for plain prop String objects', () => {19    expect(isProperty(new String('foo'))).toBe(false)20    expect(isProperty(new String('bar-'))).toBe(false)21    expect(isProperty(new String('bar1'))).toBe(false)22    expect(isProperty(new String('1bar'))).toBe(false)23  })24  test('returns false for arrays', () => {25    expect(isProperty([])).toBe(false)26    expect(isProperty(new Array())).toBe(false)27  })28  test('returns false for prop paths', () => {29    expect(isProperty('foo.bar')).toBe(false)30    expect(isProperty('foo[1]')).toBe(false)31    expect(isProperty("foo['abc']")).toBe(false)32  })33  test('returns true for prop paths that are actual props', () => {34    expect(35      isProperty('foo.bar', {36        'foo.bar': 'value'37      })38    ).toBe(true)39    expect(40      isProperty('foo[1]', {41        'foo[1]': 'value'42      })43    ).toBe(true)44    expect(45      isProperty("foo['abc']", {46        "foo['abc']": 'value'47      })48    ).toBe(true)49  })50  test('returns false for all other values', () => {51    expect(isProperty(undefined)).toBe(false)52    expect(isProperty(null)).toBe(false)53    expect(isProperty(false)).toBe(false)54    expect(isProperty(true)).toBe(false)55    expect(isProperty(0)).toBe(false)56    expect(isProperty(-1)).toBe(false)57    expect(isProperty(1)).toBe(false)58    expect(isProperty(NaN)).toBe(false)59    expect(isProperty(Infinity)).toBe(false)60    expect(isProperty(-Infinity)).toBe(false)61    expect(isProperty(/abc/)).toBe(false)62    expect(isProperty(async () => {})).toBe(false)63    expect(isProperty(() => {})).toBe(false)64    expect(isProperty(function() {})).toBe(false)65    expect(isProperty(function*() {})).toBe(false)66    expect(isProperty(new ArrayBuffer(2))).toBe(false)67    expect(isProperty(new Boolean(false))).toBe(false)68    expect(isProperty(new Boolean(true))).toBe(false)69    expect(isProperty(new Date())).toBe(false)70    expect(isProperty(new Error())).toBe(false)71    expect(isProperty(new Number(-1.2))).toBe(false)72    expect(isProperty(new Number(1.2))).toBe(false)73    expect(isProperty(new Number(NaN))).toBe(false)74    expect(isProperty(new Number(Infinity))).toBe(false)75    expect(isProperty(new Number(-Infinity))).toBe(false)76    expect(isProperty(new Promise(() => {}))).toBe(false)77    expect(isProperty(new Proxy({}, {}))).toBe(false)78    expect(isProperty(new WeakMap())).toBe(false)79    expect(isProperty(new WeakSet())).toBe(false)80  })...property.js
Source:property.js  
1import {2  FEATURED_PROPERTIES_SUCCESS,3  FEATURED_PROPERTIES_FAIL,4  ADD_PROPERTY_SUCCESS,5  ADD_PROPERTY_FAIL,6  GET_PROPERTY_SUCCESS,7  GET_PROPERTY_FAIL,8  SEARCH_PROPERTIES_SUCCESS,9  SEARCH_PROPERTIES_FAIL,10  GET_AGENTPROPERTY_SUCCESS,11  GET_AGENTPROPERTY_FAIL,12  DELETE_PROPERTY_SUCCESS,13  DELETE_PROPERTY_FAIL14} from "../actions/types";15const properties = [];16const initialState = properties17  ? { isProperty: true, properties }18  : { isProperty: false, properties: null };19export default function (state = initialState, action) {20  const { type, payload } = action;21  switch (type) {22    case FEATURED_PROPERTIES_SUCCESS:23      return {24        ...state,25        isProperty: true,26        properties: payload,27      };28    case FEATURED_PROPERTIES_FAIL:29      return {30        ...state,31        isProperty: false,32        properties: null,33      };34    case ADD_PROPERTY_SUCCESS:35      return {36        ...state,37      };38    case ADD_PROPERTY_FAIL:39      return {40        ...state,41      };42    case GET_PROPERTY_SUCCESS:43      return {44        ...state,45        properties: payload,46      };47    case GET_PROPERTY_FAIL:48      return {49        ...state,50      };51    case SEARCH_PROPERTIES_SUCCESS:52      return {53        ...state,54        isProperty: true,55        properties: payload,56      };57    case SEARCH_PROPERTIES_FAIL:58      return {59        ...state,60        isProperty: false,61        properties: null,62      };63    case GET_AGENTPROPERTY_SUCCESS:64      return {65        ...state,66        isProperty: true,67        properties: payload,68      };69    case GET_AGENTPROPERTY_FAIL:70      return {71        ...state,72        isProperty: false,73        properties: null,74      };75    case DELETE_PROPERTY_SUCCESS:76      return {77        ...state,78        isProperty: true,79      };80    case DELETE_PROPERTY_FAIL:81      return {82        ...state,83        isProperty: false,84      };85    default:86      return state;87  }...index.js
Source:index.js  
1var isProperty = require('is-property')2var gen = function(obj, prop) {3  return isProperty(prop) ? obj+'.'+prop : obj+'['+JSON.stringify(prop)+']'4}5gen.valid = isProperty6gen.property = function (prop) {7 return isProperty(prop) ? prop : JSON.stringify(prop)8}...Using AI Code Generation
1import { Selector } from 'testcafe';2test('My Test', async t => {3    const developerNameInput = Selector('#developer-name');4        .expect(developerNameInput.hasAttribute('name')).ok()5        .expect(developerNameInput.hasAttribute('id')).ok()6        .expect(developerNameInput.hasAttribute('value')).notOk()7        .expect(developerNameInput.hasAttribute('type')).ok()8        .expect(developerNameInput.hasAttribute('placeholder')).ok()9        .expect(developerNameInput.hasAttribute('required')).ok()10        .expect(developerNameInput.hasAttribute('data-testid')).ok()11        .expect(developerNameInput.hasAttribute('class')).ok();12});13import { Selector } from 'testcafe';14test('My Test', async t => {15    const developerNameInput = Selector('#developer-name');16        .expect(developerNameInput.hasClass('input')).ok()17        .expect(developerNameInput.hasClass('form-control')).ok()18        .expect(developerNameInput.hasClass('form-control-lg')).ok()19        .expect(developerNameInput.hasClass('form-control-success')).notOk()20        .expect(developerNameInput.hasClass('form-control-danger')).notOk();21});22import { Selector } from 'testcafe';23test('My Test', async t => {24    const developerNameInput = Selector('#developer-name');25        .expect(developerNameInput.hasFocus).notOk()26        .click(developerNameInput)27        .expect(developerNameInput.hasFocus).ok();28});29import { Selector } from 'testcafe';Using AI Code Generation
1import {Selector} from 'testcafe';2test('My Test', async t => {3    const developerNameInput = Selector('#developer-name');4    const windowsRadioButton = Selector('#windows');5    const submitButton = Selector('#submit-button');6        .typeText(developerNameInput, 'John Smith')7        .click(windowsRadioButton)8        .click(submitButton)9        .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!')10});11import {Selector} from 'testcafe';12test('My Test', async t => {13    const developerNameInput = Selector('#developer-name');14    const windowsRadioButton = Selector('#windows');15    const submitButton = Selector('#submit-button');16        .typeText(developerNameInput, 'John Smith')17        .click(windowsRadioButton)18        .click(submitButton)19        .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!')20});21import {Selector} from 'testcafe';22test('My Test', async t => {23    const developerNameInput = Selector('#developer-name');24    const windowsRadioButton = Selector('#windows');25    const submitButton = Selector('#submit-button');26        .typeText(developerNameInput, 'John Smith')27        .click(windowsRadioButton)28        .click(submitButton)29        .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!')30});31import {Selector} from 'testcafe';32test('My Test', async t => {33    const developerNameInput = Selector('#developer-name');34    const windowsRadioButton = Selector('#windows');35    const submitButton = Selector('#submit-button');Using AI Code Generation
1import { Selector } from 'testcafe';2test('My Test', async t => {3    const developerNameInput = Selector('#developer-name');4    const windowsRadioButton = Selector('#windows');5    const submitButton = Selector('#submit-button');6    const articleHeader = Selector('.result-content').find('h1');7        .typeText(developerNameInput, 'Peter')8        .click(windowsRadioButton)9        .click(submitButton)10        .expect(articleHeader.innerText).eql('Thank you, Peter!');11});Using AI Code Generation
1import { Selector } from 'testcafe';2test('My Test', async t => {3    const developerNameInput = Selector('#developer-name');4    const windowsOSRadio = Selector('#windows');5    const submitButton = Selector('#submit-button');6        .typeText(developerNameInput, 'John Smith')7        .click(windowsOSRadio)8        .click(submitButton)9        .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');10});11import { Selector } from 'testcafe';12test('My Test', async t => {13    const developerNameInput = Selector('#developer-name');14    const windowsOSRadio = Selector('#windows');15    const submitButton = Selector('#submit-button');16        .typeText(developerNameInput, 'John Smith')17        .click(windowsOSRadio)18        .click(submitButton)19        .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');20});21import { Selector } from 'testcafe';22test('My Test', async t => {23    const developerNameInput = Selector('#developer-name');24    const windowsOSRadio = Selector('#windows');25    const submitButton = Selector('#submit-button');26        .typeText(developerNameInput, 'John Smith')27        .click(windowsOSRadio)28        .click(submitButton)29        .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');30});31import { Selector } from 'testcafe';32test('My Test', async t => {33    const developerNameInput = Selector('#developer-name');34    const windowsOSRadio = Selector('#windows');35    const submitButton = Selector('#submit-button');36        .typeText(developerNameInput, 'JohnUsing AI Code Generation
1import { Selector } from 'testcafe';2test('My test', async t => {3    const select = Selector('#preferred-interface');4        .expect(select.value).eql('Both')5        .expect(select.find('option').withText('Both').value).eql('Both')6        .expect(select.find('option').withText('JavaScript API').value).eql('JavaScript API')7        .expect(select.find('option').withText('Both').exists).ok()8        .expect(select.find('option').withText('JavaScript API').exists).ok()9        .expect(select.find('option').withText('Command Line').exists).ok()10        .expect(select.find('option').withText('Both').count).eql(1)11        .expect(select.find('option').withText('JavaScript API').count).eql(1)12        .expect(select.find('option').withText('Command Line').count).eql(1)13        .expect(select.find('option').withText('None').exists).notOk()14        .expect(select.find('option').withText('None').count).eql(0)15        .expect(select.find('option').withText('None').exists).notOk()16        .expect(select.find('option').withText('None').count).eql(0)17        .expect(select.find('option').withText('None').exists).notOk()18        .expect(select.find('option').withText('None').count).eql(0)19        .expect(select.find('option').withText('None').exists).notOk()20        .expect(select.find('option').withText('None').count).eql(0)21        .expect(select.find('option').withText('None').exists).notOk()22        .expect(select.find('option').withText('None').count).eql(0)23        .expect(select.find('option').withText('None').exists).notOk()24        .expect(select.find('option').withText('None').count).eql(0)25        .expect(select.find('option').withText('None').exists).notOk()26        .expect(select.find('option').withText('None').count).eql(0)27        .expect(select.find('option').withText('Using AI Code Generation
1import { Selector } from 'testcafe';2test('Test', async t => {3    const developerNameInput = Selector('#developer-name');4        .expect(developerNameInput.value).eql('', 'input is empty')5        .typeText(developerNameInput, 'Peter')6        .expect(developerNameInput.value).eql('Peter', 'input has text')7        .expect(developerNameInput.hasAttribute('id')).ok()8        .expect(developerNameInput.hasAttribute('value')).ok()9        .expect(developerNameInput.hasAttribute('name')).notOk();10});11import { Selector } from 'testcafe';12test('Test', async t => {13    const developerNameInput = Selector('#developer-name');14        .expect(developerNameInput.value).eql('', 'input is empty')15        .typeText(developerNameInput, 'Peter')16        .expect(developerNameInput.value).eql('Peter', 'input has text')17        .expect(developerNameInput.hasAttribute('id')).ok()18        .expect(developerNameInput.hasAttribute('value')).ok()19        .expect(developerNameInput.hasAttribute('name')).notOk();20});21import { Selector } from 'testcafe';22test('Test', async t => {23    const developerNameInput = Selector('#developer-name');24        .expect(developerNameInput.value).eql('', 'input is empty')25        .typeText(developerNameInput, 'Peter')26        .expect(developerNameInput.value).eql('Peter', 'input has text')27        .expect(developerNameInput.hasAttribute('id')).ok()28        .expect(developerNameInput.hasAttribute('value')).ok()29        .expect(developerNameInput.hasAttribute('name')).notOk();30});31import {Using AI Code Generation
1import {Selector} from 'testcafe';2test('My Test', async t => {3    const developerNameInput = Selector('#developer-name');4    const windowsRadioButton = Selector('#windows');5    const macOSRadioButton = Selector('#macos');6    const submitButton = Selector('#submit-button');7        .typeText(developerNameInput, 'John Smith')8        .click(windowsRadioButton)9        .expect(macOSRadioButton.checked).notOk()10        .click(macOSRadioButton)11        .expect(windowsRadioButton.checked).notOk()12        .click(submitButton);13});14import {Selector} from 'testcafe';15test('My Test', async t => {16    const developerNameInput = Selector('#developer-name');17    const windowsRadioButton = Selector('#windows');18    const macOSRadioButton = Selector('#macos');19    const submitButton = Selector('#submit-button');20        .typeText(developerNameInput, 'John Smith')21        .click(windowsRadioButton)22        .expect(macOSRadioButton.withProperty('checked', 'true')).notOk()23        .click(macOSRadioButton)24        .expect(windowsRadioButton.withProperty('checked', 'true')).notOk()25        .click(submitButton);26});27import {Selector} from 'testcafe';28test('My Test', async t => {29    const developerNameInput = Selector('#developer-name');30    const windowsRadioButton = Selector('#windows');31    const macOSRadioButton = Selector('#macos');32    const submitButton = Selector('#submit-button');33    const radioButtons = Selector('input[type=radio]');Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
