Best JavaScript code snippet using karma
getMciCategories.js
Source:getMciCategories.js
1/*jslint browser: true*/2/*global $, jQuery, alert, console, document, parseAndDisplayMciCategories, getCookie, createNextScreenButton, formatCategoryName, handleAjaxError */34function getMciCategories(fileURL, nodeId, start, numberOfColumns, numberOfRows, targetRegion, targetDiv, view, titleLength, site, screenFormat) {5 "use strict";6 var dataType = 'xml', node;78 $.ajax({9 type: "GET",10 url: fileURL,11 cache: true,12 dataType: dataType,13 success: function (xml) {14 // get the requested catalogue node and call function for processing15 node = $(xml).contents().find('category[id=\"' + nodeId + '\"]').children();16 parseAndDisplayMciCategories(node, fileURL, start, numberOfColumns, numberOfRows, targetRegion, targetDiv, view, titleLength, site, screenFormat);17 },18 error: function (jqXHR, statusText, errorThrown) {19 handleAjaxError(jqXHR, statusText, errorThrown, 'getMciCategories');20 }21 });2223}2425function parseAndDisplayMciCategories(node, fileURL, start, numberOfColumns, numberOfRows, targetRegion, targetDiv, view, titleLength, site, screenFormat) {26 "use strict";27 var divContent = '', screenCount = 0, categoriesPerScreen = numberOfColumns * numberOfRows, count = 0, lineNumber = 1, columnNumber = 0, divClassPostFix = '',28 skippedCount = 0, composeURL = '', categoryName = '', urlCategoryName = '', nextStart = parseInt(start, 10) + categoriesPerScreen, nextURL = '', currentScreen,29 nodeLength = $(node).length, startTemp = start, i, nextStartTemp, chaserContent = '', chaserLeftNumber = 0, chaserRightNumber = 0, videosInCategory = 0,30 prefenencesExist = true, prefenenceFlag = false, navigationLegend = '', endCount = 0, prefenenceCount = 0, excludeCategoryArray = '', excludeCategoryArrayLength = 0,31 pePreferences = getCookie('pePreferences');3233 currentScreen = Math.round((start / categoriesPerScreen) + 1);3435 // 18 - Surgery Pediatric (not in Florida)36 // 54 - Pregnancy-Newborn (not in Florida)37 // 455 - Psychiatry and Psychology (not in Florida)38 // 2356 - Arizona (only)39 // 3127 - Jacksonville (only)40 // 3731 - High Definition (not in Arizona, Rochester)41 // 30164 - Keep Pace4243 if (fileURL.indexOf("993") === -1) {44 if (site === 'RO') {45 excludeCategoryArray = ['2356', '3127', '3731', '30164', '35575'];46 excludeCategoryArrayLength = 5;47 } else if (site === 'AZ') {48 excludeCategoryArray = ['18', '54', '3127', '30164', '35575'];49 excludeCategoryArrayLength = 5;50 } else if (site === 'FL') {51 excludeCategoryArray = ['18', '54', '455', '2356', '30164', '35575'];52 excludeCategoryArrayLength = 6;53 }54 }5556 if (screenFormat === 'SD') {57 if (fileURL.indexOf("993") !== -1) {58 divClassPostFix += ' linePEFV';59 } else {60 divClassPostFix += ' linePE';61 }62 } else {63 divClassPostFix += ' lineLarge';64 }6566 if (view === 'Adult' ) {67 if (start === '1' && (pePreferences.length > 0) ) {68 divContent = getPatientEdFavCategoriesMain(start, pePreferences, 'Main', 'categories', site, screenFormat);69 count = 3; lineNumber = 3; nextStart = nextStart - 3; nodeLength = nodeLength + 3;70 }71 // if (pePreferences.length > 1) {nodeLength = nodeLength + 3;} 72 }7374 $(node).each(function (i, row) {75 if ($(this).attr('name') !== undefined && $(this).attr('bottomCategories') !== 'true' && $.inArray($(this).attr('id'), excludeCategoryArray) === -1 && pePreferences.indexOf($(this).attr('name')) === -1) {76 77 if (i >= (startTemp) && count < categoriesPerScreen) {78 categoryName = $(this).attr('name');79 if (prefenencesExist && pePreferences.indexOf(categoryName) !== -1 && view === 'Adult') {80 prefenenceFlag = true;81 prefenenceCount++;82 } else {83 prefenenceFlag = false;84 }85 count++;86 columnNumber++;87 categoryName = formatCategoryName(categoryName, 33);88 urlCategoryName = categoryName.replace(' & ', ' %26 ');8990 composeURL = 'javascript:ForwardWithIDAndQuery(';91 // alert($(this).attr('hasCategories') + ' | ' + categoryName);92 if ($(this).attr('hasCategories') === 'true') {93 composeURL += '\'mciSubCat.html';94 videosInCategory = $(this).children().children().length - $(this).children().length + 1;95 } else {96 composeURL += '\'mciGenre.html';97 videosInCategory = $(this).children().length - 1;98 }99 // alert($(this).attr('hasCategories') + ' | ' + categoryName + ' | ' + composeURL + ' | ' + numberOfRows);100 if (fileURL.indexOf("993") !== -1) {101 composeURL += '?genre=' + 'Frequently%20Viewed' + '&genreID=' + $(this).attr('id');102 composeURL += '&subGenre=' + encodeURI($(this).attr('name')) + '&subGenreID=' + $(this).attr('id');103 composeURL += '&quickPlay=1&view=' + view;104 } else {105 composeURL += '?view=mci&genre=' + encodeURI($(this).attr('name')) + '&genreID=' + $(this).attr('id') + '&view=' + view;106 if ($(this).attr('hasCategories') === 'false') {107 composeURL += '&subGenre=' + encodeURI($(this).attr('name')) + '&subGenreID=' + $(this).attr('id');108 }109 }110 composeURL += '\');';111112 // For ICTV, create chaser (arrow key) short-cuts113 chaserContent = '';114 if (columnNumber === 1) { chaserLeftNumber = ((numberOfColumns - 1) * numberOfRows) + count; chaserContent = ' chaser_left=\"link' + chaserLeftNumber + '\"'; }115 if (columnNumber === numberOfColumns) { chaserRightNumber = count - ((numberOfColumns - 1) * numberOfRows); chaserContent = "chaser_right=\"link" + chaserRightNumber + "\""; }116117 // build category URL118 divContent += '<div class=\"lineColumn' + targetRegion + 'MciFolder' + ' lineColumn' + targetRegion + columnNumber;119 divContent += ' ' + divClassPostFix + lineNumber + ' lineColumnMainWideFolderMci' + '\"';120121 divContent += ' onmouseover=\"onHoverDiv(\'onmouseover\', \'divLink' + count + '\' ,\'left\',\'false\',' + lineNumber + ',' + columnNumber + ');\"';122 divContent += ' onmouseout=\"onHoverDiv(\'onmouseout\', \'divLink' + count + '\' ,\'right\',\'false\',' + lineNumber + ',' + columnNumber + ');\"';123 divContent += ' onclick=\"' + composeURL + '\"' + 'id=\"divLink' + count + '\">\n';124 divContent += '<a id=\"link' + count + '\" href=\"' + composeURL + '\" class=\"lineItems' + targetRegion;125 // if (prefenenceFlag) { divContent += ' preferredCategory'; }126 divContent += '\" tabIndex=\"' + count + '\"' + chaserContent;127 divContent += ' onfocus=\"onHoverDiv(\'onFocus\', \'divLink' + count + '\' ,\'left\',\'false\',' + lineNumber + ',' + columnNumber + '); offSetFunction(\'divLink' + count + '\');\"';128 divContent += ' onblur=\"onHoverDiv(\'onBlur\', \'divLink' + count + '\' ,\'right\',\'false\',' + lineNumber + ',' + columnNumber + ');\"';129 divContent += '>';130 divContent += categoryName;131 divContent += '</a>\n';132 // if (prefenenceFlag) { divContent += '<img src=\"../images/icons/star_blue.gif\" />'; }133 // if (fileURL.indexOf("993") === -1) {divContent += '<span class=videoCount>(' + videosInCategory + ')</span>'; }134 // divContent += '<img src=../images/icons/folder.png style=\"position:absolute;bottom:12px;right:12px;\">';135 divContent += '</div>\n';136 137 if (fileURL.indexOf("993") !== -1 && screenFormat === 'HD' && $(this).attr('hasCategories') === 'true3') {138 // if freq viewed (a.k.a. channel 993), expand sub categories139 $(this).children().each(function (i, row) {140 if ($(this).attr('name') !== undefined) {141 // alert($(this).attr('id') + ' | ' + $(this).attr('name') + ' | ' + $(this).text());142 count++;143 if (lineNumber >= numberOfRows) { lineNumber = 0; columnNumber++; }144 lineNumber++;145146 composeURL = 'javascript:ForwardWithIDAndQuery(';147 composeURL += '\'mciGenre.html';148 composeURL += '?genre=' + encodeURIComponent(urlCategoryName) + '&genreID=90000';149 composeURL += '&subGenre=' + encodeURIComponent($(this).attr('name')) + '&subGenreID=' + $(this).attr('id');150 composeURL += '&quickPlay=1';151 composeURL += '&view=' + view;152 composeURL += '\');';153 divContent += '<div class=\"lineColumn lineColumnIndent lineColumn' + columnNumber + ' lineCategories' + targetRegion + lineNumber + '\" id=\"lineColumn' + lineNumber + '\" onclick=\"' + composeURL + '\" >';154 divContent += ' <img src=\"../images/icons/navbar/li.gif\" /> <a id=\"Button' + lineNumber + '\" href=\"' + composeURL + '\" class=\"lineItems\" tabIndex=\"' + count + '\">';155 divContent += $(this).attr('name');156 divContent += '</a></div>';157 divContent += '<img src=../images/icons/folder.png>\n';158 }159 });160 }161162 if (columnNumber >= numberOfColumns) {163 // if column is full, move to next column164 columnNumber = 0;165 lineNumber++;166 }167 if (count === categoriesPerScreen) {168 // if no more categories can be displayed, stop processing169 return false;170 }171172 }173 } else {174 skippedCount++;175 if ($(this).attr('name') !== undefined) { startTemp++; }176 }177 });178179 screenCount = Math.round(parseFloat(((nodeLength - skippedCount) / categoriesPerScreen)) + 0.49);180 // alert(currentScreen + ',' + screenCount);181 /*182 if (screenCount > 1 && currentScreen !== screenCount) {183 // if more than one screen of categories exist, display navigation elements184 nextStartTemp = nextStart;185 nextURL = 'javascript:ForwardWithID(\'index.html?start=' + nextStartTemp + '&view=' + view + '\');';186 setTimeout(function () { createNextScreenButton(nextURL, screenFormat); }, 500);187188 /*189 divContent += '<div class=\"screenBulletIndicatorPE\">';190 for (i = 1; i < screenCount + 1; i++) {191 if (i === currentScreen) {192 divContent += '<img src=\"../images/icons/bullets/bullet-selected.gif\" /> ';193 } else {194 divContent += '<img src=\"../images/icons/bullets/bullet.gif\" /> ';195 }196 divContent += ' ';197 }198 divContent += '</div>';199 200 } else {201 // since there is only one screen of categories, remove 'Next' button202 setTimeout(function () { $('#navbarNext').html(''); }, 500);203 }204 if (fileURL.indexOf("993") === -1) { //alert(nodeLength + '|' + skippedCount);205 endCount = count + parseInt(start, 10) - 1;206 navigationLegend = start + '-' + endCount + ' of ';207 navigationLegend += nodeLength - excludeCategoryArrayLength + ' categories';208 $('#itemCount').html(navigationLegend);209 }210 */211 212 divContent += '<div class=\"lineColumnMainWide lineColumnMainWide5\" style=\"background-color: #1F1F1F;\"></div> '213 $('#' + targetDiv).append(divContent);214 $('#ajaxLoader').html('');215
...
getPatEdCategories.js
Source:getPatEdCategories.js
1/*jslint browser: true*/2/*global $, jQuery, alert, console, document, parseAndDisplaypatEdCategories, getCookie, createNextScreenButton, formatCategoryName, handleAjaxError */34function getPatientEdCategories(fileURL, nodeId, start, numberOfColumns, numberOfRows, targetRegion, targetDiv, view, titleLength, site, screenFormat) {5 "use strict";6 var dataType = 'xml', node;78 $.ajax({9 type: "GET",10 url: fileURL,11 cache: true,12 dataType: dataType,13 success: function (xml) {14 // get the requested catalogue node and call function for processing15 node = $(xml).contents().find('category[id=\"' + nodeId + '\"]').children();16 parseAndDisplaypatEdCategories(node, fileURL, start, numberOfColumns, numberOfRows, targetRegion, targetDiv, view, titleLength, site, screenFormat);17 },18 error: function (jqXHR, statusText, errorThrown) {19 handleAjaxError(jqXHR, statusText, errorThrown, 'getPatientEdCategories');20 }21 });2223}2425function parseAndDisplaypatEdCategories(node, fileURL, start, numberOfColumns, numberOfRows, targetRegion, targetDiv, view, titleLength, site, screenFormat) {26 "use strict";27 var divContent = '', screenCount = 0, categoriesPerScreen = numberOfColumns * numberOfRows, count = 0, lineNumber = 0, columnNumber = 1,28 skippedCount = 0, composeURL = '', categoryName = '', urlCategoryName = '', nextStart = parseInt(start, 10) + categoriesPerScreen, nextURL = '', currentScreen,29 nodeLength = $(node).length, startTemp = start, i, nextStartTemp, chaserContent = '', chaserLeftNumber = 0, chaserRightNumber = 0, videosInCategory = 0,30 prefenencesExist = true, prefenenceFlag = false, navigationLegend = '', endCount = 0, prefenenceCount = 0, excludeCategoryArray = '';3132 currentScreen = Math.round((start / categoriesPerScreen) + 1);3334 // 18 - Surgery Pediatric (not in Florida)35 // 54 - Pregnancy-Newborn (not in Florida)36 // 455 - Psychiatry and Psychology (not in Florida)37 // 2356 - Arizona (only)38 // 3127 - Jacksonville (only)39 // 3731 - High Definition (not in Arizona, Rochester)40 // 30164 - Keep Pace4142 if (fileURL.indexOf("993") === -1) {43 if (site === 'RO') {44 excludeCategoryArray = ['2356', '3127', '3731', '30164', '35575'];45 } else if (site === 'AZ') {46 excludeCategoryArray = ['3127', '30164', '35575'];47 } else if (site === 'FL') {48 excludeCategoryArray = ['18', '54', '455', '2356', '3127', '30164', '35575'];49 }50 }5152 $(node).each(function (i, row) {53 if ($(this).attr('name') !== undefined && $(this).attr('bottomCategories') !== 'true' && $.inArray($(this).attr('id'), excludeCategoryArray) === -1) {5455 if (i >= (startTemp) && count < categoriesPerScreen) {56 categoryName = $(this).attr('name');57 if (prefenencesExist && getCookie('pePreferences').indexOf(categoryName) !== -1 && view === 'Adult') {58 prefenenceFlag = true;59 prefenenceCount++;60 } else {61 prefenenceFlag = false;62 }63 count++;64 lineNumber++;65 categoryName = formatCategoryName(categoryName, 28);66 urlCategoryName = categoryName.replace(' & ', ' %26 ');6768 composeURL = 'javascript:ForwardWithIDAndQuery(';69 // alert($(this).attr('hasCategories'));70 if ($(this).attr('hasCategories') === 'true') {71 composeURL += '\'patientEdSubCat.html';72 videosInCategory = $(this).children().children().length - $(this).children().length + 1;73 } else {74 composeURL += '\'patientEdGenre.html';75 videosInCategory = $(this).children().length - 1;76 }77 if (fileURL.indexOf("993") !== -1) {78 composeURL += '?genre=' + 'Frequently%20Viewed' + '&genreID=' + $(this).attr('id');79 composeURL += '&subGenre=' + encodeURI($(this).attr('name')) + '&subGenreID=' + $(this).attr('id');80 composeURL += '&quickPlay=1&view=' + view;81 } else {82 composeURL += '?genre=' + encodeURI($(this).attr('name')) + '&genreID=' + $(this).attr('id') + '&view=' + view;83 }84 composeURL += '\');';8586 // For ICTV, create chaser (arrow key) short-cuts87 chaserContent = '';88 if (columnNumber === 1) { chaserLeftNumber = ((numberOfColumns - 1) * numberOfRows) + count; chaserContent = ' chaser_left=\"link' + chaserLeftNumber + '\"'; }89 if (columnNumber === numberOfColumns) { chaserRightNumber = count - ((numberOfColumns - 1) * numberOfRows); chaserContent = "chaser_right=\"link" + chaserRightNumber + "\""; }9091 // build category URL92 divContent += '<div class=\"lineColumn' + targetRegion + ' lineColumn' + targetRegion + columnNumber + ' linePatEd';93 if (fileURL.indexOf("993") !== -1) {94 divContent += 'FV';95 }96 divContent += lineNumber;97 if (prefenenceFlag) { divContent += ' preferredCategory'; }98 divContent += '\" >';99 divContent += '<a id=\"link' + count + '\" href=\"' + composeURL + '\" class=\"lineItems' + targetRegion + '\" tabIndex=\"' + count + '\"' + chaserContent + '>';100 divContent += categoryName;101 divContent += '</a>';102 // if (prefenenceFlag) { divContent += '<img src=\"../images/icons/star_blue.gif\" />'; }103 divContent += '<span class=videoCount>(' + videosInCategory + ')</span>';104 divContent += '</div>\n';105106 if (fileURL.indexOf("993") !== -1 && screenFormat === 'HD' && $(this).attr('hasCategories') === 'true') {107 // if freq viewed (a.k.a. channel 993), expand sub categories108 $(this).children().each(function (i, row) {109 if ($(this).attr('name') !== undefined) {110 // alert($(this).attr('id') + ' | ' + $(this).attr('name') + ' | ' + $(this).text());111 count++;112 if (lineNumber >= numberOfRows) { lineNumber = 0; columnNumber++; }113 lineNumber++;114115 composeURL = 'javascript:ForwardWithIDAndQuery(';116 composeURL += '\'patientEdGenre.html';117 composeURL += '?genre=' + encodeURIComponent(urlCategoryName) + '&genreID=90000';118 composeURL += '&subGenre=' + encodeURIComponent($(this).attr('name')) + '&subGenreID=' + $(this).attr('id');119 composeURL += '&quickPlay=1';120 composeURL += '&view=' + view;121 composeURL += '\');';122 divContent += '<div class=\"lineColumn lineColumnIndent lineColumn' + columnNumber + ' lineCategories' + targetRegion + lineNumber + '\" id=\"lineColumn' + lineNumber + '\" onclick=\"' + composeURL + '\" >';123 divContent += ' <img src=\"../images/icons/navbar/li.gif\" /> <a id=\"Button' + lineNumber + '\" href=\"' + composeURL + '\" class=\"lineItems\" tabIndex=\"' + count + '\">';124 divContent += $(this).attr('name');125 divContent += '</a></div>\n';126 }127 });128 }129130 if (lineNumber >= numberOfRows) {131 // if column is full, move to next column132 lineNumber = 0;133 columnNumber++;134 }135 if (count === categoriesPerScreen) {136 // if no more categories can be displayed, stop processing137 return false;138 }139140 }141 } else {142 skippedCount++;143 if ($(this).attr('name') !== undefined) { startTemp++; }144 }145 });146147 screenCount = Math.round(parseFloat(((nodeLength - skippedCount) / categoriesPerScreen)) + 0.49);148149 if (screenCount > 1 && currentScreen !== screenCount) {150 // if more than one screen of categories exist, display navigation elements151 nextStartTemp = nextStart;152 nextURL = 'javascript:ForwardWithID(\'index.html?start=' + nextStartTemp + '&view=' + view + '\');';153 setTimeout(function () { createNextScreenButton(nextURL, screenFormat); }, 500);154155 divContent += '<div class=\"screenBulletIndicatorPE\">';156 for (i = 1; i < screenCount + 1; i++) {157 if (i === currentScreen) {158 divContent += '<img src=\"../images/icons/bullets/bullet-selected.gif\" /> ';159 } else {160 divContent += '<img src=\"../images/icons/bullets/bullet.gif\" /> ';161 }162 divContent += ' ';163 }164 divContent += '</div>';165 } else {166 // since there is only one screen of categories, remove 'Next' button167 setTimeout(function () { $('#navbarNext').html(''); }, 500);168 }169 if (fileURL.indexOf("993") === -1) {170 endCount = count + parseInt(start, 10) - 1;171 navigationLegend = start + '-' + endCount + ' of ';172 navigationLegend += nodeLength - skippedCount + ' categories';173 $('#itemCount').html(navigationLegend);174 }175 $('#' + targetDiv).append(divContent);176 $('#ajaxLoader').html('');177
...
url-common.app-test.js
Source:url-common.app-test.js
...27 composeUrl.defaultOptions = initialOptions;28 });29 it("allows for no parameters", () => {30 const expected = `${rootUrl}/`;31 expect(composeUrl()).to.equal(expected);32 });33 it("allows for an optional path", () => {34 const expected = `${rootUrl}/${path}`;35 expect(composeUrl(path)).to.equal(expected);36 });37 it("allows for optional options", () => {38 const options = {};39 const expected = `${rootUrl}/`;40 expect(composeUrl(options)).to.equal(expected);41 });42 it("requires a root url", () => {43 const options = {44 rootUrl: null45 };46 expect(() => composeUrl(options))47 .to.throw(/Must pass options\.rootUrl or set ROOT_URL/);48 });49 it("prepends http: when not provided", () => {50 const host = `${randomString()}.reactioncommerce.com`;51 const options = {52 rootUrl: host53 };54 const expected = `http://${host}/`;55 expect(composeUrl(options)).to.equal(expected);56 });57 it("does not prepend http: if rootUrl begins with https", () => {58 const host = `https://${randomString()}.reactioncommerce.com`;59 const options = {60 rootUrl: host61 };62 const expected = `${host}/`;63 expect(composeUrl(options)).to.equal(expected);64 });65 it("uses https with the `secure` option", () => {66 const host = `${randomString()}.reactioncommerce.com`;67 const options = {68 rootUrl: host,69 secure: true70 };71 const expected = `https://${host}/`;72 expect(composeUrl(options)).to.equal(expected);73 });74 it("uses https with the `secure` option, unless localhost", () => {75 const host = "localhost";76 const options = {77 rootUrl: host,78 secure: true79 };80 const expected = `http://${host}/`;81 expect(composeUrl(options)).to.equal(expected);82 });83 it("uses https with the `secure` option, unless 127.0.0.1", () => {84 const host = "127.0.0.1";85 const options = {86 rootUrl: host,87 secure: true88 };89 const expected = `http://${host}/`;90 expect(composeUrl(options)).to.equal(expected);91 });92 it("replaces localhost with IP with `replaceLocalhost` option", () => {93 const host = "localhost";94 const options = {95 replaceLocalhost: true,96 rootUrl: host,97 secure: true98 };99 const expected = "http://127.0.0.1/";100 expect(composeUrl(options)).to.equal(expected);101 });102 describe("with global settings", () => {103 it("honors the global setting `rootUrl`", () => {104 composeUrl.defaultOptions.rootUrl = rootUrl;105 const expected = `${rootUrl}/${path}`;106 expect(composeUrl(path)).to.equal(expected);107 });108 it("honors the global setting `secure`", () => {109 composeUrl.defaultOptions.secure = true;110 const expected =111 `${rootUrl}/${path}`.replace(/^http:\/\//, "https://");112 expect(composeUrl(path)).to.equal(expected);113 });114 it("honors the global setting `replaceLocalhost`", () => {115 composeUrl.defaultOptions.replaceLocalhost = true;116 const options = {117 rootUrl: "localhost"118 };119 const expected = `http://127.0.0.1/${path}`;120 expect(composeUrl(path, options)).to.equal(expected);121 });122 });123 });124 function randomString() {125 return Math.random().toString(36);126 }...
getPatEdFavCategories.js
Source:getPatEdFavCategories.js
1/*jslint browser: true*/2/*global $, jQuery, alert, console, document, getCookie, getSite, formatCategoryName */34function getPatientEdFavCategories(start, pePreferences, targetRegion, targetDiv, site, screenFormat) {5 "use strict";6 var divContent = '', columnNumber = 2, lineNumber = 6, composeURL = 'javascript:ForwardWithIDAndQuery(\'patientEdSubCat.html', siteArray, i = 0, linkID = 0;78 if (site === 'RO') {9 if (screenFormat === 'HD') {10 columnNumber = 2;11 lineNumber = 7;12 linkID = 35;13 targetRegion = targetRegion + 'Wide';14 } else {15 linkID = 14;16 }1718 siteArray = pePreferences.split(',');1920 if (siteArray.length !== 1) {21 for (i = 0; i < siteArray.length; i++) {22 lineNumber++;23 composeURL = 'javascript:ForwardWithIDAndQuery(\'patientEdSubCat.html';24 composeURL += '?genre=' + encodeURI(siteArray[i]) + '&view=All';25 composeURL += '\');';26 divContent += '<div class=\"lineColumnMainPreferred lineColumn' + targetRegion + columnNumber + ' linePatEdFV' + lineNumber + ' preferredCategory\" >';27 divContent += '<a id=\"link' + linkID + '\" href=\"' + composeURL + '\" class=\"lineItems' + targetRegion + '\" tabIndex=\"' + start + '\"' + '>';28 divContent += formatCategoryName(siteArray[i], 28);29 divContent += ' <img src=\"../images/icons/star_blue.gif\" id=\"FavIcon\" align=\"middle\" />';30 divContent += '</a>';31 divContent += '</div>\n';32 linkID++;33 }34 if (siteArray.length !== 0) {35 if (screenFormat === 'SD') {36 divContent = '<div class=\"lineColumnMain lineColumnMain2 lineCategoriesMain6 preferredCategoriesLabel\" id=\"preferredCategoriesLabel\">Channel 999 Preferred Categories</div>' + divContent;37 } else {38 divContent = '<span class=\"ch999preferences\"><div class=\"lineColumnMain lineColumnMainWide2 lineCategoriesMain7 preferredCategoriesLabel\">Channel 999 Preferred Categories <img src=\"../images/icons/star_blue.gif\" /></div></span>' + divContent;39 }40 $('#' + targetDiv).append(divContent);41 }42 }43 }44}4546function getPatientEdFavCategoriesMain(start, pePreferences, targetRegion, targetDiv, site, screenFormat) {47 "use strict";48 var divContent = '', columnNumber = 1, lineNumber = 0, composeURL = 'javascript:ForwardWithIDAndQuery(\'patientEdSubCat.html', siteArray, i = 0, linkID = 0, targetRegion2 = 'linePE';4950 if (site === 'RO') {51 if (screenFormat === 'HD') {52 linkID = 35;53 targetRegion = targetRegion + 'Wide';54 targetRegion2 = 'lineLarge';55 } else {56 linkID = 14;57 }5859 siteArray = pePreferences.split(',');6061 if (siteArray.length !== 1) {62 for (i = 0; i < siteArray.length; i++) {63 lineNumber++;64 composeURL = 'javascript:ForwardWithIDAndQuery(\'patientEdSubCat.html';65 composeURL += '?genre=' + encodeURI(siteArray[i]) + '&view=All';66 composeURL += '\');';67 divContent += '<div class=\"lineColumnMain lineColumn' + targetRegion + columnNumber + ' ' + targetRegion2 + lineNumber + '\" >';68 divContent += '<a id=\"link' + lineNumber + '\" href=\"' + composeURL + '\" class=\"lineItems' + targetRegion + '\" tabIndex=\"' + lineNumber + '\"' + '>';69 divContent += formatCategoryName(siteArray[i], 28);70 divContent += '</a>';71 if (navigator.userAgent.indexOf("MSIE") != -1) {72 divContent += ' <img src=\"../images/icons/star_blue.gif\" align=\"middle\" />';73 } else {74 divContent += ' <img src=\"../images/icons/star_blue.gif\" />';75 }76 divContent += '</div>\n';77 linkID++;78 } // alert(divContent);79 return divContent;80 }81 }
...
domains.test.js
Source:domains.test.js
1jest.mock("/lib/core/url-common");2import { composeUrl } from "/lib/core/url-common";3import { DomainsMixin } from "./domains";4describe("DomainsMixin", () => {5 let path;6 let connectionHost;7 beforeEach(() => {8 // commonly used test vars9 path = randomString();10 connectionHost = `${randomString()}.reactioncommerce.com`;11 });12 describe("#absoluteUrl", () => {13 beforeEach(() => {14 // mocking $ROOT_URL15 const ROOT_URL = `https://${randomString()}.reactioncommerce.com`;16 if (!composeUrl.defaultOptions) {17 composeUrl.defaultOptions = {};18 }19 composeUrl.defaultOptions.rootUrl = ROOT_URL;20 });21 describe("before the domain is set", () => {22 test("wraps composeUrl without parameters", () => {23 DomainsMixin.absoluteUrl();24 expect(composeUrl).toHaveBeenCalledWith(undefined, {});25 });26 test("wraps composeUrl with path only", () => {27 DomainsMixin.absoluteUrl(path);28 expect(composeUrl).toHaveBeenCalledWith(path, {});29 });30 test("wraps composeUrl with options only", () => {31 const options = { a: 1, b: 2 };32 DomainsMixin.absoluteUrl(options);33 expect(composeUrl).toHaveBeenCalledWith(undefined, options);34 });35 test("wraps composeUrl both a path and options", () => {36 const options = { a: 1, b: 2 };37 DomainsMixin.absoluteUrl(path, options);38 expect(composeUrl).toHaveBeenCalledWith(path, options);39 });40 });41 describe("within the domain set", () => {42 beforeEach(() => {43 jest.spyOn(DomainsMixin, "shopDomain").mockReturnValue(connectionHost);44 DomainsMixin.absoluteUrl();45 });46 test("uses the current connection's host", () => {47 expect(composeUrl)48 .toHaveBeenCalledWith(undefined, expect.objectContaining({49 rootUrl: expect.stringContaining(connectionHost)50 }));51 });52 test("uses $ROOT_URL's protocol/scheme", () => {53 // this would he http:// if $ROOT_URL had not used https://54 expect(composeUrl)55 .toHaveBeenCalledWith(undefined, expect.objectContaining({56 rootUrl: expect.stringMatching(/^https:\/\//)57 }));58 });59 });60 });61 describe("#getDomain", () => {62 test("returns the domain portion of absoluteUrl", () => {63 jest.spyOn(DomainsMixin, "absoluteUrl")64 .mockReturnValue(`https://${connectionHost}:80/${path}`);65 expect(DomainsMixin.getDomain())66 .toEqual(connectionHost);67 });68 });69 function randomString() {70 return Math.random().toString(36);71 }...
sling.js
Source:sling.js
1const Q = require('q');2const Sling = require("./../modules/sling.js");3const Test = require("./../modules/test.js");4module.exports.name = "sling";5module.exports = function(promiseArray) {6 Run(promiseArray);7 return;8}9const Run = function(promiseArray) {10 promiseArray.push(Q().then(function(input){11 var result = Sling("");12 Test.DealTest("resourcePath", result.GetResourcePath(), "");13 Test.DealTest("selector", result.HasSelector("z"), false);14 Test.DealTest("selector", result.GetSelector("z"), "");15 Test.DealTest("extension", result.GetExtension(), "");16 Test.DealTest("suffix", result.GetSuffix(), "");17 Test.DealTest("parameter", result.GetParameter("y"), "");18 Test.DealTest("ComposeURL", result.ComposeURL(), ".");19 result = Sling("index.lc=en.s=5.html");20 Test.DealTest("resourcePath", result.GetResourcePath(), "index");21 Test.DealTest("selector", result.GetSelector("lc"), "en");22 Test.DealTest("selector", result.GetSelector("s"), "5");23 Test.DealTest("selector", result.GetSelector("z"), "");24 Test.DealTest("extension", result.GetExtension(), "html");25 Test.DealTest("suffix", result.GetSuffix(), "");26 var temp = result.ComposeURL();27 Test.DealTest("ComposeURL", result.ComposeURL(), "index.lc=en.s=5.html");28 var temp = result.ComposeResourcePathExtension();29 Test.DealTest("ComposeURL", temp, "index.html");30 result = Sling("/a/b.s1.s2.html/c/d.s.txt");31 Test.DealTest("resourcePath", result.GetResourcePath(), "/a/b");32 Test.DealTest("selector", result.HasSelector("s1"), true);33 Test.DealTest("selector", result.HasSelector("s2"), true);34 Test.DealTest("extension", result.GetExtension(), "html");35 Test.DealTest("suffix", result.GetSuffix(), "/c/d.s.txt");36 var temp = result.ComposeURL();37 Test.DealTest("ComposeURL", result.ComposeURL(), "/a/b.s1.s2.html/c/d.s.txt");38 result = Sling("/index?hello=0&world=1");39 Test.DealTest("resourcePath", result.GetResourcePath(), "/index");40 Test.DealTest("extension", result.GetExtension(), "");41 Test.DealTest("suffix", result.GetSuffix(), "");42 Test.DealTest("parameter", result.GetParameter("hello"), "0");43 Test.DealTest("parameter", result.GetParameter("world"), "1");44 var temp = result.ComposeURL();45 Test.DealTest("ComposeURL", result.ComposeURL(), "/index.?hello=0&world=1");46 }));47 return;...
use-axios.test.js
Source:use-axios.test.js
...13 expect(res).toBe(false);14 }),15 );16 });17 describe('composeUrl()', () => {18 it(`should remove duplicate "/" from a url`, () => {19 expect(composeUrl('http://foo/', '/bar')).toBe('http://foo/bar');20 expect(composeUrl('http://', '/foobar')).toBe('http://foobar');21 expect(composeUrl('http://', 'foobar')).toBe('http://foobar');22 expect(composeUrl('/', '/foobar')).toBe('/foobar');23 expect(composeUrl('', '//foobar')).toBe('/foobar');24 expect(composeUrl('http://foo/', '/bar/', '/tee')).toBe(25 'http://foo/bar/tee',26 );27 expect(composeUrl('http://foo/', '/bar/', '/tee//')).toBe(28 'http://foo/bar/tee/',29 );30 });31 });...
SEO.test.js
Source:SEO.test.js
2import { __test__ } from './SEO'3const { composeUrl } = __test__4const baseUrl = 'https://apptiva.ch'5test('Slug "foo"', t => {6 const actual = composeUrl(baseUrl, 'foo')7 t.is(actual, 'https://apptiva.ch/foo/')8})9test('Slug "/foo"', t => {10 const actual = composeUrl(baseUrl, '/foo')11 t.is(actual, 'https://apptiva.ch/foo/')12})13test('Slug "foo/"', t => {14 const actual = composeUrl(baseUrl, 'foo/')15 t.is(actual, 'https://apptiva.ch/foo/')16})17test('Slug "/foo/"', t => {18 const actual = composeUrl(baseUrl, '/foo/')19 t.is(actual, 'https://apptiva.ch/foo/')20})21test('Slug "/"', t => {22 const actual = composeUrl(baseUrl, '/')23 t.is(actual, 'https://apptiva.ch/')24})25test('Empty slug', t => {26 const actual = composeUrl(baseUrl, '')27 t.is(actual, 'https://apptiva.ch/')28})29test('Undefined slug', t => {30 const actual = composeUrl(baseUrl, undefined)31 t.is(actual, 'https://apptiva.ch/')32})33test('null slug', t => {34 const actual = composeUrl(baseUrl, null)35 t.is(actual, 'https://apptiva.ch/')...
Using AI Code Generation
1var karma = require('karma').server;2var path = require('path');3karma.start({4 configFile: path.resolve('karma.conf.js'),5}, function(exitCode) {6 console.log('Karma has exited with ' + exitCode);7 process.exit(exitCode);8});9module.exports = function(config) {10 config.set({11 preprocessors: {12 },13 coverageReporter: {14 },15 })16}
Using AI Code Generation
1var karma = require('karma');2console.log(karma.composeUrl('/base', 'test.js'));3var karma = require('karma');4console.log(karma.composeUrl('/base', '/base/test.js'));5var karma = require('karma');6console.log(karma.composeUrl('/base', '/base/test.js'));7var karma = require('karma');8console.log(karma.composeUrl('/base', '/base/test.js'));9var karma = require('karma');10console.log(karma.composeUrl('/base', '/base/test.js'));11var karma = require('karma');12console.log(karma.composeUrl('/base', '/base/test.js'));13var karma = require('karma');14console.log(karma.composeUrl('/base', '/base/test.js'));15var karma = require('karma');16console.log(karma.composeUrl('/base', '/base/test.js'));17var karma = require('karma');18console.log(karma.composeUrl('/base', '/base/test.js'));19var karma = require('karma');20console.log(karma.composeUrl('/base', '/base/test.js'));21var karma = require('karma');22console.log(karma.composeUrl('/base', '/base/test
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!!