How to use componentMetadata method in storybook-root

Best JavaScript code snippet using storybook-root

ComponentMetadata-dbg.js

Source:ComponentMetadata-dbg.js Github

copy

Full Screen

1/*!2 * UI development toolkit for HTML5 (OpenUI5)3 * (c) Copyright 2009-2016 SAP SE or an SAP affiliate company.4 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.5 */6// Provides class sap.ui.core.ComponentMetadata7sap.ui.define(['jquery.sap.global', 'sap/ui/base/ManagedObjectMetadata', 'sap/ui/core/Manifest', 'sap/ui/thirdparty/URI', 'jquery.sap.resources'],8 function(jQuery, ManagedObjectMetadata, Manifest, URI /*, jQuery2 */) {9 "use strict";10 /**11 * Creates a new metadata object for a Component subclass.12 *13 * @param {string} sClassName Fully qualified name of the class that is described by this metadata object14 * @param {object} oStaticInfo Static info to construct the metadata from15 *16 * @public17 * @class18 * @author SAP SE19 * @version 1.44.1220 * @since 1.9.221 * @alias sap.ui.core.ComponentMetadata22 */23 var ComponentMetadata = function(sClassName, oClassInfo) {24 // call super constructor25 ManagedObjectMetadata.apply(this, arguments);26 };27 //chain the prototypes28 ComponentMetadata.prototype = jQuery.sap.newObject(ManagedObjectMetadata.prototype);29 ComponentMetadata.preprocessClassInfo = function(oClassInfo) {30 // if the component is a string we convert this into a "_src" metadata entry31 // the specific metadata object can decide to support this or gracefully ignore it32 // basically the ComponentMetadata makes use of this feature33 if (oClassInfo && typeof oClassInfo.metadata === "string") {34 oClassInfo.metadata = {35 _src: oClassInfo.metadata36 };37 }38 return oClassInfo;39 };40 ComponentMetadata.prototype.applySettings = function(oClassInfo) {41 var oStaticInfo = oClassInfo.metadata;42 // if the component metadata loadFromFile feature is active then43 // the component metadata will be loaded from the specified file44 // which needs to be located next to the Component.js file.45 var sName = this.getName(),46 sPackage = sName.replace(/\.\w+?$/, "");47 if (oStaticInfo._src) {48 if (oStaticInfo._src == "component.json") {49 jQuery.sap.log.warning("Usage of declaration \"metadata: 'component.json'\" is deprecated (component " + sName + "). Use \"metadata: 'json'\" instead.");50 } else if (oStaticInfo._src != "json") {51 throw new Error("Invalid metadata declaration for component " + sName + ": \"" + oStaticInfo._src + "\"! Use \"metadata: 'json'\" to load metadata from component.json.");52 }53 var sResource = sPackage.replace(/\./g, "/") + "/component.json";54 jQuery.sap.log.info("The metadata of the component " + sName + " is loaded from file " + sResource + ".");55 try {56 var oResponse = jQuery.sap.loadResource(sResource, {57 dataType: "json"58 });59 jQuery.extend(oStaticInfo, oResponse);60 } catch (err) {61 jQuery.sap.log.error("Failed to load component metadata from \"" + sResource + "\" (component " + sName + ")! Reason: " + err);62 }63 }64 ManagedObjectMetadata.prototype.applySettings.call(this, oClassInfo);65 // keep the information about the component name (for customizing)66 this._sComponentName = sPackage;67 // static initialization flag & instance count68 this._bInitialized = false;69 this._iInstanceCount = 0;70 // extract the manifest71 var oManifest = oStaticInfo["manifest"];72 // if a manifest is available we switch to load the manifest for the73 // metadata instead of using the component metadata section74 if (oManifest) {75 // set the version of the metadata76 oStaticInfo.__metadataVersion = 2;77 // load the manifest if defined as string78 if (typeof oManifest === "string" && oManifest === "json") {79 // In contrast to sap.ui.core.Manifest#load the sap-language parameter80 // won't be added here as the resource is expected to be served from the81 // preload module cache which does not contain any URL parameters82 var sResource = sPackage.replace(/\./g, "/") + "/manifest.json";83 jQuery.sap.log.info("The manifest of the component " + sName + " is loaded from file " + sResource + ".");84 try {85 // the synchronous loading would be only relevant during the86 // development time - for productive usage the Component should87 // provide a preload packaging which includes the manifest88 // next to the Component code - so the sync request penalty89 // should be ignorable for now (async implementation will90 // change the complete behavior of the constructor function)91 var oResponse = jQuery.sap.loadResource(sResource, {92 dataType: "json"93 });94 oManifest = oResponse;95 } catch (err) {96 jQuery.sap.log.error("Failed to load component manifest from \"" + sResource + "\" (component " + sName + ")! Reason: " + err);97 // in case of error the manifest is an empty object98 // to behave similar like for missing component.json99 oManifest = {};100 }101 }102 } else {103 // set the version of the metadata104 // no manifest => metadata version 1105 oStaticInfo.__metadataVersion = 1;106 oManifest = {};107 }108 // ensure the general property name, the namespace sap.app with the id,109 // the namespace sap.ui5 and eventually the extends property110 oManifest["name"] = oManifest["name"] || sName;111 oManifest["sap.app"] = oManifest["sap.app"] || {112 "id": sPackage // use the "package" namespace instead of the classname (without ".Component")113 };114 oManifest["sap.ui5"] = oManifest["sap.ui5"] || {};115 // the extends property will be added when the component is not a base class116 if (!this.isBaseClass()) {117 oManifest["sap.ui5"]["extends"] = oManifest["sap.ui5"]["extends"] || {};118 }119 // convert the old legacy metadata and merge with the new manifest120 this._convertLegacyMetadata(oStaticInfo, oManifest);121 this._oStaticInfo = oStaticInfo;122 this._oManifest = new Manifest(oManifest, {123 componentName: this._sComponentName,124 baseUrl: jQuery.sap.getModulePath(this._sComponentName) + "/",125 process: oStaticInfo.__metadataVersion === 2126 });127 };128 /**129 * Static initialization of components. This function will be called by the130 * Component and the metadata decides whether to execute the static init code131 * or not. It will be called the first time a Component is initialized.132 * @private133 */134 ComponentMetadata.prototype.init = function() {135 if (!this._bInitialized) {136 // first we load the dependencies of the parent137 var oParent = this.getParent();138 if (oParent instanceof ComponentMetadata) {139 oParent.init();140 }141 // init the manifest and save initialize state142 this._oManifest.init();143 this._bInitialized = true;144 }145 };146 /**147 * Static termination of components.148 *149 * TODO: Right now it is unclear when this function should be called. Just to150 * make sure that we do not forget this in future.151 *152 * @private153 */154 ComponentMetadata.prototype.exit = function() {155 if (this._bInitialized) {156 var oParent = this.getParent();157 if (oParent instanceof ComponentMetadata) {158 oParent.exit();159 }160 // exit the manifest and save initialize state161 this._oManifest.exit();162 this._bInitialized = false;163 }164 };165 /**166 * Component instances need to register themselves in this method to enable167 * the customizing for this component. This will only be done for the first168 * instance and only if a customizing configuration is available.169 * @private170 */171 ComponentMetadata.prototype.onInitComponent = function() {172 var oUI5Manifest = this.getManifestEntry("sap.ui5", true),173 mExtensions = oUI5Manifest && oUI5Manifest["extends"] && oUI5Manifest["extends"].extensions;174 if (this._iInstanceCount === 0 && !jQuery.isEmptyObject(mExtensions)) {175 var CustomizingConfiguration = sap.ui.requireSync('sap/ui/core/CustomizingConfiguration');176 CustomizingConfiguration.activateForComponent(this._sComponentName);177 }178 this._iInstanceCount++;179 };180 /**181 * Component instances need to unregister themselves in this method to disable182 * the customizing for this component. This will only be done for the last183 * instance and only if a customizing configuration is available.184 * @private185 */186 ComponentMetadata.prototype.onExitComponent = function() {187 this._iInstanceCount = Math.max(this._iInstanceCount - 1, 0);188 var CustomizingConfiguration = sap.ui.require('sap/ui/core/CustomizingConfiguration');189 if (this._iInstanceCount === 0 && CustomizingConfiguration) {190 CustomizingConfiguration.deactivateForComponent(this._sComponentName);191 }192 };193 /**194 * Returns whether the class of this metadata is a component base class195 * or not.196 * @return {boolean} true if it is sap.ui.core.Component or sap.ui.core.UIComponent197 * @protected198 * @since 1.33.0199 */200 ComponentMetadata.prototype.isBaseClass = function() {201 return /^sap\.ui\.core\.(UI)?Component$/.test(this.getName());202 };203 /**204 * Returns the version of the metadata which could be 1 or 2. 1 is for legacy205 * metadata whereas 2 is for the manifest.206 * @return {int} metadata version (1: legacy metadata, 2: manifest)207 * @protected208 * @since 1.27.1209 */210 ComponentMetadata.prototype.getMetadataVersion = function() {211 return this._oStaticInfo.__metadataVersion;212 };213 /**214 * Returns the manifest object.215 * @return {sap.ui.core.Manifest} manifest.216 * @public217 * @since 1.33.0218 */219 ComponentMetadata.prototype.getManifestObject = function() {220 return this._oManifest;221 };222 /**223 * Returns the manifest defined in the metadata of the Component.224 * If not specified, the return value is null.225 * @return {Object} manifest.226 * @public227 * @since 1.27.1228 * @deprecated Since 1.33.0. Please use the sap.ui.core.Component#getManifest229 */230 ComponentMetadata.prototype.getManifest = function() {231 // use raw manifest in case of legacy metadata232 if (this.getMetadataVersion() === 1) {233 return this._oManifest.getRawJson();234 }235 return this._oManifest.getJson();236 };237 /**238 * Returns the processed manifest object (no copy).239 * Processing will be done in a "lazy" way.240 *241 * @return {object} manifest242 * @private243 * @since 1.29.0244 * @deprecated Since 1.33.0. Please use the sap.ui.core.Component#getManifest245 */246 ComponentMetadata.prototype._getManifest = function() {247 jQuery.sap.log.warning("ComponentMetadata#_getManifest: do not use deprecated functions anymore!");248 return this._oManifest.getJson();249 };250 /**251 * Returns the raw manifest defined in the metadata of the Component.252 * If not specified, the return value is null.253 * @return {Object} manifest254 * @public255 * @since 1.29.0256 * @deprecated Since 1.33.0. Please use the sap.ui.core.Component#getManifest257 */258 ComponentMetadata.prototype.getRawManifest = function() {259 return this._oManifest.getRawJson();260 };261 /**262 * Returns the raw manifest object (no copy).263 *264 * @return {object} manifest265 * @private266 * @since 1.29.0267 * @deprecated Since 1.33.0. Please use the sap.ui.core.Component#getRawManifest268 */269 ComponentMetadata.prototype._getRawManifest = function() {270 jQuery.sap.log.warning("ComponentMetadata#_getRawManifest: do not use deprecated functions anymore!");271 return this._oManifest.getRawJson();272 };273 /**274 * Returns the configuration of a manifest section or the value for a275 * specific path. If no section or key is specified, the return value is null.276 *277 * Example:278 * <code>279 * {280 * "sap.ui5": {281 * "dependencies": {282 * "libs": {283 * "sap.m": {}284 * },285 * "components": {286 * "my.component.a": {}287 * }288 * }289 * });290 * </code>291 *292 * The configuration above can be accessed in the following ways:293 * <ul>294 * <li><b>By section/namespace</b>: <code>oComponent.getMetadata().getManifestEntry("sap.ui5")</code></li>295 * <li><b>By path</b>: <code>oComponent.getMetadata().getManifestEntry("/sap.ui5/dependencies/libs")</code></li>296 * </ul>297 *298 * By section/namespace returns the configuration for the specified manifest299 * section and by path allows to specify a concrete path to a dedicated entry300 * inside the manifest. The path syntax always starts with a slash (/).301 *302 * @param {string} sKey Either the manifest section name (namespace) or a concrete path303 * @param {boolean} [bMerged] Indicates whether the custom configuration is merged with the parent custom configuration of the Component.304 * @return {any|null} Value of the manifest section or the key (could be any kind of value)305 * @public306 * @since 1.27.1307 * @deprecated Since 1.33.0. Please use the sap.ui.core.Component#getManifest308 */309 ComponentMetadata.prototype.getManifestEntry = function(sKey, bMerged) {310 var oData = this._oManifest.getEntry(sKey);311 // merge / extend should only be done for objects or when entry wasn't found312 if (oData !== undefined && !jQuery.isPlainObject(oData)) {313 return oData;314 }315 // merge the configuration of the parent manifest with local manifest316 // the configuration of the static component metadata will be ignored317 var oParent, oParentData;318 if (bMerged && (oParent = this.getParent()) instanceof ComponentMetadata) {319 oParentData = oParent.getManifestEntry(sKey, bMerged);320 }321 // only extend / clone if there is data322 // otherwise "null" will be converted into an empty object323 if (oParentData || oData) {324 oData = jQuery.extend(true, {}, oParentData, oData);325 }326 return oData;327 };328 /**329 * Returns the custom Component configuration entry with the specified key (this must be a JSON object).330 * If no key is specified, the return value is null.331 *332 * Example:333 * <code>334 * sap.ui.core.Component.extend("sample.Component", {335 * metadata: {336 * "my.custom.config" : {337 * "property1" : true,338 * "property2" : "Something else"339 * }340 * }341 * });342 * </code>343 *344 * The configuration above can be accessed via <code>sample.Component.getMetadata().getCustomEntry("my.custom.config")</code>.345 *346 * @param {string} sKey Key of the custom configuration (must be prefixed with a namespace)347 * @param {boolean} bMerged Indicates whether the custom configuration is merged with the parent custom configuration of the Component.348 * @return {Object} custom Component configuration with the specified key.349 * @public350 * @deprecated Since 1.27.1. Please use the sap.ui.core.ComponentMetadata#getManifestEntry351 */352 ComponentMetadata.prototype.getCustomEntry = function(sKey, bMerged) {353 if (!sKey || sKey.indexOf(".") <= 0) {354 jQuery.sap.log.warning("Component Metadata entries with keys without namespace prefix can not be read via getCustomEntry. Key: " + sKey + ", Component: " + this.getName());355 return null;356 }357 var oParent,358 oData = this._oStaticInfo[sKey] || {};359 if (!jQuery.isPlainObject(oData)) {360 jQuery.sap.log.warning("Custom Component Metadata entry with key '" + sKey + "' must be an object. Component: " + this.getName());361 return null;362 }363 if (bMerged && (oParent = this.getParent()) instanceof ComponentMetadata) {364 return jQuery.extend(true, {}, oParent.getCustomEntry(sKey, bMerged), oData);365 }366 return jQuery.extend(true, {}, oData);367 };368 /**369 * Returns the name of the Component (which is the namespace only with the module name)370 * @return {string} Component name371 * @public372 */373 ComponentMetadata.prototype.getComponentName = function() {374 return this._sComponentName;375 };376 /**377 * Returns the dependencies defined in the metadata of the Component. If not specified, the return value is null.378 * <p>379 * <b>Important:</b></br>380 * If a Component is loaded using the manifest URL (or according the381 * "manifest first" strategy), this function ignores the entries of the382 * manifest file! It returns only the entries which have been defined in383 * the Component metadata or in the proper Component manifest.384 *385 * @return {Object} Component dependencies.386 * @public387 * @deprecated Since 1.27.1. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.ui5/dependencies")388 */389 ComponentMetadata.prototype.getDependencies = function() {390 //jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.getDependencies is deprecated!");391 if (!this._oLegacyDependencies) {392 var mDependencies = this.getManifestEntry("/sap.ui5/dependencies"),393 sUI5Version = mDependencies && mDependencies.minUI5Version || null,394 mLibs = mDependencies && mDependencies.libs || {},395 mComponents = mDependencies && mDependencies.components || {};396 var mLegacyDependencies = {397 ui5version: sUI5Version,398 libs: [],399 components: []400 };401 for (var sLib in mLibs) {402 mLegacyDependencies.libs.push(sLib);403 }404 for (var sComponent in mComponents) {405 mLegacyDependencies.components.push(sComponent);406 }407 this._oLegacyDependencies = mLegacyDependencies;408 }409 return this._oLegacyDependencies;410 };411 /**412 * Returns the array of the included files that the Component requires such413 * as CSS and JavaScript. If not specified or the array is empty, the return414 * value is null.415 * <p>416 * <b>Important:</b></br>417 * If a Component is loaded using the manifest URL (or according the418 * "manifest first" strategy), this function ignores the entries of the419 * manifest file! It returns only the entries which have been defined in420 * the Component metadata or in the proper Component manifest.421 *422 * @return {string[]} Included files.423 * @public424 * @deprecated Since 1.27.1. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.ui5/resources")425 */426 ComponentMetadata.prototype.getIncludes = function() {427 //jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.getIncludes is deprecated!");428 if (!this._aLegacyIncludes) {429 var aIncludes = [],430 mResources = this.getManifestEntry("/sap.ui5/resources") || {},431 aCSSResources = mResources && mResources.css || [],432 aJSResources = mResources && mResources.js || [];433 for (var i = 0, l = aCSSResources.length; i < l; i++) {434 if (aCSSResources[i] && aCSSResources[i].uri) {435 aIncludes.push(aCSSResources[i].uri);436 }437 }438 for (var i = 0, l = aJSResources.length; i < l; i++) {439 if (aJSResources[i] && aJSResources[i].uri) {440 aIncludes.push(aJSResources[i].uri);441 }442 }443 this._aLegacyIncludes = (aIncludes.length > 0) ? aIncludes : null;444 }445 return this._aLegacyIncludes;446 };447 /**448 * Returns the required version of SAPUI5 defined in the metadata of the449 * Component. If returned value is null, then no special UI5 version is450 * required.451 * <p>452 * <b>Important:</b></br>453 * If a Component is loaded using the manifest URL (or according the454 * "manifest first" strategy), this function ignores the entries of the455 * manifest file! It returns only the entries which have been defined in456 * the Component metadata or in the proper Component manifest.457 *458 * @return {string} Required version of UI5 or if not specified then null.459 * @public460 * @deprecated Since 1.27.1. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.ui5/dependencies/minUI5Version")461 */462 ComponentMetadata.prototype.getUI5Version = function() {463 //jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.getUI5Version is deprecated!");464 return this.getManifestEntry("/sap.ui5/dependencies/minUI5Version");465 };466 /**467 * Returns array of components specified in the metadata of the Component.468 * If not specified or the array is empty, the return value is null.469 * <p>470 * <b>Important:</b></br>471 * If a Component is loaded using the manifest URL (or according the472 * "manifest first" strategy), this function ignores the entries of the473 * manifest file! It returns only the entries which have been defined in474 * the Component metadata or in the proper Component manifest.475 *476 * @return {string[]} Required Components.477 * @public478 * @deprecated Since 1.27.1. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.ui5/dependencies/components")479 */480 ComponentMetadata.prototype.getComponents = function() {481 //jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.getComponents is deprecated!");482 return this.getDependencies().components;483 };484 /**485 * Returns array of libraries specified in metadata of the Component, that486 * are automatically loaded when an instance of the component is created.487 * If not specified or the array is empty, the return value is null.488 * <p>489 * <b>Important:</b></br>490 * If a Component is loaded using the manifest URL (or according the491 * "manifest first" strategy), this function ignores the entries of the492 * manifest file! It returns only the entries which have been defined in493 * the Component metadata or in the proper Component manifest.494 *495 * @return {string[]} Required libraries.496 * @public497 * @deprecated Since 1.27.1. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.ui5/dependencies/libs")498 */499 ComponentMetadata.prototype.getLibs = function() {500 //jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.getLibs is deprecated!");501 return this.getDependencies().libs;502 };503 /**504 * Returns the version of the component. If not specified, the return value505 * is null.506 * <p>507 * <b>Important:</b></br>508 * If a Component is loaded using the manifest URL (or according the509 * "manifest first" strategy), this function ignores the entries of the510 * manifest file! It returns only the entries which have been defined in511 * the Component metadata or in the proper Component manifest.512 *513 * @return {string} The version of the component.514 * @public515 * @deprecated Since 1.34.2. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.app/applicationVersion/version")516 */517 ComponentMetadata.prototype.getVersion = function() {518 return this.getManifestEntry("/sap.app/applicationVersion/version");519 };520 /**521 * Returns a copy of the configuration property to disallow modifications.522 * If no key is specified it returns the complete configuration property523 *524 * @param {string} [sKey] Key of the configuration property525 * @param {boolean} [bDoNotMerge] If set to <code>true</code>, only the local configuration is returned526 * @return {object} the value of the configuration property527 * @public528 * @since 1.15.1529 * @deprecated Since 1.27.1. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.ui5/config")530 */531 ComponentMetadata.prototype.getConfig = function(sKey, bDoNotMerge) {532 //jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.getConfig is deprecated!");533 var mConfig = this.getManifestEntry("/sap.ui5/config", !bDoNotMerge);534 if (!mConfig) {535 return {};536 }537 if (!sKey) {538 return mConfig;539 }540 return mConfig.hasOwnProperty(sKey) ? mConfig[sKey] : {};541 };542 /**543 * Returns a copy of the Customizing property544 * <p>545 * <b>Important:</b></br>546 * If a Component is loaded using the manifest URL (or according the547 * "manifest first" strategy), this function ignores the entries of the548 * manifest file! It returns only the entries which have been defined in549 * the Component metadata or in the proper Component manifest.550 *551 * @param {boolean} [bDoNotMerge] If set to <code>true</code>, only the local configuration is returned552 * @return {object} the value of the Customizing property553 * @private554 * @since 1.15.1555 * @experimental Since 1.15.1. Implementation might change.556 * @deprecated Since 1.27.1. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.ui5/extends/extensions")557 */558 ComponentMetadata.prototype.getCustomizing = function(bDoNotMerge) {559 //jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.getCustomizing is deprecated!");560 return this.getManifestEntry("/sap.ui5/extends/extensions", !bDoNotMerge);561 };562 /**563 * Returns the models configuration which defines the available models of the564 * Component.565 * <p>566 * <b>Important:</b></br>567 * If a Component is loaded using the manifest URL (or according the568 * "manifest first" strategy), this function ignores the entries of the569 * manifest file! It returns only the entries which have been defined in570 * the Component metadata or in the proper Component manifest.571 *572 * @param {boolean} [bDoNotMerge] If set to <code>true</code>, only the local configuration is returned573 * @return {object} models configuration574 * @private575 * @since 1.15.1576 * @experimental Since 1.15.1. Implementation might change.577 * @deprecated Since 1.27.1. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.ui5/models")578 */579 ComponentMetadata.prototype.getModels = function(bDoNotMerge) {580 //jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.getModels is deprecated!");581 if (!this._oLegacyModels) {582 this._oLegacyModels = {};583 var mDataSources = this.getManifestEntry("/sap.ui5/models") || {};584 for (var sDataSource in mDataSources) {585 var oDataSource = mDataSources[sDataSource];586 this._oLegacyModels[sDataSource] = oDataSource.settings || {};587 this._oLegacyModels[sDataSource].type = oDataSource.type;588 this._oLegacyModels[sDataSource].uri = oDataSource.uri;589 }590 }591 // deep copy of the legacy models object592 var oParent,593 mModels = jQuery.extend(true, {}, this._oLegacyModels);594 // merge the models object if defined via parameter595 if (!bDoNotMerge && (oParent = this.getParent()) instanceof ComponentMetadata) {596 mModels = jQuery.extend(true, {}, oParent.getModels(), mModels);597 }598 // return a clone of the models599 return mModels;600 };601 /**602 * Returns messaging flag603 * <p>604 * <b>Important:</b></br>605 * If a Component is loaded using the manifest URL (or according the606 * "manifest first" strategy), this function ignores the entries of the607 * manifest file! It returns only the entries which have been defined in608 * the Component metadata or in the proper Component manifest.609 *610 * @return {boolean} bMessaging Messaging enabled/disabled611 * @private612 * @since 1.28.0613 * @deprecated Since 1.28.1. Please use {@link sap.ui.core.Component#getManifestEntry}("/sap.ui5/handleValidation")614 */615 ComponentMetadata.prototype.handleValidation = function() {616 //jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.handleValidation is deprecated!");617 return this.getManifestEntry("/sap.ui5/handleValidation");618 };619 /**620 * Returns the services configuration which defines the available services621 * of the component.622 * <p>623 * <b>Important:</b></br>624 * If a Component is loaded using the manifest URL (or according the625 * "manifest first" strategy), this function ignores the entries of the626 * manifest file! It returns only the entries which have been defined in627 * the Component metadata or in the proper Component manifest.628 *629 * @return {object} services configuration630 * @private631 * @since 1.15.1632 * @experimental Since 1.15.1. Implementation might change.633 * @deprecated Since 1.27.1. Please use the sap.ui.core.ComponentMetadata#getManifest634 */635 ComponentMetadata.prototype.getServices = function() {636 jQuery.sap.log.warning("Usage of sap.ui.core.ComponentMetadata.protoype.getServices is deprecated!");637 // legacy API - for the manifest services has a different meaning!638 return this._oStaticInfo.services || {};639 };640 /**641 * Converts the legacy metadata into the new manifest format642 * @private643 */644 ComponentMetadata.prototype._convertLegacyMetadata = function(oStaticInfo, oManifest) {645 // this function can be outsourced in future when the ComponentMetadata646 // is not used anymore and the new Application manifest is used -647 // but for now we keep it as it will be one of the common use cases648 // to have the classical ComponentMetadata and this should be649 // transformed into the new manifest structure for compatibility650 // converter for array with string values to object651 var fnCreateObject = function(a, fnCallback) {652 var o = {};653 if (a) {654 for (var i = 0, l = a.length; i < l; i++) {655 var oValue = a[i];656 if (typeof oValue === "string") {657 o[oValue] = typeof fnCallback === "function" && fnCallback(oValue) || {};658 }659 }660 }661 return o;662 };663 // add the old information on component metadata to the manifest info664 var oAppManifest = oManifest["sap.app"];665 var oUI5Manifest = oManifest["sap.ui5"];666 // we do not merge the manifest and the metadata - once a manifest667 // entry exists, the metadata entries will be ignored and the specific668 // metadata entry needs to be migrated into the manifest.669 for (var sName in oStaticInfo) {670 var oValue = oStaticInfo[sName];671 if (oValue !== undefined) {672 switch (sName) {673 case "name":674 oManifest[sName] = oManifest[sName] || oValue;675 oAppManifest["id"] = oAppManifest["id"] || oValue;676 break;677 case "description":678 case "keywords":679 oAppManifest[sName] = oAppManifest[sName] || oValue;680 break;681 case "version":682 var mAppVersion = oAppManifest.applicationVersion = oAppManifest.applicationVersion || {};683 mAppVersion.version = mAppVersion.version || oValue;684 break;685 case "config":686 oUI5Manifest[sName] = oUI5Manifest[sName] || oValue;687 break;688 case "customizing":689 var mExtends = oUI5Manifest["extends"] = oUI5Manifest["extends"] || {};690 mExtends.extensions = mExtends.extensions || oValue;691 break;692 case "dependencies":693 if (!oUI5Manifest[sName]) {694 oUI5Manifest[sName] = {};695 oUI5Manifest[sName].minUI5Version = oValue.ui5version;696 oUI5Manifest[sName].libs = fnCreateObject(oValue.libs);697 oUI5Manifest[sName].components = fnCreateObject(oValue.components);698 }699 break;700 case "includes":701 if (!oUI5Manifest["resources"]) {702 oUI5Manifest["resources"] = {};703 if (oValue && oValue.length > 0) {704 for (var i = 0, l = oValue.length; i < l; i++) {705 var sResource = oValue[i];706 var m = sResource.match(/\.(css|js)$/i);707 if (m) {708 oUI5Manifest["resources"][m[1]] = oUI5Manifest["resources"][m[1]] || [];709 oUI5Manifest["resources"][m[1]].push({710 "uri": sResource711 });712 }713 }714 }715 }716 break;717 case "handleValidation":718 if (oUI5Manifest[sName] === undefined) {719 oUI5Manifest[sName] = oValue;720 }721 break;722 case "models":723 if (!oUI5Manifest["models"]) {724 var oModels = {};725 for (var sModel in oValue) {726 var oDS = oValue[sModel];727 var oModel = {};728 for (var sDSSetting in oDS) {729 var oDSSetting = oDS[sDSSetting];730 switch (sDSSetting) {731 case "type":732 case "uri":733 oModel[sDSSetting] = oDSSetting;734 break;735 default:736 oModel.settings = oModel.settings || {};737 oModel.settings[sDSSetting] = oDSSetting;738 }739 }740 oModels[sModel] = oModel;741 }742 oUI5Manifest["models"] = oModels;743 }744 break;745 // no default746 }747 }748 }749 };750 return ComponentMetadata;...

Full Screen

Full Screen

contacts-app.spec.ts

Source:contacts-app.spec.ts Github

copy

Full Screen

1// import {2// describe,3// it,4// iit,5// expect,6// beforeEachProviders,7// inject,8// injectAsync,9// TestComponentBuilder,10// ComponentFixture11// } from 'angular2/testing';12// import {reflector, ComponentMetadata, provide} from 'angular2/core';13// import {ContactsApp} from '../app/contacts-app';14// import {ContactHeaderComponent} from '../app/contact-header/contact-header';15// // import {ContactsService} from '../app/services/contacts-service/contacts-service';16//17// // describe('Exercise 1', () => {18//19// // it('should run', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {20// // return tcb.createAsync(ContactsApp).then((componentFixture: ComponentFixture) => {21// // const element = componentFixture.nativeElement;22// // expect(element.querySelector('h1').innerHTML).toEqual('Hello World!');23// // });24// // }));25// // });26//27// describe('Exercise 2', () => {28//29// it('should have ContactHeaderComponent directive dependency', () => {30// let metadatas = reflector.annotations(ContactsApp);31// let componentMetadata = metadatas.find(type => type instanceof ComponentMetadata);32// expect(componentMetadata.directives).toBeDefined();33// expect(componentMetadata.directives.indexOf(ContactHeaderComponent) > -1).toBe(true);34// });35// });36//37// // describe('Exercise 3', () => {38//39// // it('should have a contact property', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {40// // return tcb.createAsync(ContactsApp).then((componentFixture: ComponentFixture) => {41// // let contactProp = componentFixture.componentInstance.contact;42// // expect(contactProp).toBeDefined();43// // expect(contactProp.id).toEqual(7);44// // expect(contactProp.name).toEqual('Diana Ellis');45// // });46// // }));47// // });48//49// describe('Exercise 4', () => {50//51// it('should have a list of contacts', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {52// return tcb.createAsync(ContactsApp).then((componentFixture: ComponentFixture) => {53// let contactsProp = componentFixture.componentInstance.contacts;54// expect(contactsProp).toBeDefined();55// let element = componentFixture.nativeElement;56// componentFixture.detectChanges();57// expect(element.querySelectorAll('li').length > 1).toBe(true);58// });59// }));60// });61//62// // describe('Exercise 5', () => {63//64// // it('should have ContactsService provider', () => {65// // let metadatas = reflector.annotations(ContactsApp);66// // let componentMetadata = metadatas.find(type => type instanceof ComponentMetadata);67// // expect(componentMetadata.providers).toBeDefined();68// // expect(componentMetadata.providers.indexOf(ContactsService) > -1).toBe(true);69// // });70//71// // it('should use ContactsService to get contacts', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {72// // return tcb73// // .overrideProviders(ContactsApp, [74// // provide(ContactsService, { useValue: {75// // getContacts: function () {76// // return [{name: 'Pascal'}, {name: 'Christoph'}];77// // }78// // }})79// // ])80// // .createAsync(ContactsApp).then((componentFixture: ComponentFixture) => {81// // let element = componentFixture.nativeElement;82// // componentFixture.detectChanges();83// // expect(element.querySelectorAll('li').length).toBe(2);84// // });85// // }));86// // });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { componentMetadata } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3import { withKnobs, text } from '@storybook/addon-knobs/react';4const stories = storiesOf('test', module);5stories.addDecorator(withKnobs);6stories.add('test', () => {7 const name = text('name', 'John');8 const age = text('age', '20');9 return componentMetadata({10 props: {11 }12 });13});14import { addDecorator, configure } from '@storybook/react';15import { withRootDecorator } from 'storybook-root-decorator';16addDecorator(withRootDecorator);17configure(require.context('../src', true, /\.stories\.js$/), module);18{19 "props": {20 }21}22function componentMetadata({23 props = {},24 style = {},25}) {}26class RootDecorator extends Component {27 static propTypes = {28 };29 static defaultProps = {30 props: {},31 style: {},32 };33 render() {34 const { children, component, description, props, style, className } = this.props;35 return (36 <div className={className} style={style}>37 <div className="component">{component}</div>38 <div className="description">{description}</div>39 <div className="props">{JSON.stringify(props)}</div>40 {children}41 );

Full Screen

Using AI Code Generation

copy

Full Screen

1import { componentMetadata } from 'storybook-root-decorator';2export default componentMetadata({3 parameters: {4 },5});6export const MyComponent = () => (7 label={text('Label', 'Label')}8 placeholder={text('Placeholder', 'Placeholder')}9);10MyComponent.story = {11};12import { storybookRootDecorator } from 'storybook-root-decorator';13addDecorator(storybookRootDecorator);14import { configure, addDecorator } from '@storybook/react';15import { storybookRootDecorator } from 'storybook-root-decorator';16addDecorator(storybookRootDecorator);17const req = require.context('../src', true, /.stories.js$/);18function loadStories() {19 req.keys().forEach(filename => req(filename));20}21configure(loadStories, module);22const path = require('path');23const { storybookRootDecorator } = require('storybook-root-decorator');24module.exports = (baseConfig, env, config) => {25 config.module.rules.push({26 {27 loader: require.resolve('@storybook/source-loader'),28 options: {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { componentMetadata } from 'storybook-root-decorator';2const metadata = componentMetadata({3});4export default metadata;5export const Default = () => ({6 props: {7 value: text('value', 'Hello World'),8 },9});10Default.story = {11};12@Component({13})14export class ExampleComponent implements OnInit {15 @Input() value: string;16 constructor() { }17 ngOnInit() {18 }19}20 <h1>{{value}}</h1>21h1 {22 color: red;23}24import { async, ComponentFixture, TestBed } from '@angular/core/testing';25import { ExampleComponent } from './example.component';26describe('ExampleComponent', () => {27 let component: ExampleComponent;28 let fixture: ComponentFixture<ExampleComponent>;29 beforeEach(async(() => {30 TestBed.configureTestingModule({31 })32 .compileComponents();33 }));34 beforeEach(() => {35 fixture = TestBed.createComponent(ExampleComponent);36 component = fixture.componentInstance;37 fixture.detectChanges();38 });39 it('should create', () => {40 expect(component).toBeTruthy();41 });42});43import { ExampleComponent } from './example.component';44import { text, withKnobs } from '@storybook/addon-knobs';45import { componentMetadata } from 'storybook-root-decorator';46const metadata = componentMetadata({47});48export default metadata;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { componentMetadata } from 'storybook-root-decorator';2export default componentMetadata({3 subcomponents: { TestSubComponent },4 parameters: {5 notes: {6 },7 },8});9MIT © [joshblack](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { componentMetadata } from 'storybook-react-router';2const metadata = {3 parameters: {4 },5};6export default componentMetadata(metadata);7import { storyMetadata } from 'storybook-react-router';8import ComponentName from './ComponentName';9export default storyMetadata(ComponentName, 'ComponentName', {10});11import { story } from 'storybook-react-router';12import ComponentName from './ComponentName';13export default story(ComponentName, 'ComponentName', {14});15import { storyWithRouter } from 'storybook-react-router';16import ComponentName from './ComponentName';17export default storyWithRouter(ComponentName, 'ComponentName', {18});19import { storyWithRouterAndRedux } from 'storybook-react-router';20import ComponentName from './ComponentName';21export default storyWithRouterAndRedux(ComponentName, 'ComponentName', {22});23import { storyWithRedux } from 'storybook-react-router';24import ComponentName from './ComponentName';25export default storyWithRedux(ComponentName, 'ComponentName', {26});27import { storyWithRedux } from 'storybook-react-router';28import ComponentName from './ComponentName';29export default storyWithRedux(ComponentName, 'ComponentName', {30});31import { storyWithRedux } from 'storybook-react-router';32import ComponentName from './ComponentName';33export default storyWithRedux(ComponentName, 'ComponentName', {34});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { componentMetadata } from 'storybook-root-decorator';2const story = componentMetadata('some-component');3const storyMetadata = story.metadata;4import { componentMetadata } from 'storybook-root-decorator';5const story = componentMetadata('some-component');6const storyMetadata = story.metadata;7import { componentMetadata } from 'storybook-root-decorator';8const story = componentMetadata('some-component');9const storyMetadata = story.metadata;10import { componentMetadata } from 'storybook-root-decorator';11const story = componentMetadata('some-component');12const storyMetadata = story.metadata;13import { componentMetadata } from 'storybook-root-decorator';14const story = componentMetadata('some-component');15const storyMetadata = story.metadata;16import { componentMetadata } from 'storybook-root-decorator';17const story = componentMetadata('some-component');18const storyMetadata = story.metadata;19import { componentMetadata } from 'storybook-root-decorator';20const story = componentMetadata('some-component');21const storyMetadata = story.metadata;22import { componentMetadata } from 'storybook-root-decorator';23const story = componentMetadata('some-component');24const storyMetadata = story.metadata;25import { componentMetadata } from 'storybook-root-decorator';26const story = componentMetadata('some-component');27const storyMetadata = story.metadata;28import { componentMetadata } from 'storybook-root-de

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 storybook-root 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