How to use vcr method in ng-mocks

Best JavaScript code snippet using ng-mocks

relatedVcr.js

Source:relatedVcr.js Github

copy

Full Screen

1var VCRLocationGA = {2 "RIGHTBAR_BOX_TYPE1_TOP" : "top",3 "RIGHTBAR_BOX_TYPE1_BOTTOM ": "bottom",4 "RIGHTBAR_BOX_TYPE2_TOP" : "top",5 "RIGHTBAR_BOX_TYPE2_BOTTOM" : "bottom"6};7var VCR = {8 loadAllVcrs : function(communityIds, topicIds) {9 window.vcrsLoaded = false;10 $.ajax({11 type : "POST",12 url : InfoQConstants.countryCode + "/vendorcontent/loadVcrs.action",13 dataType : 'json',14 data : {15 'communityIds' : communityIds,16 'topicIds' : topicIds17 },18 success : function(result){19 if(result.vcrs != null && result.vcrs.length > 0)20 {21 window.vcrList = result.vcrs;22 window.excludedVcrs = [];23 window.vcrsLoaded = true;24 } else {25 window.vcrList = [];26 window.excludedVcrs = [];27 window.vcrsLoaded = true;28 }29 },30 error : function(xhr, errmsg) {31 console.log("Error!!! " + errmsg);32 }33 });34 },35 filterByCover : function(maxItems, toFilter) {36 var filteredVcrs = toFilter.filter(function(vcr){37 return window.excludedVcrs.indexOf(vcr) == -1 &&38 vcr.coverImagePath != undefined &&39 vcr.coverImagePath != null &&40 vcr.coverImagePath != "";41 });42 filteredVcrs.sort(function() { return 0.5 - Math.random() });43 if(maxItems < 0 || filteredVcrs.length <= maxItems) {44 return filteredVcrs;45 }46 return filteredVcrs.slice(0, maxItems);47 },48 filterByCompany : function(company, toFilter) {49 return toFilter.filter(function(vcr){50 return window.excludedVcrs.indexOf(vcr) == -1 &&51 vcr.company == company;52 });53 },54 filterByTopic : function(topicId, toFilter) {55 return toFilter.filter(function(vcr){56 return window.excludedVcrs.indexOf(vcr) == -1 &&57 vcr.categories.indexOf(parseInt(topicId)) > -1;58 });59 },60 filterByTopics : function(topics, toFilter) {61 var topicIds = topics.split(",");62 return toFilter.filter(function(vcr){63 if(window.excludedVcrs.indexOf(vcr) != -1) {64 return false;65 }66 for(var index in topicIds) {67 if(vcr.categories.indexOf(parseInt(topicIds[index])) > -1) {68 return true;69 }70 }71 return false;72 });73 },74 filterByTopicsWithoutList : function(topics, toFilter, withoutList) {75 var topicIds = topics.split(",");76 return toFilter.filter(function(vcr){77 if(window.excludedVcrs.indexOf(vcr) != -1 || withoutList.indexOf(vcr) != -1) {78 return false;79 }80 for(var index in topicIds) {81 if(vcr.categories.indexOf(parseInt(topicIds[index])) > -1) {82 return true;83 }84 }85 return false;86 });87 },88 addToExcludedList : function(vcrs) {89 window.excludedVcrs = window.excludedVcrs.concat(vcrs);90 },91 addIdstoExcludeList : function(vcrIds) {92 if( vcrIds != "") {93 var excludedIds = vcrIds.split(",");94 for(var vcr in window.excludedVcrs) {95 if(excludedIds.indexOf(window.excludedVcrs[vcr].id.toString()) > -1) {96 VCR.addToExcludedList(vcr);97 }98 }99 }100 },101 getRandomVcrs : function(maxItems, fromList) {102 var filteredVcrs = fromList.filter(function(vcr){103 return window.excludedVcrs.indexOf(vcr) == -1 && vcr.categories != null && vcr.categories.length > 0;104 });105 if(filteredVcrs.length <= maxItems) {106 return filteredVcrs;107 }108 filteredVcrs = VCR.shuffleArray(filteredVcrs);109 return filteredVcrs.slice(0, maxItems);110 },111 shuffleArray : function(array) {112 var currentIndex = array.length, temporaryValue, randomIndex;113 while (0 !== currentIndex) {114 randomIndex = Math.floor(Math.random() * currentIndex);115 currentIndex -= 1;116 temporaryValue = array[currentIndex];117 array[currentIndex] = array[randomIndex];118 array[randomIndex] = temporaryValue;119 }120 return array;121 },122 getByTopicsAndCommunities : function(fromList, topicIds, communityIds, maxItems, withCover, company) {123 var result = [];124 var filteredByTopic = fromList;125 if(topicIds != "") {126 filteredByTopic = VCR.filterByTopics(topicIds, fromList);127 }128 if(withCover) {129 filteredByTopic = VCR.filterByCover(-1, filteredByTopic);130 }131 if(company != null) {132 filteredByTopic = VCR.filterByCompany(company, filteredByTopic);133 }134 if(filteredByTopic.length < maxItems) {135 var remainingItems = maxItems - filteredByTopic.length;136 var filteredByCommunities = fromList;137 if(communityIds != "") {138 filteredByCommunities = VCR.filterByTopicsWithoutList(communityIds, fromList, filteredByTopic);139 }140 if(withCover) {141 filteredByCommunities = VCR.filterByCover(-1, filteredByCommunities);142 }143 if(company != null) {144 filteredByCommunities = VCR.filterByCompany(company, filteredByCommunities);145 }146 if(filteredByCommunities.length < remainingItems) {147 result = filteredByTopic.concat(filteredByCommunities);148 } else {149 result = filteredByTopic.concat(VCR.getRandomVcrs(remainingItems, filteredByCommunities));150 }151 } else {152 result = VCR.getRandomVcrs(maxItems, filteredByTopic);153 }154 return result;155 },156 isVcrSponsored : function(sponsoredLinks, vcr) {157 for(var index in sponsoredLinks) {158 var item = sponsoredLinks[index];159 if(item.target != null && item.target != "") {160 if(item.target.indexOf("show.action?vcr=" + vcr.id) != -1) {161 return true;162 } else if(item.target == vcr.sponsoredPath) {163 return true;164 }165 }166 }167 return false;168 }169};170function submitNativeAdCustomVar(position){171 var _gaq = _gaq || [];172 _gaq.push(['_setCustomVar', 5, 'VCR Native Ads experiment', "native-vcr-A" + position, 3]);173}174function getVendorContentIconType(vcr) {175 if(null == vcr.type) {176 return "";177 }178 if(vcr.isPodcast) {179 return "podcast";180 }181 if(vcr.type != "sponsorship") {182 return vcr.type;183 }184 if (null != vcr.sponsoredPath){185 if(vcr.sponsoredPath.startsWith("/news")) {186 return "article";187 }188 if(vcr.sponsoredPath.startsWith("/articles")) {189 return "article";190 }191 if(vcr.sponsoredPath.startsWith("/interviews")) {192 return "demo";193 }194 if(vcr.sponsoredPath.startsWith("/presentations")) {195 return "demo";196 }197 if(vcr.sponsoredPath.startsWith("/minibooks")) {198 return "pdf";199 }200 if(vcr.sponsoredPath.startsWith("/podcasts")) {201 return "podcast";202 }203 }204 return "";205}206function getVcrAnchorUrl(vcr, uriMapping, dataPlace, isInline) {207 var primaryTopicId = $('#cont_item_primary_topic').val();208 var vcrAnchorUrl = "";209 vcrAnchorUrl += InfoQConstants.countryCode + '/vendorcontent/show.action?vcr=' + vcr.id;210 if(primaryTopicId){211 vcrAnchorUrl += '&primaryTopicId=' + primaryTopicId;212 vcrAnchorUrl += '&vcrPlace=' + dataPlace;213 if(InfoQConstants.pageType){214 vcrAnchorUrl += '&pageType=' + InfoQConstants.pageType;215 }216 vcrAnchorUrl += '&vcrReferrer=' + encodeURIComponent(InfoQConstants.pageUrl);217 }218 var source = "infoq";219 if(window.device === "mobile") {220 source += "_mobile";221 }222 vcrAnchorUrl += "&utm_source=" + source + "&utm_medium=" + (isInline ? "VCRinlineitem" : "VCR") + "&utm_campaign=vcr_";223 if(uriMapping !== undefined && uriMapping !== null && uriMapping !== "") {224 vcrAnchorUrl += uriMapping ;225 } else {226 vcrAnchorUrl += getPageMappingforPageType();227 }228 var content = VCRLocationGA[dataPlace];229 if(content === undefined) {230 content = dataPlace.toLowerCase();231 }232 vcrAnchorUrl += "_click&utm_content=" + content;233 return vcrAnchorUrl;234}235function getOptionalVcrAnchorUrl(vcr, uriMapping, dataPlace) {236 var vcrAnchorUrl = "";237 vcrAnchorUrl += InfoQConstants.countryCode + '/vendorcontent/show.action?vcr=' + vcr.id;238 if(uriMapping !== undefined && uriMapping !== null && uriMapping !== "") {239 vcrAnchorUrl += '&utm_source=infoq&utm_medium=related_content_native_link&utm_campaign=relatedContent_native_' + uriMapping + '_clk';240 } else {241 vcrAnchorUrl += '&utm_source=infoq&utm_medium=related_content_native_link&utm_campaign=relatedContent_native_' + getPageMappingforPageType() + '_clk';242 }243 vcrAnchorUrl += "&utm_content=" + dataPlace.toLowerCase();244 return vcrAnchorUrl;245}246function getPageMappingforPageType() {247 if(InfoQConstants.pageType === "CONTENT_TYPE_PAGE") {248 return "contentTypePage_all" + InfoQConstants.mapping.toLowerCase();249 } else if(InfoQConstants.pageType === "CATEGORY_PAGE_BY_CONTENT_TYPE") {250 return "categoryPageByContentType_all" + InfoQConstants.mapping.toLowerCase();251 } else if(InfoQConstants.pageType === "CATEGORY_PAGE") {252 return "categoryPage";253 }254 return "homePage";255}256function getVcrCoverElement(vcrCoverMain, vcr, isPopup) {257 var vcrCoverSection = $(document.createElement('div'));258 vcrCoverSection.addClass("m-section");259 var vcrCoverImage = $(document.createElement('div'));260 vcrCoverImage.addClass("m-atom");261 vcrCoverImage.addClass("m-cover");262 var vcrCoverImageStencil = $(document.createElement('div'));263 vcrCoverImageStencil.addClass("m-cover-stencil");264 var img = $(document.createElement('img'));265 img.attr("src", vcr.coverImagePath);266 img.css("height", "177px");267 img.css("width", "125px");268 var vcrCoverTitle = $(document.createElement('div'));269 vcrCoverTitle.addClass("m-atom");270 vcrCoverTitle.addClass("m-title");271 var vcrCoverTitleTable = $(document.createElement('div'));272 vcrCoverTitleTable.addClass("m-table");273 vcrCoverTitleTable.css("width", "100%");274 if(!isPopup) {275 vcrCoverTitleTable.css("border-right", "1px dotted #d7d7d7");276 }277 var vcrCoverTitleSpan = $(document.createElement('span'));278 vcrCoverTitleSpan.addClass("m-table-cell");279 var vcrCoverTitleSpanP = $(document.createElement('p'));280 vcrCoverTitleSpanP.text(vcr.title);281 if(standaloneVcr.title.length > 88) {282 vcrCoverTitleSpanP.css("font-size", "12px");283 }284 var vcrCoverTitleSpanSpan = $(document.createElement('span'));285 if(vcr.author && vcr.author != ""){286 vcrCoverTitleSpanSpan.text(vcr.author);287 } else {288 vcrCoverTitleSpanSpan.text(vcr.company);289 }290 vcrCoverTitleSpan.append(vcrCoverTitleSpanP);291 vcrCoverTitleSpan.append(vcrCoverTitleSpanSpan);292 vcrCoverTitleTable.append(vcrCoverTitleSpan);293 vcrCoverTitle.append(vcrCoverTitleTable);294 vcrCoverImage.append(vcrCoverImageStencil);295 vcrCoverImageStencil.append(img);296 if(isPopup) {297 vcrCoverSection.append(vcrCoverImage);298 vcrCoverMain.append(vcrCoverSection);299 } else {300 vcrCoverMain.append(vcrCoverImage);301 }302 vcrCoverSection.append(vcrCoverImage);303 vcrCoverMain.append(vcrCoverImage);304 vcrCoverMain.append(vcrCoverTitle);305}306function getCommonElements(vcrs, uriMapping, place) {307 var $vcrs = $(".vcrs");308 $vcrs.empty();309 for(var vcr in vcrs) {310 var jsh = '{"id": "' + vcrs[vcr].id + '", "title": "' + vcrs[vcr].title + '"}';311 var vcrElement = $(document.createElement('h3'));312 vcrElement.addClass("entry" + getVendorContentIconType(vcrs[vcr]));313 vcrElement.addClass("f_vcrdefault");314 vcrElement.attr("data-place", place);315 vcrElement.attr("jsh", jsh);316 var vcrAnchor = $(document.createElement('a'));317 if(vcrs[vcr].external && !vcrs[vcr].registerOnInfoQ && ! vcrs[vcr].landingOnInfoq) {318 vcrAnchor.attr("target","_blank");319 }320 vcrAnchor.attr("href", getVcrAnchorUrl(vcrs[vcr], uriMapping, place, false));321 vcrAnchor.text(vcrs[vcr].title);322 vcrElement.append(vcrAnchor);323 $vcrs.append(vcrElement);324 }325}326function getMobileCommonElements(vcrs, uriMapping, place) {327 var $vcrs = $(".rvc_vcrs ul");328 $vcrs.empty();329 for(var vcr in vcrs) {330 var jsh = '{"id": "' + vcrs[vcr].id + '", "title": "' + vcrs[vcr].title + '"}';331 var vcrElement = $(document.createElement('li'));332 vcrElement.addClass("rvc_" + getVendorContentIconType(vcrs[vcr]));333 vcrElement.addClass("f_vcrdefault");334 vcrElement.attr("data-place", place);335 vcrElement.attr("jsh", jsh);336 var vcrAnchor = $(document.createElement('a'));337 if(vcrs[vcr].external && !vcrs[vcr].registerOnInfoQ && ! vcrs[vcr].landingOnInfoq) {338 vcrAnchor.attr("target","_blank");339 }340 vcrAnchor.attr("href", getVcrAnchorUrl(vcrs[vcr], uriMapping, place, false));341 vcrAnchor.text(vcrs[vcr].title);342 vcrElement.append(vcrAnchor);343 $vcrs.append(vcrElement);344 }345}346function getCommonMobileElement(vcr, uriMapping) {347 var element = $(document.createElement('li'));348 element.addClass("f_vcrdefault");349 element.attr("data-place", "BOTTOM");350 var jsh = '{"id": "' + vcr.id + '", "title": "' + vcr.title + '"}';351 element.attr("jsh", jsh);352 var anchor = $(document.createElement('a'));353 anchor.addClass("rvc_" + getVendorContentIconType(vcr));354 anchor.attr("href", getVcrAnchorUrl(vcr, uriMapping, "BOTTOM", false));355 anchor.text(vcr.title);356 element.append(anchor);357 return element;358}359function getABC2Elements(standaloneVcr, uriMapping, $firstBox, $secondBox) {360 $secondBox.addClass("m-trigger");361 $secondBox.css("width","46%");362 $secondBox.css("float","right");363 $secondBox.find("p.title").css("font-size", "16px");364 var vcrCoverMain = $(document.createElement('a'));365 vcrCoverMain.addClass("f_vcrdefault");366 vcrCoverMain.addClass("no-jsh");367 vcrCoverMain.attr("data-place", "BOTTOM");368 vcrCoverMain.attr("data-vcrtitle", standaloneVcr.title);369 vcrCoverMain.attr("data-vcrid", standaloneVcr.id);370 if(standaloneVcr.external && !standaloneVcr.registerOnInfoQ && !standaloneVcr.landingOnInfoq) {371 vcrCoverMain.attr("target","_blank");372 }373 vcrCoverMain.attr("href", getVcrAnchorUrl(standaloneVcr, uriMapping, "BOTTOM", false));374 getVcrCoverElement(vcrCoverMain, standaloneVcr, false);375 $firstBox.append(vcrCoverMain);376 $firstBox.css("display", "block");377}378function getPopUpVcr(vcr, uriMapping) {379 var popUpVcr = $(document.createElement('a'));380 popUpVcr.addClass("f_vcrdefault");381 popUpVcr.addClass("hidden");382 popUpVcr.addClass("no-jsh");383 popUpVcr.addClass("no-data");384 popUpVcr.attr("data-place", "BOTTOM");385 popUpVcr.css("float", "left");386 if(vcr.external && !vcr.registerOnInfoQ && !vcr.landingOnInfoq) {387 popUpVcr.attr("target","_blank");388 }389 popUpVcr.attr("href", getVcrAnchorUrl(vcr, uriMapping, "BOTTOM", false));390 var hiddenVcrId = $(document.createElement('div'));391 hiddenVcrId.addClass("vcrid");392 hiddenVcrId.css("display", "none");393 hiddenVcrId.text(vcr.id);394 var hiddenVcrTitle = $(document.createElement('div'));395 hiddenVcrTitle.addClass("vcrtitle");396 hiddenVcrTitle.css("display", "none");397 hiddenVcrTitle.text(vcr.title);398 popUpVcr.append(hiddenVcrId);399 popUpVcr.append(hiddenVcrTitle);400 getVcrCoverElement(popUpVcr, vcr, true);401 return popUpVcr;402}403function getABC3Elements(vcrList, uriMapping, $firstBox) {404 $firstBox.addClass("m-trigger");405 $firstBox.addClass("m-section");406 var popUp = $(document.createElement('div'));407 popUp.addClass("m-panel");408 popUp.append(getPopUpVcr(vcrList[0], uriMapping));409 popUp.append(getPopUpVcr(vcrList[1], uriMapping));410 return popUp;411}412function getOptionalElements(vcrs, params){413 for(var vcr in vcrs) {414 var row = $(document.createElement('div'));415 row.addClass("row");416 var anchor = $(document.createElement('a'));417 anchor.attr("data-vcrtitle", vcrs[vcr].title);418 anchor.attr("data-vcrid", vcrs[vcr].id);419 anchor.attr("data-place", params.vcrsPosition <=1 ? "1" : "2");420 anchor.attr("href", getOptionalVcrAnchorUrl(vcrs[vcr], params.uriMapping, params.vcrsPosition <=1 ? "top" : "bottom"));421 var cover = $(document.createElement('div'));422 cover.addClass("cover");423 var container = $(document.createElement('div'));424 container.addClass("vcr_optional_icontainer");425 var image = $(document.createElement('img'));426 image.attr("src", vcrs[vcr].coverImagePath);427 container.append(image);428 cover.append(container);429 anchor.append(cover);430 var title = $(document.createElement('div'));431 title.addClass("vcr_title");432 var titleP = $(document.createElement('p'));433 titleP.text(vcrs[vcr].title);434 var titleSpan = $(document.createElement('span'));435 if(vcrs[vcr].author && vcrs[vcr].author != ""){436 titleSpan.text(vcrs[vcr].author);437 } else {438 titleSpan.text(vcrs[vcr].company);439 }440 title.append(titleP);441 title.append(titleSpan);442 anchor.append(title);443 row.append(anchor);444 $(".vcrs_optional_" + params.vcrsPosition).append(row);445 }446}447function toggleAds(vcrs, params) {448 var hasOptionalContent = (vcrs.length == 2);449 setTimeout(function () {450 var theDiv;451 if(params.vcrsPosition <= 1) {452 theDiv = $('#id_300x250_banner_top');453 } else {454 theDiv = $('#id_300x250_banner_bottom');455 }456 var ad_iframe = theDiv.find("iframe");457 var ad_height = 0;458 if(ad_iframe.length > 0) {459 ad_height+=ad_iframe.contents().height();460 }461 462 if (ad_height === 0 || theDiv.css("display") === "none") {463 theDiv.css("display", "none");464 var idString = "vcrOptional" + (params.vcrsPosition <= 1 ? "1" : "2");465 if (hasOptionalContent) {466 $("#" + idString).css("display", "block");467 $("#" + idString + " .row > a").addClass("f_vcroptional");468 VCR.addToExcludedList(vcrs);469 if(params.vcrsPosition <= 1) {470 window.finishedVcrOptional1 = true;471 }else {472 window.finishedVcrOptional2 = true;473 }474 setTimeout(function () {475 submitNativeAdCustomVar(params.vcrsPosition <= 1 ? "-top" : "-bottom");476 }, isAdBlocked() ? 2500 : 0);477 } else {478 if ($("#" + idString).parents('.gbanner').length) {479 $("#" + idString).parents('.gbanner').first().css("display", "none");480 }481 if(params.vcrsPosition <= 1) {482 window.finishedVcrOptional1 = true;483 } else {484 window.finishedVcrOptional2 = true;485 }486 }487 } else {488 theDiv.addClass("f_dfp_ad");489 if(params.vcrsPosition <= 1) {490 window.finishedVcrOptional1 = true;491 } else {492 window.finishedVcrOptional2 = true;493 }494 }495 }, isAdBlocked() ? 0 : 3500);496}497function getSponsoredPodcast(url, topicIds, filteringCategoryId, podcastChannel, language) {498 var sponsoredPodcast = null;499 $.ajax({500 type: "POST",501 url: url,502 dataType: 'json',503 data: {504 'topicIds': topicIds,505 'categoryId': filteringCategoryId,506 'channel':podcastChannel,507 'language':language508 },509 success: function (result) {510 if (result.vcrs != null && result.vcrs.length > 0) {511 populateSponsoredPodcast(result.vcrs[0], podcastChannel, language);512 }513 },514 error: function (xhr, errmsg) {515 console.log("Error!!! " + errmsg);516 }517 });518 return sponsoredPodcast;519}520function populateSponsoredPodcast(sponsoredPodcast, podcastChannel, language) {521 var sponsoredPodcastElement = jQuery(".podcast__sponsored." + podcastChannel.toLowerCase());522 if(sponsoredPodcastElement.length) {523 sponsoredPodcastElement.attr("data-vcrid", sponsoredPodcast.id);524 sponsoredPodcastElement.attr("data-vcrtitle", sponsoredPodcast.title);525 var anchorUrl = getVcrAnchorUrl(sponsoredPodcast, "contentTypePage", sponsoredPodcastElement.data("place"), false);526 var $sponsoredPodcastElementImage = sponsoredPodcastElement.find(".podcast__featured-image");527 $sponsoredPodcastElementImage.attr("href", anchorUrl);528 if(sponsoredPodcast.external && !sponsoredPodcast.registerOnInfoQ && !sponsoredPodcast.landingOnInfoq) {529 $sponsoredPodcastElementImage.attr("target","_blank");530 }531 $sponsoredPodcastElementImage.find("img").attr("src", sponsoredPodcast.coverImagePath);532 var $sponsoredPodcastElementTitle = sponsoredPodcastElement.find(".podcast__title").find("a");533 $sponsoredPodcastElementTitle.attr("href", anchorUrl);534 $sponsoredPodcastElementTitle.text(sponsoredPodcast.title);535 sponsoredPodcastElement.find(".podcast__excerpt").text(sponsoredPodcast.shortSummary);536 sponsoredPodcastElement.find(".podcast__highlighted").text(sponsoredPodcast.company);537 sponsoredPodcastElement.find(".la").attr("href", anchorUrl);538 sponsoredPodcastElement.css("display", "block");539 }...

Full Screen

Full Screen

rightbarOptionalVcrBox.js

Source:rightbarOptionalVcrBox.js Github

copy

Full Screen

1// for this to work all it needs is a vcrOptionalListJson in the page (see rightbar_related.jsp -> var vcrOptionalListJson = "<ww:property value='%{vendorContentOptionalListJson}'/>"; )2var optionalVcrBox = {3 vcrOptionalList : null,4 topBannerId : "id_300x250_banner_top",5 bottomBannerId : "id_300x250_banner_bottom",6 abTestVersion : null,7 8 // the following variables are needed to check the display/tracking status when box is displayed before page load or after page load. DO NOT CHANGE!!!!9 isGACustomVarSet : false,10 isOptionalVcrTopDisplayed : false,11 isOptionalVcrBottomDisplayed : false,12 isOptiopnalVcrTopTrackingDone : false,13 isOptiopnalVcrBottomTrackingDone : false,14 15 16 //workaround the fact the slotRenderedEvent is fired multiple times for the same slot(not sure why)17 checkedBannerTop: false,18 checkedBannerBottom: false,19 20 parseVendorContentOptionalList : function(vcrOptionalListJson) {21 // since the json is encoded as hrml, we need to decode it(jquery way,22 // create a div with a text and get the text)23 this.vcrOptionalList = $.parseJSON($("<div/>").html(JSON.stringify(vcrOptionalListJson)).text());24 },25 addWidgetVcrItem : function(vcrItem, trackerClass, place) {26 // tvi = tracked vcr id, tvl = tracked vcr label used for impression tracking, see tracker.js (called on document ready)27 vcrUrl=InfoQConstants.countryCode+"/vendorcontent/show.action?vcr="+vcrItem.id;28 vcrResult="<li> <a href=\""+vcrUrl+this.addVcrGATracking(place)+"\" class=\"rhs_b_s__cover\"><img src=\""+vcrItem.coverImagePath+"\" ></a>";29 vcrResult+="<a href=\""+vcrUrl+this.addVcrGATracking(place)+"\"" + " class=\"rhs_b_s__title "+trackerClass+"\" tvi=\""+vcrItem.id+"\" tvl=\"rightbar\">"+vcrItem.title+"</a><br>";30 vcrResult+="</li>";31 32 return vcrResult;33 },34 // this replaces the native vcr box used for homepage or other places. display one or two randomly from an array 35 addOptionalVcrSection : function (place, afterElemId){36 // place can be top or bottom 37 if(this.vcrOptionalList!=null && this.vcrOptionalList.length>0){38 var boxClassName = "f_sponsorbox_";39 if(place == "top" && ($('.f_sponsorbox').length > 0 ||40 $('.f_sponsorbox_top_1').length > 0 ||41 $('.f_sponsorbox_bottom_1').length > 0 )) {42 boxClassName += "bottom";43 } else {44 boxClassName += place;45 }46 boxClassName += "_1";47 $("<div id=\"optionalVcr_"+place+"\" class=\"" + boxClassName + " rhs_b rhs_b_s rhs_b_s--single nocontent\"><div class=\"rhs_b__title\">"+JSi18n.relatedRightbar_sponsoredContent+"</div><ul id=\"optionalVcr_ul_"+place+"\" class=\"rhs_b_s__books\"> </ul></div>").insertAfter("#"+afterElemId);48 var vcrClassName = "f_vcrrightbar_optional_"+place+"_1";49 if(this.vcrOptionalList.length>2){50 // 1 random 51 index1 = Math.floor(Math.random() * this.vcrOptionalList.length);52 index2 = Math.floor(Math.random() * this.vcrOptionalList.length);53 // check if not used before54 while (index1==index2) {55 index2 = Math.floor(Math.random() * this.vcrOptionalList.length);56 }57 //f_vcrrightbar_optional_top or bottom is used for impression tracking and we differentiate with classes not to double impressions if we have 2 boxes on the same page58 $( "#optionalVcr_ul_"+place ).append(this.addWidgetVcrItem(this.vcrOptionalList[index1],vcrClassName, place));59 $( "#optionalVcr_ul_"+place ).append(this.addWidgetVcrItem(this.vcrOptionalList[index2],vcrClassName, place));60 }else{61 $.each(this.vcrOptionalList, function(i,vcrItem) {62 //f_vcrrightbar_optional is used for impression tracking63 $( "#optionalVcr_ul_"+place ).append(optionalVcrBox.addWidgetVcrItem(vcrItem,vcrClassName, place));64 });65 }66 67 if(place=="top"){68 this.isOptionalVcrTopDisplayed = true;69 }else{70 this.isOptionalVcrBottomDisplayed = true;71 }72 73 // check to see if the GA variable exisis and is initialized, if yes to the tracking now)74 if(typeof _gaq !== "undefined"){75 this.doTracking(place);76 }77 }78 },79 80 addVcrGATracking: function(place){81 return "&utm_source=infoq&utm_medium=related_content_native_link&utm_campaign=relatedContent_native_"+contentUriMapping+"_clk&utm_content=" + place;82 },83 84 optionalVcrBoxDisplayAdBlock : function(){85 //check to see if we have adBlock on and if we have banners elements on page if yes insert optional vcr box86 if(isAdBlocked()){87 if($("#"+this.topBannerId).length>0){88 // we have a top banner and ad block on89 if($('.f_vcrrightbar_sponsorship_top_1').length > 0 ||90 $('.f_vcrrightbar_sponsorship_top_2').length > 0 ||91 $('.f_vcrrightbar_sponsorship_bottom_1').length > 0 ||92 $('.f_vcrrightbar_sponsorship_bottom_2').length > 0) {93 optionalVcrBox.addOptionalVcrSection("bottom","id_300x250_banner_top");94 } else {95 optionalVcrBox.addOptionalVcrSection("top","id_300x250_banner_top");96 }97 }98 if($("#"+this.bottomBannerId).length>0){99 // we have a top banner and ad block on100 optionalVcrBox.addOptionalVcrSection("bottom","id_300x250_banner_bottom");101 }102 }103 },104 105 // used on slotRendered event (see gpt.jsp) to see if the banners were displayed106 relatedRightbarNativeVcrSlotRendered: function(event){107 if (event.slot.getSlotElementId() == "id_300x250_banner_top") {108 // not sure sometimes events get called even if we did not put any banner on page so check to be sure first109 if($("#"+optionalVcrBox.topBannerId).length>0){110 if(event.isEmpty && !optionalVcrBox.checkedBannerTop){111 optionalVcrBox.checkedBannerTop = true;112 optionalVcrBox.addOptionalVcrSection("top","id_300x250_banner_top"); 113 }114 }115 }116 if (event.slot.getSlotElementId() == "id_300x250_banner_bottom") {117 // not sure sometimes events get called even if we did not put any banner on page so check to be sure first 118 if($("#"+optionalVcrBox.bottomBannerId).length>0){119 if(event.isEmpty && !optionalVcrBox.checkedBannerBottom){120 optionalVcrBox.checkedBannerBottom = true;121 optionalVcrBox.addOptionalVcrSection("bottom","id_300x250_banner_bottom"); 122 }123 }124 }125 },126 127 doTracking : function(place){128 if(this.isOptionalVcrTopDisplayed || this.isOptionalVcrBottomDisplayed){129 if(!this.isGACustomVarSet){130 _gaq.push(['_setCustomVar', 3, 'VCR Native Related Rightbar', this.abTestVersion, 3]);131 this.isGACustomVarSet = true;132 }133 }134 if(place=="top"){135 if(!this.isOptiopnalVcrTopTrackingDone){136 if(this.isOptionalVcrTopDisplayed){137 Tracker.doTrackVcrRightbarImpressions("f_vcrrightbar_optional_top_1");138 Tracker.doTrackVcrRightbarBoxesImpressions("f_sponsorbox_top_1");139 Tracker.doTrackVcrRightbarImpressions("f_vcrrightbar_optional_top_2");140 Tracker.doTrackVcrRightbarBoxesImpressions("f_sponsorbox_top_2");141 this.isOptiopnalVcrTopTrackingDone = true;142 }143 }144 }else{145 if(!this.isOptiopnalVcrBottomTrackingDone){146 if(this.isOptionalVcrBottomDisplayed){147 Tracker.doTrackVcrRightbarImpressions("f_vcrrightbar_optional_bottom_1");148 Tracker.doTrackVcrRightbarBoxesImpressions("f_sponsorbox_bottom_1");149 Tracker.doTrackVcrRightbarImpressions("f_vcrrightbar_optional_bottom_2");150 Tracker.doTrackVcrRightbarBoxesImpressions("f_sponsorbox_bottom_2");151 this.isOptiopnalVcrBottomTrackingDone = true;152 }153 }154 } 155 } 156 ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { vcr } from 'ng-mocks';2describe('TestComponent', () => {3 let fixture: any;4 let component: any;5 beforeEach(() => {6 fixture = vcr(TestComponent);7 component = fixture.componentInstance;8 });9 it('should create', () => {10 expect(component).toBeTruthy();11 });12});13import { ComponentFixture, TestBed } from '@angular/core/testing';14import { TestComponent } from './test.component';15describe('TestComponent', () => {16 let component: TestComponent;17 let fixture: ComponentFixture<TestComponent>;18 beforeEach(async () => {19 await TestBed.configureTestingModule({20 }).compileComponents();21 });22 beforeEach(() => {23 fixture = TestBed.createComponent(TestComponent);24 component = fixture.componentInstance;25 fixture.detectChanges();26 });27 it('should create', () => {28 expect(component).toBeTruthy();29 });30});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { vcr } from 'ng-mocks';2import { MyComponent } from './my.component';3import { MyService } from './my.service';4import { TestBed } from '@angular/core/testing';5import { HttpClientTestingModule } from '@angular/common/http/testing';6import { of } from 'rxjs';7describe('MyComponent', () => {8 let component: MyComponent;9 let fixture: ComponentFixture<MyComponent>;10 let service: MyService;11 beforeEach(async () => {12 await TestBed.configureTestingModule({13 imports: [HttpClientTestingModule],14 }).compileComponents();15 });16 beforeEach(() => {17 fixture = TestBed.createComponent(MyComponent);18 component = fixture.componentInstance;19 service = TestBed.inject(MyService);20 fixture.detectChanges();21 });22 it('should create', () => {23 expect(component).toBeTruthy();24 });25 it('should call service', () => {26 const spy = spyOn(service, 'get').and.returnValue(of('value'));27 component.ngOnInit();28 expect(spy).toHaveBeenCalled();29 });30 it('should render title', () => {31 const title = 'My Title';32 const spy = spyOn(service, 'get').and.returnValue(of(title));33 vcr.detectChanges(fixture);34 const compiled = fixture.nativeElement;35 expect(compiled.querySelector('h1').textContent).toContain(title);36 });37});38TestBed.configureTestingModule({39 imports: [HttpClientTestingModule],40 });41CREATE my-app/README.md (1029 bytes)42CREATE my-app/.editorconfig (274 bytes)43CREATE my-app/.gitignore (503 bytes)44CREATE my-app/angular.json (3569 bytes)45CREATE my-app/package.json (1245 bytes)

Full Screen

Using AI Code Generation

copy

Full Screen

1import { VCR } from 'ng-mocks';2import { ComponentFixture, TestBed } from '@angular/core/testing';3import { Component } from '@angular/core';4@Component({5})6export class TestComponent {}7describe('TestComponent', () => {8 let component: TestComponent;9 let fixture: ComponentFixture<TestComponent>;10 beforeEach(() => {11 TestBed.configureTestingModule({12 }).compileComponents();13 });14 beforeEach(() => {15 fixture = TestBed.createComponent(TestComponent);16 component = fixture.componentInstance;17 });18 it('should create', () => {19 expect(component).toBeTruthy();20 });21 it('should emit', () => {22 const spy = spyOn(component, 'emit');23 VCR(fixture).click('button');24 expect(spy).toHaveBeenCalled();25 });26});27import { VCR } from 'ng-mocks';28import { ComponentFixture, TestBed } from '@angular/core/testing';29import { Component } from '@angular/core';30@Component({31})32export class TestComponent {}33describe('TestComponent', () => {34 let component: TestComponent;35 let fixture: ComponentFixture<TestComponent>;36 beforeEach(() => {37 TestBed.configureTestingModule({38 }).compileComponents();39 });40 beforeEach(() => {41 fixture = TestBed.createComponent(TestComponent);42 component = fixture.componentInstance;43 });44 it('should create', () => {45 expect(component).toBeTruthy();46 });47 it('should emit', () => {48 const spy = spyOn(component, 'emit');49 VCR(fixture).click('button');50 expect(spy).toHaveBeenCalled();51 });52});53import { VCR } from 'ng-mocks';54import { ComponentFixture, TestBed } from '@angular/core/testing';55import { Component } from '@angular/core';56@Component({57})58export class TestComponent {}59describe('TestComponent', () => {60 let component: TestComponent;61 let fixture: ComponentFixture<TestComponent>;62 beforeEach(() => {63 TestBed.configureTestingModule({64 }).compileComponents();65 });66 beforeEach(() => {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { vcr } from 'ng-mocks';2describe('MyComponent', () => {3 it('should render', () => {4 const fixture = vcr.create(MyComponent);5 expect(fixture.nativeElement).toMatchSnapshot();6 });7});8import 'ng-mocks/dist/ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('my test', () => {2 beforeEach(() => {3 vcr.configure({4 imports: [AppModule],5 });6 });7 it('should call get', () => {8 const fixture = vcr.create(AppComponent);9 const service = fixture.point.injector.get(AppService);10 const spy = spyOn(service, 'get').and.returnValue(of([]));11 fixture.detectChanges();12 expect(spy).toHaveBeenCalled();13 });14});15describe('my test', () => {16 beforeEach(() => {17 TestBed.configureTestingModule({18 imports: [AppModule],19 });20 });21 it('should call get', () => {22 const fixture = TestBed.createComponent(AppComponent);23 const service = fixture.debugElement.injector.get(AppService);24 const spy = spyOn(service, 'get').and.returnValue(of([]));25 fixture.detectChanges();26 expect(spy).toHaveBeenCalled();27 });28});29describe('my test', () => {30 beforeEach(() => {31 vcr.configure({32 imports: [AppModule],33 });34 });35 it('should call get', () => {36 const fixture = vcr.create(AppComponent);37 const service = fixture.point.injector.get(AppService);38 const spy = spyOn(service, 'get').and.returnValue(of([]));39 fixture.detectChanges();40 expect(spy).toHaveBeenCalled();41 });42});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ng-mocks automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful