How to use attributes method in ng-mocks

Best JavaScript code snippet using ng-mocks

extensions.js

Source:extensions.js Github

copy

Full Screen

1$.fn.ajx = function(attributes){2 var type = 'POST';3 var url = $(this).data('url');4 var data = $(this).data('params');5 var dataType = 'json';6 var cache = true;7 var beforeSend = function(){};8 var success = function(json){};9 var complete = function(){};10 var error = function(){};11 var updateId = $(this).data('update');12 var parent = $(this).data('parent');13 var closest = $(this).data('closest');14 var formId = $(this).data('form');15 var addId = $(this).data('add');16 if(typeof attributes != 'undefined'){17 if(typeof attributes.type != 'undefined')18 type = attributes.type;19 if(typeof attributes.url != 'undefined')20 url = attributes.url;21 if(typeof attributes.data != 'undefined')22 data = attributes.data;23 if(typeof attributes.dataType != 'undefined')24 dataType = attributes.dataType;25 if(typeof attributes.cache != 'undefined')26 cache = attributes.cache;27 if(typeof attributes.beforeSend != 'undefined')28 beforeSend = attributes.beforeSend;29 if(typeof attributes.success != 'undefined')30 success = attributes.success;31 if(typeof attributes.complete != 'undefined')32 complete = attributes.complete;33 if(typeof attributes.error != 'undefined')34 error = attributes.error;35 if(typeof attributes.updateId != 'undefined')36 updateId = attributes.updateId;37 if(typeof attributes.formId != 'undefined')38 formId = attributes.formId;39 if(typeof attributes.addId != 'undefined')40 addId = attributes.addId;41 }42 if(typeof updateId == 'undefined'){43 if(typeof parent != 'undefined')44 updateId = $(this).parent(parent);45 if(typeof closest != 'undefined')46 updateId = $(this).closest(closest);47 }48 if(typeof data == 'undefined')49 data = 'name=value';50 if(typeof formId != 'undefined' && formId){51 var form;52 if(formId == 1)53 form = $(this).closest('form');54 else55 form = $(formId);56 if(form.length)57 data += '&'+form.serialize();58 }59 $.ajax({60 type: type,61 url: url,62 data: data,63 dataType: dataType,64 cache: cache,65 beforeSend: function(){66 Main.beforeAjax();67 beforeSend();68 },69 success: function(json){70 Main.successAjax(json, updateId, addId);71 success(json);72 },73 complete: function(){74 Main.afterAjax();75 complete();76 },77 error: function(XMLHttpRequest, textStatus, errorThrown){78 Main.errorAjax(errorThrown);79 error();80 }81 });82};83$.fn.serializeObject = function() {84 var o = {};85 var a = this.serializeArray();86 $.each(a, function() {87 if (o[this.name]) {88 if (!o[this.name].push) {89 o[this.name] = [o[this.name]];90 }91 o[this.name].push(this.value || '');92 } else {93 o[this.name] = this.value || '';94 }95 });96 return o;97};98$.fn.modalWindow = function(attributes){99 var autoOpen = false;100 var submit = null;101 var modalId = Main.modalId;102 var content = $(this).data('content');103 var url = $(this).data('url');104 var title = $(this).data('title');105 var okButtonText = $(this).data('okbutton');106 var cancelButtonText = $(this).data('cancelbutton');107 var noContent = $(this).data('nocontent');108 var noSubmit = $(this).data('nosubmit');109 var noCancel = $(this).data('nocancel');110 var notShowSubmit = $(this).data('notshowsubmit');111 var closeId = Main.modalCloseId;112 var modalOk = Main.modalOkId;113 var modalCancel = Main.modalCancelId;114 var modalContent = Main.modalContentId;115 var modalTitle = Main.modalTitleId;116 var form = $(this).data('form');117 if(typeof attributes != 'undefined'){118 if(typeof attributes == 'string'){119 if(attributes == 'close'){120 $(modalId).addClass('modal');121 $(modalId).addClass('fade');122 }123 }else{124 if(typeof attributes.autoOpen != 'undefined')125 autoOpen = attributes.autoOpen;126 if(typeof attributes.submit != 'undefined')127 submit = attributes.submit;128 if(typeof attributes.modalId != 'undefined')129 modalId = attributes.modalId;130 if(typeof attributes.content != 'undefined')131 content = attributes.content;132 if(typeof attributes.url != 'undefined')133 url = attributes.url;134 if(typeof attributes.okButtonText != 'undefined')135 okButtonText = attributes.okButtonText;136 if(typeof attributes.cancelButtonText != 'undefined')137 cancelButtonText = attributes.cancelButtonText;138 if(typeof attributes.title != 'undefined')139 title = attributes.title;140 if(typeof attributes.closeId != 'undefined')141 closeId = attributes.closeId;142 if(typeof attributes.noContent != 'undefined')143 noContent = attributes.noContent;144 if(typeof attributes.noSubmit != 'undefined')145 noSubmit = attributes.noSubmit;146 if(typeof attributes.noCancel != 'undefined')147 noCancel = attributes.noCancel;148 if(typeof attributes.noSubmit != 'undefined')149 noSubmit = attributes.notShowSubmit;150 if(typeof attributes.notShowSubmit != 'undefined')151 notShowSubmit = attributes.notShowSubmit;152 if(typeof attributes.modalCancel != 'undefined')153 modalCancel = attributes.modalCancel;154 if(typeof attributes.modalContent != 'undefined')155 modalContent = attributes.modalContent;156 if(typeof attributes.modalTitle != 'undefined')157 modalTitle = attributes.modalTitle;158 if(typeof attributes.form != 'undefined')159 form = attributes.form;160 }161 }162 if(typeof notShowSubmit != 'undefined' && notShowSubmit)163 $(modalOk).addClass('hide');164 if(typeof noSubmit == 'undefined' || noSubmit == '0' || !noSubmit)165 noSubmit = false;166 else167 noSubmit = true;168 if(typeof noCancel == 'undefined' || noCancel == '0' || !noCancel)169 noCancel = false;170 else171 noCancel = true;172 function openModal(){173 if(typeof title != 'undefined' && title){174 $(modalTitle).html(title);175 }176 if(typeof okButtonText != 'undefined' && okButtonText){177 $(modalOk).html(okButtonText);178 }179 if(typeof cancelButtonText != 'undefined' && cancelButtonText){180 $(modalCancel).html(cancelButtonText);181 }182 var contentHtml = $(content);183 if(contentHtml.length)184 contentHtml = $(content).html();185 else186 contentHtml = content;187 if(contentHtml && !noContent){188 $(modalContent).html(contentHtml);189 var modalWindow = $(modalId);190 modalWindow.removeClass('modal');191 modalWindow.removeClass('fade');192 }193 var realForm;194 if(typeof form != 'undefined' && form)195 realForm = $(form);196 else197 realForm = $(modalId+' form');198 if(realForm.length && !noSubmit && submit == null){199 $(modalOk).on('click', function(){200 realForm.submit();201 });202 }203 if(submit != null && typeof submit == 'function'){204 $(modalOk).on('click', function(){205 submit($(this));206 });207 }208 if(!noSubmit){209 if(typeof url != 'undefined' && url){210 document.location.href = url;211 }else{212 $(modalOk).on('click', function(){213 $(modalId).addClass('modal');214 $(modalId).addClass('fade');215 });216 }217 }218 $(closeId).on('click', function(){219 $(modalId).addClass('modal');220 $(modalId).addClass('fade');221 });222 if(!noCancel){223 $(modalCancel).on('click', function(){224 $(modalId).addClass('modal');225 $(modalId).addClass('fade');226 });227 }228 }229 $(this).on('click', function(){230 openModal();231 return false;232 });233 if(autoOpen){234 openModal();235 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1/**2 * Internal dependencies3 */4import {5 getAttributes,6 getVariationAttributes,7 getVariationsMatchingSelectedAttributes,8 getVariationMatchingSelectedAttributes,9 getActiveSelectControlOptions,10} from '../utils';11const rawAttributeData = [12 {13 id: 1,14 name: 'Color',15 taxonomy: 'pa_color',16 has_variations: true,17 terms: [18 {19 id: 22,20 name: 'Blue',21 slug: 'blue',22 },23 {24 id: 23,25 name: 'Green',26 slug: 'green',27 },28 {29 id: 24,30 name: 'Red',31 slug: 'red',32 },33 ],34 },35 {36 id: 0,37 name: 'Logo',38 taxonomy: null,39 has_variations: true,40 terms: [41 {42 id: 0,43 name: 'Yes',44 slug: 'Yes',45 },46 {47 id: 0,48 name: 'No',49 slug: 'No',50 },51 ],52 },53 {54 id: 0,55 name: 'Non-variable attribute',56 taxonomy: null,57 has_variations: false,58 terms: [59 {60 id: 0,61 name: 'Test',62 slug: 'Test',63 },64 {65 id: 0,66 name: 'Test 2',67 slug: 'Test 2',68 },69 ],70 },71];72const rawVariations = [73 {74 id: 35,75 attributes: [76 {77 name: 'Color',78 value: 'blue',79 },80 {81 name: 'Logo',82 value: 'Yes',83 },84 ],85 },86 {87 id: 28,88 attributes: [89 {90 name: 'Color',91 value: 'red',92 },93 {94 name: 'Logo',95 value: 'No',96 },97 ],98 },99 {100 id: 29,101 attributes: [102 {103 name: 'Color',104 value: 'green',105 },106 {107 name: 'Logo',108 value: 'No',109 },110 ],111 },112 {113 id: 30,114 attributes: [115 {116 name: 'Color',117 value: 'blue',118 },119 {120 name: 'Logo',121 value: 'No',122 },123 ],124 },125];126describe( 'Testing utils', () => {127 describe( 'Testing getAttributes()', () => {128 it( 'returns empty object if there are no attributes', () => {129 const attributes = getAttributes( null );130 expect( attributes ).toStrictEqual( {} );131 } );132 it( 'returns list of attributes when given valid data', () => {133 const attributes = getAttributes( rawAttributeData );134 expect( attributes ).toStrictEqual( {135 Color: {136 id: 1,137 name: 'Color',138 taxonomy: 'pa_color',139 has_variations: true,140 terms: [141 {142 id: 22,143 name: 'Blue',144 slug: 'blue',145 },146 {147 id: 23,148 name: 'Green',149 slug: 'green',150 },151 {152 id: 24,153 name: 'Red',154 slug: 'red',155 },156 ],157 },158 Logo: {159 id: 0,160 name: 'Logo',161 taxonomy: null,162 has_variations: true,163 terms: [164 {165 id: 0,166 name: 'Yes',167 slug: 'Yes',168 },169 {170 id: 0,171 name: 'No',172 slug: 'No',173 },174 ],175 },176 } );177 } );178 } );179 describe( 'Testing getVariationAttributes()', () => {180 it( 'returns empty object if there are no variations', () => {181 const variationAttributes = getVariationAttributes( null );182 expect( variationAttributes ).toStrictEqual( {} );183 } );184 it( 'returns list of attribute names and value pairs when given valid data', () => {185 const variationAttributes = getVariationAttributes( rawVariations );186 expect( variationAttributes ).toStrictEqual( {187 'id:35': {188 id: 35,189 attributes: {190 Color: 'blue',191 Logo: 'Yes',192 },193 },194 'id:28': {195 id: 28,196 attributes: {197 Color: 'red',198 Logo: 'No',199 },200 },201 'id:29': {202 id: 29,203 attributes: {204 Color: 'green',205 Logo: 'No',206 },207 },208 'id:30': {209 id: 30,210 attributes: {211 Color: 'blue',212 Logo: 'No',213 },214 },215 } );216 } );217 } );218 describe( 'Testing getVariationsMatchingSelectedAttributes()', () => {219 const attributes = getAttributes( rawAttributeData );220 const variationAttributes = getVariationAttributes( rawVariations );221 it( 'returns all variations, in the correct order, if no selections have been made yet', () => {222 const selectedAttributes = {};223 const matches = getVariationsMatchingSelectedAttributes(224 attributes,225 variationAttributes,226 selectedAttributes227 );228 expect( matches ).toStrictEqual( [ 35, 28, 29, 30 ] );229 } );230 it( 'returns correct subset of variations after a selection', () => {231 const selectedAttributes = {232 Color: 'blue',233 };234 const matches = getVariationsMatchingSelectedAttributes(235 attributes,236 variationAttributes,237 selectedAttributes238 );239 expect( matches ).toStrictEqual( [ 35, 30 ] );240 } );241 it( 'returns correct subset of variations after all selections', () => {242 const selectedAttributes = {243 Color: 'blue',244 Logo: 'No',245 };246 const matches = getVariationsMatchingSelectedAttributes(247 attributes,248 variationAttributes,249 selectedAttributes250 );251 expect( matches ).toStrictEqual( [ 30 ] );252 } );253 it( 'returns no results if selection does not match or is invalid', () => {254 const selectedAttributes = {255 Color: 'brown',256 };257 const matches = getVariationsMatchingSelectedAttributes(258 attributes,259 variationAttributes,260 selectedAttributes261 );262 expect( matches ).toStrictEqual( [] );263 } );264 } );265 describe( 'Testing getVariationMatchingSelectedAttributes()', () => {266 const attributes = getAttributes( rawAttributeData );267 const variationAttributes = getVariationAttributes( rawVariations );268 it( 'returns first match if no selections have been made yet', () => {269 const selectedAttributes = {};270 const matches = getVariationMatchingSelectedAttributes(271 attributes,272 variationAttributes,273 selectedAttributes274 );275 expect( matches ).toStrictEqual( 35 );276 } );277 it( 'returns first match after single selection', () => {278 const selectedAttributes = {279 Color: 'blue',280 };281 const matches = getVariationMatchingSelectedAttributes(282 attributes,283 variationAttributes,284 selectedAttributes285 );286 expect( matches ).toStrictEqual( 35 );287 } );288 it( 'returns correct match after all selections', () => {289 const selectedAttributes = {290 Color: 'blue',291 Logo: 'No',292 };293 const matches = getVariationMatchingSelectedAttributes(294 attributes,295 variationAttributes,296 selectedAttributes297 );298 expect( matches ).toStrictEqual( 30 );299 } );300 it( 'returns no match if invalid', () => {301 const selectedAttributes = {302 Color: 'brown',303 };304 const matches = getVariationMatchingSelectedAttributes(305 attributes,306 variationAttributes,307 selectedAttributes308 );309 expect( matches ).toStrictEqual( 0 );310 } );311 } );312 describe( 'Testing getActiveSelectControlOptions()', () => {313 const attributes = getAttributes( rawAttributeData );314 const variationAttributes = getVariationAttributes( rawVariations );315 it( 'returns all possible options if no selections have been made yet', () => {316 const selectedAttributes = {};317 const controlOptions = getActiveSelectControlOptions(318 attributes,319 variationAttributes,320 selectedAttributes321 );322 expect( controlOptions ).toStrictEqual( {323 Color: [324 {325 value: 'blue',326 label: 'Blue',327 },328 {329 value: 'green',330 label: 'Green',331 },332 {333 value: 'red',334 label: 'Red',335 },336 ],337 Logo: [338 {339 value: 'Yes',340 label: 'Yes',341 },342 {343 value: 'No',344 label: 'No',345 },346 ],347 } );348 } );349 it( 'returns only valid options if color is selected', () => {350 const selectedAttributes = {351 Color: 'green',352 };353 const controlOptions = getActiveSelectControlOptions(354 attributes,355 variationAttributes,356 selectedAttributes357 );358 expect( controlOptions ).toStrictEqual( {359 Color: [360 {361 value: 'blue',362 label: 'Blue',363 },364 {365 value: 'green',366 label: 'Green',367 },368 {369 value: 'red',370 label: 'Red',371 },372 ],373 Logo: [374 {375 value: 'No',376 label: 'No',377 },378 ],379 } );380 } );381 } );...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1/**2 * External dependencies3 */4import { keyBy } from 'lodash';5import { decodeEntities } from '@wordpress/html-entities';6/**7 * Key an array of attributes by name,8 *9 * @param {Object} attributes Attributes array.10 */11export const getAttributes = ( attributes ) => {12 return attributes13 ? keyBy(14 Object.values( attributes ).filter(15 ( { has_variations: hasVariations } ) => hasVariations16 ),17 'name'18 )19 : {};20};21/**22 * Format variations from the API into a map of just the attribute names and values.23 *24 * Note, each item is keyed by the variation ID with an id: prefix. This is to prevent the object25 * being reordered when iterated.26 *27 * @param {Object} variations List of Variation objects and attributes keyed by variation ID.28 */29export const getVariationAttributes = ( variations ) => {30 if ( ! variations ) {31 return {};32 }33 const attributesMap = {};34 variations.forEach( ( { id, attributes } ) => {35 attributesMap[ `id:${ id }` ] = {36 id,37 attributes: attributes.reduce( ( acc, { name, value } ) => {38 acc[ name ] = value;39 return acc;40 }, {} ),41 };42 } );43 return attributesMap;44};45/**46 * Given a list of variations and a list of attribute values, return variations which match.47 *48 * Allows an attribute to be excluded by name. This is used to filter displayed options for49 * individual attribute selects.50 *51 * @param {Object} attributes List of attribute names and terms.52 * @param {Object} variationAttributes Attributes for each variation keyed by variation ID.53 * @param {Object} selectedAttributes Attribute Name Value pairs of current selections by the user.54 * @return {Array} List of matching variation IDs.55 */56export const getVariationsMatchingSelectedAttributes = (57 attributes,58 variationAttributes,59 selectedAttributes60) => {61 const variationIds = Object.values( variationAttributes ).map(62 ( { id: variationId } ) => {63 return variationId;64 }65 );66 // If nothing is selected yet, just return all variations.67 if (68 Object.values( selectedAttributes ).every( ( value ) => value === '' )69 ) {70 return variationIds;71 }72 const attributeNames = Object.keys( attributes );73 return variationIds.filter( ( variationId ) =>74 attributeNames.every( ( attributeName ) => {75 const selectedAttribute = selectedAttributes[ attributeName ] || '';76 const variationAttribute =77 variationAttributes[ 'id:' + variationId ].attributes[78 attributeName79 ];80 // If there is no selected attribute, consider this a match.81 if ( selectedAttribute === '' ) {82 return true;83 }84 // If the variation attributes for this attribute are set to null, it matches all values.85 if ( variationAttribute === null ) {86 return true;87 }88 // Otherwise, only match if the selected values are the same.89 return variationAttribute === selectedAttribute;90 } )91 );92};93/**94 * Given a list of variations and a list of attribute values, returns the first matched variation ID.95 *96 * @param {Object} attributes List of attribute names and terms.97 * @param {Object} variationAttributes Attributes for each variation keyed by variation ID.98 * @param {Object} selectedAttributes Attribute Name Value pairs of current selections by the user.99 * @return {number} Variation ID.100 */101export const getVariationMatchingSelectedAttributes = (102 attributes,103 variationAttributes,104 selectedAttributes105) => {106 const matchingVariationIds = getVariationsMatchingSelectedAttributes(107 attributes,108 variationAttributes,109 selectedAttributes110 );111 return matchingVariationIds[ 0 ] || 0;112};113/**114 * Given a list of terms, filter them and return valid options for the select boxes.115 *116 * @see getActiveSelectControlOptions117 * @param {Object} attributeTerms List of attribute term objects.118 * @param {?Array} validAttributeTerms Valid values if selections have been made already.119 * @return {Array} Value/Label pairs of select box options.120 */121const getValidSelectControlOptions = (122 attributeTerms,123 validAttributeTerms = null124) => {125 return Object.values( attributeTerms )126 .map( ( { name, slug } ) => {127 if (128 validAttributeTerms === null ||129 validAttributeTerms.includes( null ) ||130 validAttributeTerms.includes( slug )131 ) {132 return {133 value: slug,134 label: decodeEntities( name ),135 };136 }137 return null;138 } )139 .filter( Boolean );140};141/**142 * Given a list of terms, filter them and return active options for the select boxes. This factors in143 * which options should be hidden due to current selections.144 *145 * @param {Object} attributes List of attribute names and terms.146 * @param {Object} variationAttributes Attributes for each variation keyed by variation ID.147 * @param {Object} selectedAttributes Attribute Name Value pairs of current selections by the user.148 * @return {Object} Select box options.149 */150export const getActiveSelectControlOptions = (151 attributes,152 variationAttributes,153 selectedAttributes154) => {155 const options = {};156 const attributeNames = Object.keys( attributes );157 const hasSelectedAttributes =158 Object.values( selectedAttributes ).filter( Boolean ).length > 0;159 attributeNames.forEach( ( attributeName ) => {160 const currentAttribute = attributes[ attributeName ];161 const selectedAttributesExcludingCurrentAttribute = {162 ...selectedAttributes,163 [ attributeName ]: null,164 };165 // This finds matching variations for selected attributes apart from this one. This will be166 // used to get valid attribute terms of the current attribute narrowed down by those matching167 // variation IDs. For example, if I had Large Blue Shirts and Medium Red Shirts, I want to only168 // show Red shirts if Medium is selected.169 const matchingVariationIds = hasSelectedAttributes170 ? getVariationsMatchingSelectedAttributes(171 attributes,172 variationAttributes,173 selectedAttributesExcludingCurrentAttribute174 )175 : null;176 // Uses the above matching variation IDs to get the attributes from just those variations.177 const validAttributeTerms =178 matchingVariationIds !== null179 ? matchingVariationIds.map(180 ( varId ) =>181 variationAttributes[ 'id:' + varId ].attributes[182 attributeName183 ]184 )185 : null;186 // Intersects attributes with valid attributes.187 options[ attributeName ] = getValidSelectControlOptions(188 currentAttribute.terms,189 validAttributeTerms190 );191 } );192 return options;...

Full Screen

Full Screen

theme.js

Source:theme.js Github

copy

Full Screen

1/**2 * @file3 * Theme hooks for the Drupal Bootstrap base theme.4 */5(function ($, Drupal, Bootstrap, Attributes) {6 /**7 * Fallback for theming an icon if the Icon API module is not installed.8 */9 if (!Drupal.icon) Drupal.icon = { bundles: {} };10 if (!Drupal.theme.icon || Drupal.theme.prototype.icon) {11 $.extend(Drupal.theme, /** @lends Drupal.theme */ {12 /**13 * Renders an icon.14 *15 * @param {string} bundle16 * The bundle which the icon belongs to.17 * @param {string} icon18 * The name of the icon to render.19 * @param {object|Attributes} [attributes]20 * An object of attributes to also apply to the icon.21 *22 * @returns {string}23 */24 icon: function (bundle, icon, attributes) {25 if (!Drupal.icon.bundles[bundle]) return '';26 attributes = Attributes.create(attributes).addClass('icon').set('aria-hidden', 'true');27 icon = Drupal.icon.bundles[bundle](icon, attributes);28 return '<span' + attributes + '></span>';29 }30 });31 }32 /**33 * Callback for modifying an icon in the "bootstrap" icon bundle.34 *35 * @param {string} icon36 * The icon being rendered.37 * @param {Attributes} attributes38 * Attributes object for the icon.39 */40 Drupal.icon.bundles.bootstrap = function (icon, attributes) {41 attributes.addClass(['glyphicon', 'glyphicon-' + icon]);42 };43 /**44 * Add necessary theming hooks.45 */46 $.extend(Drupal.theme, /** @lends Drupal.theme */ {47 /**48 * Renders a Bootstrap AJAX glyphicon throbber.49 *50 * @returns {string}51 */52 ajaxThrobber: function () {53 return Drupal.theme('bootstrapIcon', 'refresh', {'class': ['ajax-throbber', 'glyphicon-spin'] });54 },55 /**56 * Renders a button element.57 *58 * @param {object|Attributes} attributes59 * An object of attributes to apply to the button. If it contains one of:60 * - value: The label of the button.61 * - context: The context type of Bootstrap button, can be one of:62 * - default63 * - primary64 * - success65 * - info66 * - warning67 * - danger68 * - link69 *70 * @returns {string}71 */72 button: function (attributes) {73 attributes = Attributes.create(attributes).addClass('btn');74 var context = attributes.get('context', 'default');75 var label = attributes.get('value', '');76 attributes.remove('context').remove('value');77 if (!attributes.hasClass(['btn-default', 'btn-primary', 'btn-success', 'btn-info', 'btn-warning', 'btn-danger', 'btn-link'])) {78 attributes.addClass('btn-' + Bootstrap.checkPlain(context));79 }80 // Attempt to, intelligently, provide a default button "type".81 if (!attributes.exists('type')) {82 attributes.set('type', attributes.hasClass('form-submit') ? 'submit' : 'button');83 }84 return '<button' + attributes + '>' + label + '</button>';85 },86 /**87 * Alias for "button" theme hook.88 *89 * @param {object|Attributes} attributes90 * An object of attributes to apply to the button.91 *92 * @see Drupal.theme.button()93 *94 * @returns {string}95 */96 btn: function (attributes) {97 return Drupal.theme('button', attributes);98 },99 /**100 * Renders a button block element.101 *102 * @param {object|Attributes} attributes103 * An object of attributes to apply to the button.104 *105 * @see Drupal.theme.button()106 *107 * @returns {string}108 */109 'btn-block': function (attributes) {110 return Drupal.theme('button', Attributes.create(attributes).addClass('btn-block'));111 },112 /**113 * Renders a large button element.114 *115 * @param {object|Attributes} attributes116 * An object of attributes to apply to the button.117 *118 * @see Drupal.theme.button()119 *120 * @returns {string}121 */122 'btn-lg': function (attributes) {123 return Drupal.theme('button', Attributes.create(attributes).addClass('btn-lg'));124 },125 /**126 * Renders a small button element.127 *128 * @param {object|Attributes} attributes129 * An object of attributes to apply to the button.130 *131 * @see Drupal.theme.button()132 *133 * @returns {string}134 */135 'btn-sm': function (attributes) {136 return Drupal.theme('button', Attributes.create(attributes).addClass('btn-sm'));137 },138 /**139 * Renders an extra small button element.140 *141 * @param {object|Attributes} attributes142 * An object of attributes to apply to the button.143 *144 * @see Drupal.theme.button()145 *146 * @returns {string}147 */148 'btn-xs': function (attributes) {149 return Drupal.theme('button', Attributes.create(attributes).addClass('btn-xs'));150 },151 /**152 * Renders a glyphicon.153 *154 * @param {string} name155 * The name of the glyphicon.156 * @param {object|Attributes} [attributes]157 * An object of attributes to apply to the icon.158 *159 * @returns {string}160 */161 bootstrapIcon: function (name, attributes) {162 return Drupal.theme('icon', 'bootstrap', name, attributes);163 }164 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';2import { MyComponent } from './my.component';3describe('MyComponent', () => {4 beforeEach(() => MockBuilder(MyComponent));5 it('renders the component', () => {6 const fixture = MockRender(MyComponent);7 expect(ngMocks.formatText(fixture)).toContain('Hello World');8 });9});10import { Component } from '@angular/core';11@Component({12})13export class MyComponent {14 public myAttr = 'value';15}16import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';17import { MyComponent } from './my.component';18describe('MyComponent', () => {19 beforeEach(() => MockBuilder(MyComponent));20 it('renders the component', () => {21 const fixture = MockRender(MyComponent);22 expect(ngMocks.formatHtml(fixture)).toContain(23 );24 });25});26import { Component } from '@angular/core';27@Component({28})29export class MyComponent {30 public myAttr = 'value';31}32import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';33import { MyComponent } from './my.component';34describe('MyComponent', () => {35 beforeEach(() => MockBuilder(MyComponent));36 it('renders the component', () => {37 const fixture = MockRender(MyComponent);38 expect(ngMocks.formatText(fixture)).toContain('Hello World');39 });40});41import { Component } from '@angular/core';42@Component({43})44export class MyComponent {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { attributes } from 'ng-mocks';2const fixture = MockRender(`3`);4const component = MockInstance(fixture.debugElement.componentInstance, {5});6attributes(component).toEqual({7});8attributes(component, {9});10import { MockInstance } from 'ng-mocks';11const fixture = MockRender(`12`);13const component = MockInstance(fixture.debugElement.componentInstance, {14});15attributes(component).toEqual({16});17attributes(component, {18});19import { MockRender } from 'ng-mocks';20const fixture = MockRender(`21`);22const component = MockInstance(fixture.debugElement.componentInstance, {23});24attributes(component).toEqual({25});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('ng-mocks-attributes', () => {2 it('should test attributes method', () => {3 const fixture = MockRender(`4 `);5 const div = fixture.point.componentInstance;6 expect(MockNgAriaController.attributes(div)).toEqual({7 });8 });9});10`MockNgAriaController.attributesBySelector(selector: string): { [key: string]: any }`11describe('ng-mocks-attributes', () => {12 it('should test attributesBySelector method', () => {13 MockRender(`14 `);15 expect(MockNgAriaController.attributesBySelector('div')).toEqual({16 });17 });18});19`MockNgAriaController.attributesByDirective<T>(directive: Type<T>): { [key: string]: any }`20describe('ng-mocks-attributes', () => {21 it('should test attributesByDirective method', () => {22 MockRender(`

Full Screen

Using AI Code Generation

copy

Full Screen

1const mock = ngMocks.find('my-component');2const mock = ngMocks.find(MyComponent);3const mock = ngMocks.find(MyComponent, 'my-component');4const mock = ngMocks.find(MyComponent, { selector: 'my-component' });5const mock = ngMocks.find(MyComponent, { selector: 'my-component', inputs: { name: 'value' } });6const mock = ngMocks.find(MyComponent, { selector: 'my-component', inputs: { name: 'value' }, outputs: { name: 'value' } });7const mock = ngMocks.find(MyComponent, { selector: 'my-component', inputs: { name: 'value' }, outputs: { name: 'value' }, exportAs: 'name' });8const mock = ngMocks.find(MyComponent, { selector: 'my-component', inputs: { name: 'value' }, outputs: { name: 'value' }, exportAs: 'name', changeDetection: ChangeDetectionStrategy.Default });9const mock = ngMocks.find(MyComponent, { selector: 'my-component', inputs: { name: 'value' }, outputs: { name: 'value' }, exportAs: 'name', changeDetection: ChangeDetectionStrategy.Default, providers: [] });10const mock = ngMocks.find(MyComponent, { selector: 'my-component', inputs: { name: 'value' }, outputs: { name: 'value' }, exportAs: 'name', changeDetection: ChangeDetectionStrategy.Default, providers: [], viewProviders: [] });11const mock = ngMocks.find(MyComponent, { selector: 'my-component', inputs: { name: 'value' }, outputs: { name: 'value' }, exportAs: 'name', changeDetection: ChangeDetectionStrategy.Default, providers: [], viewProviders: [], queries: {} });12const mock = ngMocks.find(MyComponent, { selector: 'my-component', inputs: { name: 'value' }, outputs: { name: 'value' },

Full Screen

Using AI Code Generation

copy

Full Screen

1const attributes = ngMocks.attributes(2 fixture.debugElement.query(By.directive(TestComponent))3);4console.log(attributes);5const attributes = ngMocks.attributes(6 fixture.debugElement.query(By.directive(TestComponent))7);8console.log(attributes);9const attributes = ngMocks.attributes(10 fixture.debugElement.query(By.directive(TestComponent))11);12console.log(attributes);13const attributes = ngMocks.attributes(14 fixture.debugElement.query(By.directive(TestComponent))15);16console.log(attributes);17const attributes = ngMocks.attributes(18 fixture.debugElement.query(By.directive(TestComponent))19);20console.log(attributes);21const attributes = ngMocks.attributes(22 fixture.debugElement.query(By.directive(TestComponent))23);24console.log(attributes);25const attributes = ngMocks.attributes(26 fixture.debugElement.query(By.directive(TestComponent))27);28console.log(attributes);

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