How to use annotations method in storybook-root

Best JavaScript code snippet using storybook-root

ODataAnnotationsTest.qunit.js

Source:ODataAnnotationsTest.qunit.js Github

copy

Full Screen

1/* global module start test asyncTest expect ok equal deepEqual */23/**4 * Test-Function to be used in place of deepEquals which only tests for the existence of the given5 * values, not the absence of others.6 * 7 * @param {object} oValue - The value to be tested8 * @param {object} oExpected - The value that is tested against, containing the structure expected inside oValue9 * @param {string} sMessage - Message prefix for every sub-test. The property names of the structure will be prepended to this string10 * @returns {void}11 */12function deepContains(oValue, oExpected, sMessage) {13 for (var sKey in oExpected) {14 equals(typeof oValue[sKey], typeof oExpected[sKey], sMessage + "/" + sKey + " have same type");15 16 if (Array.isArray(oExpected[sKey]) && Array.isArray(oValue[sKey])) {17 equal(oValue[sKey].length, oExpected[sKey].length, sMessage + "/" + sKey + " length matches");18 }19 20 if (typeof oExpected[sKey] === "object" && typeof oValue[sKey] === "object") {21 // Go deeper22 deepContains(oValue[sKey], oExpected[sKey], sMessage + "/" + sKey);23 } else {24 // Compare directly25 equal(oValue[sKey], oExpected[sKey], sMessage + "/" + sKey + " match");26 }27 }28}2930/* eslint-disable no-unused-vars */31function runODataAnnotationTests() {32/* eslint-enable no-unused-vars */33"use strict";3435 var aServices = [{36 name : "Northwind",37 service : "fakeService://testdata/odata/northwind/",38 annotations : "fakeService://testdata/odata/northwind-annotations-normal.xml",39 serviceValid : true,40 annotationsValid : true41 }, {42 name : "Northwind",43 service : "fakeService://testdata/odata/northwind/",44 annotations : "fakeService://testdata/odata/northwind-annotations-malformed.xml",45 serviceValid : true,46 annotationsValid : false47 }, {48 name : "Northwind",49 service : "fakeService://testdata/odata/northwind/",50 annotations : "fakeService://testdata/odata/NOT_EXISTANT",51 serviceValid : true,52 annotationsValid : false53 },{54 name : "Invalid",55 service : "fakeService://testdata/odata/NOT_EXISTANT/",56 annotations : "fakeService://testdata/odata/NOT_EXISTANT",57 serviceValid : false,58 annotationsValid : false59 },{60 name : "Complex EPM",61 service : "fakeService://testdata/odata/northwind/",62 annotations : "fakeService://testdata/odata/epm-annotations-complex.xml",63 serviceValid : true,64 annotationsValid : true65 },{66 name : "Northwind",67 service : "fakeService://testdata/odata/northwind/",68 annotations : "fakeService://testdata/odata/northwind-annotations-normal.xml",69 serviceValid : true,70 annotationsValid : true,71 sharedMetadata : true72 }, {73 name : "Northwind",74 service : "fakeService://testdata/odata/northwind/",75 annotations : "fakeService://testdata/odata/northwind-annotations-malformed.xml",76 serviceValid : true,77 annotationsValid : false,78 sharedMetadata : true79 }, {80 name : "Northwind",81 service : "fakeService://testdata/odata/northwind/",82 annotations : "fakeService://testdata/odata/NOT_EXISTANT",83 serviceValid : true,84 annotationsValid : false,85 sharedMetadata : true86 },{87 name : "Invalid",88 service : "fakeService://testdata/odata/NOT_EXISTANT/",89 annotations : "fakeService://testdata/odata/NOT_EXISTANT",90 serviceValid : false,91 annotationsValid : false,92 sharedMetadata : true93 },{94 name : "Northwind with annotated metadata",95 service : "fakeService://testdata/odata/northwind-annotated/",96 annotations : "fakeService://testdata/odata/northwind-annotated/$metadata",97 serviceValid : true,98 annotationsValid : true,99 sharedMetadata : true100 },{101 name : "Northwind with annotated metadata + annotations",102 service : "fakeService://testdata/odata/northwind-annotated/",103 annotations : [ 104 "fakeService://testdata/odata/northwind-annotated/$metadata",105 "fakeService://testdata/odata/northwind-annotations-normal.xml"106 ],107 serviceValid : true,108 annotationsValid : true,109 sharedMetadata : true110 },{111 name : "Northwind with annotated metadata + annotations",112 service : "fakeService://testdata/odata/northwind-annotated/",113 annotations : [ 114 "fakeService://testdata/odata/northwind-annotated/$metadata",115 "fakeService://testdata/odata/northwind-annotations-malformed.xml"116 ],117 serviceValid : true,118 annotationsValid : false,119 sharedMetadata : true120 }];121122 // Additional tests that have extra tests and should thus be referable by name. For this the name123 // of the test is not added as property of the test but as key in the map124 var mAdditionalTestsServices = {125 "Default Annotated Service": {126 service : "fakeService://testdata/odata/northwind/",127 annotations : "fakeService://testdata/odata/northwind-annotations-normal.xml",128 serviceValid : true,129 annotationsValid : "all"130 },131 "Test 2014-12-08": {132 service : "fakeService://testdata/odata/northwind/",133 annotations : "fakeService://testdata/odata/2014-12-08-test.xml",134 serviceValid : true,135 annotationsValid : true136 },137 "Multiple Property Annotations": {138 service : "fakeService://testdata/odata/northwind/",139 annotations : "fakeService://testdata/odata/multiple-property-annotations.xml",140 serviceValid : true,141 annotationsValid : true142 },143 "Property Annotation Qualifiers": {144 service : "fakeService://testdata/odata/northwind/",145 annotations : "fakeService://testdata/odata/property-annotation-qualifiers.xml",146 serviceValid : true,147 annotationsValid : true148 },149 "Other Property Values": {150 service : "fakeService://testdata/odata/northwind/",151 annotations : "fakeService://testdata/odata/other-property-values.xml",152 serviceValid : true,153 annotationsValid : true154 },155 "Aliases in Namespaces": {156 service : "fakeService://testdata/odata/northwind/",157 annotations : "fakeService://testdata/odata/namespaces-aliases.xml",158 serviceValid : true,159 annotationsValid : true160 },161 "Namespaces in Other Property Values": {162 service : "fakeService://testdata/odata/northwind/",163 annotations : "fakeService://testdata/odata/other-property-value-aliases.xml",164 serviceValid : true,165 annotationsValid : true166 },167 "Text Properties" : {168 service : "fakeService://testdata/odata/northwind/",169 annotations : "fakeService://testdata/odata/other-property-textproperties.xml",170 serviceValid : true,171 annotationsValid : true172 },173 "Entity Containers": {174 service : "fakeService://testdata/odata/sapdata01/",175 annotations : "fakeService://testdata/odata/sapdata01/$metadata",176 serviceValid : true,177 annotationsValid : true178 },179 "Simple Values": {180 service : "fakeService://testdata/odata/sapdata01/",181 annotations : "fakeService://testdata/odata/simple-values.xml",182 serviceValid : true,183 annotationsValid : true184 },185 "Alias Replacement": {186 service : "fakeService://testdata/odata/sapdata01/",187 annotations : "fakeService://testdata/odata/Aliases.xml",188 serviceValid : true,189 annotationsValid : "all"190 }, 191 "DynamicExpressions": {192 service : "fakeService://testdata/odata/sapdata01/",193 annotations : "fakeService://testdata/odata/DynamicExpressions.xml",194 serviceValid : true,195 annotationsValid : "all"196 },197 "DynamicExpressions2": {198 service : "fakeService://testdata/odata/sapdata01/",199 annotations : "fakeService://testdata/odata/DynamicExpressions2.xml",200 serviceValid : true,201 annotationsValid : "all"202 },203 "CollectionsWithSimpleValues": {204 service : "fakeService://testdata/odata/sapdata01/",205 annotations : "fakeService://testdata/odata/collections-with-simple-values.xml",206 serviceValid : true,207 annotationsValid : "all"208 },209 "Simple Values 2": {210 service : "fakeService://testdata/odata/sapdata01/",211 annotations : "fakeService://testdata/odata/simple-values-2.xml",212 serviceValid : true,213 annotationsValid : "all"214 },215 "If in Apply": {216 service : "fakeService://testdata/odata/sapdata01/",217 annotations : "fakeService://testdata/odata/if-in-apply.xml",218 serviceValid : true,219 annotationsValid : "all"220 },221 "Other Elements in LabeledElement": {222 service : "fakeService://testdata/odata/sapdata01/",223 annotations : "fakeService://testdata/odata/labeledelement-other-values.xml",224 serviceValid : true,225 annotationsValid : "all"226 },227 "Apply Parameters": {228 service : "fakeService://testdata/odata/sapdata01/",229 annotations : "fakeService://testdata/odata/apply-parameters.xml",230 serviceValid : true,231 annotationsValid : "all"232 }233 };234235236 // Add additional tests to stadard tests as well237 for (var sName in mAdditionalTestsServices) {238 var mTest = mAdditionalTestsServices[sName];239 mTest.name = sName;240 aServices.push(mTest);241 }242243 var 244 sTestName, sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid, bSharedMetadata,245 sTestType, fnTest, mService, oAnnotations, i;246247 sap.ui.test.qunit.delayTestStart();248249 module("Synchronous loading");250251 fnTest = function(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid, bSharedMetadata) {252 return function() {253 if (!bSharedMetadata){254 sap.ui.model.odata.ODataModel.mServiceData = {};255 }256 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);257 // Since this is synchronous, everything should be ready right now.258 if (bServiceValid && bAnnotationsValid) {259 // This should have worked.260 ok(!!oModel.getServiceMetadata(), "Metadata is available.");261 ok(!!oModel.getServiceAnnotations(), "Annotations are available.");262263 } else if (bServiceValid && !bAnnotationsValid) {264 // Service Metadata should be there, annotations should not be loaded265 ok(!!oModel.getServiceMetadata(), "Metadata is available.");266 ok(!oModel.getServiceAnnotations(), "Annotations are not available.");267268 } else if (!bServiceValid) {269 // Service is invalid, so both should not be there270 ok(!oModel.getServiceMetadata(), "Metadata is available.");271 ok(!oModel.getServiceAnnotations(), "Annotations are not available.");272 }273 };274 };275276 for (i = 0; i < aServices.length; ++i) {277 sServiceURI = aServices[i].service;278 mModelOptions = {279 annotationURI : aServices[i].annotations,280 json : true281 };282 bServiceValid = aServices[i].serviceValid;283 bAnnotationsValid = aServices[i].annotationsValid;284 bSharedMetadata = aServices[i].sharedMetadata;285 sTestName = aServices[i].name ? aServices[i].name : "";286287 sTestType = 288 sTestName + " (" + 289 (bServiceValid ? "Valid Service" : "Broken Service") + "/" + 290 (bAnnotationsValid ? "Valid Annotations" : "Broken Annotations") +291 (bSharedMetadata ? "/Shared Metadata" : "") + 292 ")";293294 // Check synchronous loading295 mModelOptions.loadAnnotationsJoined = false;296 mModelOptions.loadMetadataAsync = false;297298 test(sTestType, fnTest(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid));299 }300301 module("Asynchronous loading");302303 fnTest = function(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid, bSharedMetadata) {304 return function() {305 if (!bSharedMetadata){306 sap.ui.model.odata.ODataModel.mServiceData = {};307 }308 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);309310 var bMetadataLoaded = false;311 var bAnnotationsLoaded = false;312313 var fnOnLoaded = function(sWhat) {314315 switch (sWhat) {316317 case "Metadata":318 ok(bMetadataLoaded, "Metadata loaded successfully");319 jQuery.sap.log.debug("check for metadata");320 break;321322 case "Annotations":323 ok(bAnnotationsLoaded, "Annotations loaded successfully");324 break;325326 case "Both":327 ok(bMetadataLoaded && bAnnotationsLoaded, "Check: Annotations and Metadata loaded");328 jQuery.sap.log.debug("check for both");329 start();330 break;331332 case "MetadataFailed": 333 // Nothing should be loaded334 ok(!bServiceValid && !bAnnotationsLoaded, "Check: Invalid Service - Annotations and Metadata NOT loaded");335 jQuery.sap.log.debug("check for none");336 start();337 break;338339 case "AnnotationsFailed":340 // Metadata should be loaded, but no annotations341 ok(bMetadataLoaded && !bAnnotationsLoaded, "Check: Invalid Annotations - Only Metadata loaded");342 jQuery.sap.log.debug("check for no annotations");343 start();344 break;345346 default:347 throw "This is unexpected and should never happen...";348349 }350 };351352 /* eslint-disable new-cap */353 var metadataDfd = jQuery.Deferred();354 var annotationsDfd = jQuery.Deferred();355 /* eslint-enable new-cap */356357 // Metadata must be loaded before annotations358 oModel.attachMetadataLoaded(function() {359 bMetadataLoaded = true;360 jQuery.sap.log.debug("metadata loaded is fired");361 fnOnLoaded("Metadata");362 metadataDfd.resolve();363 });364365 oModel.attachAnnotationsLoaded(function() {366 bAnnotationsLoaded = true;367 jQuery.sap.log.debug("annotations loaded is fired");368 fnOnLoaded("Annotations");369 annotationsDfd.resolve();370 });371372 oModel.attachMetadataFailed(function() {373 jQuery.sap.log.debug("metadata failed is fired");374 metadataDfd.reject();375 });376377 if (bServiceValid && bAnnotationsValid){378 jQuery.when(metadataDfd, annotationsDfd).done(function(e){379 jQuery.sap.log.debug("both promises fulfilled");380 fnOnLoaded("Both");381 }).fail(function(e){382 jQuery.sap.log.debug("metadata promise failed");383 ok(false, 'Metadata promise rejected');384 }); 385 } else if (bServiceValid && !bAnnotationsValid){386 jQuery.when(metadataDfd).done(function(e){387 jQuery.sap.log.debug("metadata promise fulfilled");388 //make sure annotations really don't load an we're not just too quick389 window.setTimeout(function() {390 fnOnLoaded("AnnotationsFailed");391 }, 50);392 });393 } else if (!bServiceValid){394 jQuery.when(metadataDfd).fail(function(e){395 jQuery.sap.log.debug("metadata failed fulfilled");396 fnOnLoaded("MetadataFailed");397 });398 }399 this.clock.tick(50);400 };401 };402403 for (i = 0; i < aServices.length; ++i) {404405 mService = aServices[i];406407 sServiceURI = mService.service;408 mModelOptions = {409 annotationURI : mService.annotations,410 json : true411 };412 bServiceValid = mService.serviceValid;413 bAnnotationsValid = mService.annotationsValid;414 bSharedMetadata = mService.sharedMetadata;415 sTestName = aServices[i].name ? aServices[i].name : "";416417 // Check asynchronous loading418 mModelOptions.loadAnnotationsJoined = false;419 mModelOptions.loadMetadataAsync = true;420 421 sTestType = 422 sTestName + " (" + 423 (bServiceValid ? "Valid Service" : "Broken Service") + "/" + 424 (bAnnotationsValid ? "Valid Annotations" : "Broken Annotations") +425 (bSharedMetadata ? "/Shared Metadata" : "") + 426 ")";427428 jQuery.sap.log.debug("testtype: " + sTestType);429430 asyncTest(431 "Asynchronous loading - " + sTestType,432 fnTest(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid)433 );434 }435436437 module("Asynchronous loading (joined events)");438439 fnTest = function(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid, bSharedMetadata) {440 return function() {441 if (!bSharedMetadata){442 sap.ui.model.odata.ODataModel.mServiceData = {};443 }444 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);445 var that = this;446 var bMetadataLoaded = false;447 var bAnnotationsLoaded = false;448 var bInternalMetadataLoaded = false;449450 var fnOnLoaded = function(sWhat) {451452 switch (sWhat) {453454 case "InternalMetadata":455 ok(!bAnnotationsLoaded, "Internal metadata loaded before annotations");456 break;457458 case "Metadata":459 ok(bMetadataLoaded, "Metadata loaded successfully");460 ok(bAnnotationsLoaded, "Metadata loaded after annotations");461 break;462463 case "Both":464 ok(bMetadataLoaded && bAnnotationsLoaded, "Check: Annotations and Metadata loaded");465 jQuery.sap.log.debug("check for both");466 start();467 break;468469 case "MetadataFailed": 470 // Nothing should be loaded471 ok(!bInternalMetadataLoaded && !bAnnotationsLoaded, "Check: Invalid Service - Annotations and Metadata NOT loaded");472 jQuery.sap.log.debug("check for none");473 start();474 break;475476 case "AnnotationsFailed":477 // Metadata should be loaded, but no annotations478 ok(bInternalMetadataLoaded && !bAnnotationsLoaded, "Check: Invalid Annotations - Only Metadata loaded");479 jQuery.sap.log.debug("check for no annotations");480 start();481 break;482483 default:484 throw "This is unexpected and should never happen...";485 } 486487 };488489 /* eslint-disable new-cap */490 var metadataDfd = jQuery.Deferred();491 var internalMetadataDfd = jQuery.Deferred();492 /* eslint-enable new-cap */493494 // Use internal metadata loaded event, because in case of joined loading, the real one495 // does not fire until Annotations are there496 if (oModel.oMetadata.getServiceMetadata()){497 bInternalMetadataLoaded = true;498 fnOnLoaded("InternalMetadata");499 internalMetadataDfd.resolve();500 } else {501 oModel.oMetadata.attachLoaded(function() {502 bInternalMetadataLoaded = true;503 fnOnLoaded("InternalMetadata");504 internalMetadataDfd.resolve();505 });506 }507 // Metadata must be loaded before annotations508 oModel.attachMetadataLoaded(function() {509 bMetadataLoaded = true;510 if (oModel.bLoadMetadataAsync && oModel.bLoadAnnotationsJoined){511 // Metadata loaded event is only fired after both metadata and annotations have been loaded successfully, so we can also set bAnnotationsloaded to true512 bAnnotationsLoaded = true;513 }514 fnOnLoaded("Metadata");515 metadataDfd.resolve();516 });517518 oModel.attachMetadataFailed(function() {519 metadataDfd.reject();520 });521 oModel.attachAnnotationsLoaded(function() {522 bAnnotationsLoaded = true;523 });524525 if (bServiceValid && bAnnotationsValid){526 jQuery.when(metadataDfd).done(function(e){527 jQuery.sap.log.debug("metadata promise fulfilled");528 fnOnLoaded("Both");529 }).fail(function(e){530 jQuery.sap.log.debug("metadata promise failed");531 ok(false, 'Metadata promise rejected');532 }); 533 } else if (bServiceValid && !bAnnotationsValid){534 //internal metadata needs to be sucessful prior to the failed annotations535 jQuery.when(internalMetadataDfd).done(function(){536 jQuery.sap.log.debug("metadata promise rejected");537 oModel.attachAnnotationsFailed(function(){fnOnLoaded("AnnotationsFailed");}, that);538 });539 } else if (!bServiceValid){540 jQuery.when(metadataDfd).fail(function(e){541 jQuery.sap.log.debug("metadata failed fulfilled");542 fnOnLoaded("MetadataFailed");543 });544 }545 this.clock.tick(100);546 };547 };548549 for (i = 0; i < aServices.length; ++i) {550 mService = aServices[i];551552 sServiceURI = mService.service;553 mModelOptions = {554 annotationURI : mService.annotations,555 json : true556 };557 bServiceValid = mService.serviceValid;558 bAnnotationsValid = mService.annotationsValid;559 bSharedMetadata = mService.sharedMetadata;560 sTestName = aServices[i].name ? aServices[i].name : "";561 562 // Check asynchronous loading563 mModelOptions.loadAnnotationsJoined = true;564 mModelOptions.loadMetadataAsync = true;565566567 sTestType = 568 sTestName + " (" +569 (bServiceValid ? "Valid Service" : "Broken Service") + "/" +570 (bAnnotationsValid ? "Valid Annotations" : "Broken Annotations") +571 (bSharedMetadata ? "/Shared Metadata" : "") +572 ")";573574 asyncTest(575 "Asynchronous loading (joined events) - " + sTestType,576 fnTest(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid)577 ); 578 }579580581 module("Multiple Annotation Sources Merged");582583 asyncTest("Asynchronous loading", function() {584 expect(12);585 var asyncStartsExpected = 2; // The number of asynchronous starts expected before the real start is triggered586587 var oModel1 = new sap.ui.model.odata.ODataModel(588 "fakeService://testdata/odata/northwind-annotated/", 589 {590 annotationURI : [591 "fakeService://testdata/odata/northwind-annotated/$metadata",592 "fakeService://testdata/odata/northwind-annotations-normal.xml"593 ],594 json : true,595 loadAnnotationsJoined : false,596 loadMetadataAsync : false597 }598 );599600 oAnnotations = oModel1.getServiceAnnotations();601602 ok(oAnnotations.UnitTest["Test.FromAnnotations"][0].Value.Path === "Annotations", "Annotation from correct source (Annotations)");603 ok(oAnnotations.UnitTest["Test.FromMetadata"][0].Value.Path === "Metadata", "Annotation from correct source (Metadata)");604 ok(oAnnotations.UnitTest["Test.Merged"][0].Value.Path === "Annotations", "Annotation from correct source (Annotations)");605606 var oModel2 = new sap.ui.model.odata.ODataModel(607 "fakeService://testdata/odata/northwind-annotated/", 608 {609 annotationURI : [610 "fakeService://testdata/odata/northwind-annotations-normal.xml",611 "fakeService://testdata/odata/northwind-annotated/$metadata"612 ],613 json : true,614 loadAnnotationsJoined : false,615 loadMetadataAsync : false616 }617 );618619 oAnnotations = oModel2.getServiceAnnotations();620621 ok(oAnnotations.UnitTest["Test.FromAnnotations"][0].Value.Path === "Annotations", "Annotation from correct source (Annotations)");622 ok(oAnnotations.UnitTest["Test.FromMetadata"][0].Value.Path === "Metadata", "Annotation from correct source (Metadata)");623 ok(oAnnotations.UnitTest["Test.Merged"][0].Value.Path === "Metadata", "Annotation from correct source (Metadata)");624625 var oModel3 = new sap.ui.model.odata.ODataModel(626 "fakeService://testdata/odata/northwind-annotated/", 627 {628 annotationURI : [629 "fakeService://testdata/odata/northwind-annotations-normal.xml",630 "fakeService://testdata/odata/northwind-annotated/$metadata"631 ],632 json : true,633 loadAnnotationsJoined : false,634 loadMetadataAsync : true635 }636 );637 oModel3.attachAnnotationsLoaded(function() {638 var oAnnotations = oModel3.getServiceAnnotations();639 ok(oAnnotations.UnitTest["Test.FromAnnotations"][0].Value.Path === "Annotations", "Annotation from correct source (Annotations)");640 ok(oAnnotations.UnitTest["Test.FromMetadata"][0].Value.Path === "Metadata", "Annotation from correct source (Metadata)");641 ok(oAnnotations.UnitTest["Test.Merged"][0].Value.Path === "Metadata", "Annotation from correct source (Metadata)");642 asyncStart();643 });644645 var oModel4 = new sap.ui.model.odata.ODataModel(646 "fakeService://testdata/odata/northwind-annotated/", 647 {648 annotationURI : [649 "fakeService://testdata/odata/northwind-annotated/$metadata",650 "fakeService://testdata/odata/northwind-annotations-normal.xml"651 ],652 json : true,653 loadAnnotationsJoined : false,654 loadMetadataAsync : true655 }656 );657 oModel4.attachAnnotationsLoaded(function() {658 var oAnnotations = oModel4.getServiceAnnotations();659 ok(oAnnotations.UnitTest["Test.FromAnnotations"][0].Value.Path === "Annotations", "Annotation from correct source (Annotations)");660 ok(oAnnotations.UnitTest["Test.FromMetadata"][0].Value.Path === "Metadata", "Annotation from correct source (Metadata)");661 ok(oAnnotations.UnitTest["Test.Merged"][0].Value.Path === "Annotations", "Annotation from correct source (Annotations)");662 asyncStart();663 });664665666 function asyncStart() {667 if (asyncStart.num === undefined) {668 asyncStart.num = 0;669 }670671 if (++asyncStart.num >= asyncStartsExpected) {672 oModel1.destroy();673 oModel2.destroy();674 oModel3.destroy();675 oModel4.destroy();676677 start();678 }679 }680 681 });682683684685 module("Additional tests for fixed bugs");686687688 test("Test 2014-12-08", function() {689 expect(12);690691 var mTest = mAdditionalTestsServices["Test 2014-12-08"];692 var sServiceURI = mTest.service;693 var mModelOptions = {694 annotationURI : mTest.annotations,695 json : true,696 loadAnnotationsJoined: false,697 loadMetadataAsync: false698 };699700 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);701 var oMetadata = oModel.getServiceMetadata();702 var oAnnotations = oModel.getServiceAnnotations();703704 ok(!!oMetadata, "Metadata is available.");705 ok(!!oAnnotations, "Annotations are available.");706707 ok(708 !!oAnnotations709 ["Test.2014-12-08"],710 "Test Annotations are available"711 );712 ok(713 !!oAnnotations714 ["Test.2014-12-08"]715 ["com.sap.vocabularies.UI.v1.Identification"],716 "Namespace exists"717 );718 ok(719 !!oAnnotations720 ["Test.2014-12-08"]721 ["com.sap.vocabularies.UI.v1.Identification"]722 [0],723 "Namespace has content"724 );725726727 var mNamespace = oAnnotations["Test.2014-12-08"]["com.sap.vocabularies.UI.v1.Identification"][0];728729 ok(730 !!mNamespace731 ["com.sap.vocabularies.UI.v1.Importance"],732 "Sub-namespace exists"733 );734 ok(735 !!mNamespace736 ["com.sap.vocabularies.UI.v1.Importance"]737 ["EnumMember"],738 "EnumMember exists"739 );740 equal(741 mNamespace742 ["com.sap.vocabularies.UI.v1.Importance"]743 ["EnumMember"],744 "com.sap.vocabularies.UI.v1.Priority/High",745 "EnumMember has correct value"746 );747748 ok(!!mNamespace["RecordType"], "RecordType exists");749 equal(750 mNamespace["RecordType"],751 "com.sap.vocabularies.UI.v1.DataField",752 "RecordType has correct value"753 );754755 ok(!!mNamespace["Value"], "Value exists");756757 var mCorrectValue = {758 "Apply": {759 "Name" : "odata.concat",760 "Parameters" : [{761 "Type" : "Path",762 "Value" : "CompanyCodeTESet/ContactPerson"763 }, {764 "Type" : "String",765 "Value" : " ("766 }, {767 "Type" : "Path",768 "Value" : "CompanyCode"769 }, {770 "Type" : "String",771 "Value" : ")"772 }]773 }774 };775776 deepEqual(mNamespace["Value"], mCorrectValue, "Value has correct value");777 });778779780 test("Multiple Property Annotations", function() {781 expect(11);782783 var mTest = mAdditionalTestsServices["Multiple Property Annotations"];784 var sServiceURI = mTest.service;785 var mModelOptions = {786 annotationURI : mTest.annotations,787 json : true,788 loadAnnotationsJoined: false,789 loadMetadataAsync: false790 };791792 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);793 var oMetadata = oModel.getServiceMetadata();794 var oAnnotations = oModel.getServiceAnnotations();795796 ok(!!oMetadata, "Metadata is available.");797 ok(!!oAnnotations, "Annotations are available.");798799 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");800801 ok(802 !!oAnnotations["propertyAnnotations"]["MultiplePropertyAnnotations.Product"],803 "Target namespace inside PropertyAnnotations exists"804 );805806 ok(807 !!oAnnotations["propertyAnnotations"]["MultiplePropertyAnnotations.Product"]["Price/Amount"],808 "Target values exist"809 );810811 ok(812 !!oAnnotations813 ["propertyAnnotations"]814 ["MultiplePropertyAnnotations.Product"]815 ["Price/Amount"]816 ["CQP.ISOCurrency"],817 "Target value 1 exists"818 );819820 ok(821 !!oAnnotations822 ["propertyAnnotations"]823 ["MultiplePropertyAnnotations.Product"]824 ["Price/Amount"]825 ["Common.Label"],826 "Target value 2 exists"827 );828829 ok(830 !!oAnnotations831 ["propertyAnnotations"]832 ["MultiplePropertyAnnotations.Product"]833 ["Price/Amount"]834 ["CQP.ISOCurrency"]835 ["Path"],836 "Target value 1 property exists"837 );838839 ok(840 !!oAnnotations841 ["propertyAnnotations"]842 ["MultiplePropertyAnnotations.Product"]843 ["Price/Amount"]844 ["Common.Label"]845 ["String"],846 "Target value 2 property exists"847 );848849 equal(850 oAnnotations851 ["propertyAnnotations"]852 ["MultiplePropertyAnnotations.Product"]853 ["Price/Amount"]854 ["CQP.ISOCurrency"]855 ["Path"],856 "Price/CurrencyCode",857 "Target value 1 property exists"858 );859860 equal(861 oAnnotations862 ["propertyAnnotations"]863 ["MultiplePropertyAnnotations.Product"]864 ["Price/Amount"]865 ["Common.Label"]866 ["String"],867 "Price",868 "Target value 2 property exists"869 );870 });871872873 test("Qualifiers in Property Annotations", function() {874 expect(8);875876 var mTest = mAdditionalTestsServices["Property Annotation Qualifiers"];877 var sServiceURI = mTest.service;878 var mModelOptions = {879 annotationURI : mTest.annotations,880 json : true,881 loadAnnotationsJoined: false,882 loadMetadataAsync: false883 };884885 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);886 var oMetadata = oModel.getServiceMetadata();887 var oAnnotations = oModel.getServiceAnnotations();888889 ok(!!oMetadata, "Metadata is available.");890 ok(!!oAnnotations, "Annotations are available.");891892 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");893894 ok(895 !!oAnnotations["propertyAnnotations"]["PropertyAnnotationQualifiers.Product"],896 "Target namespace inside PropertyAnnotations exists"897 );898899 ok(900 !!oAnnotations901 ["propertyAnnotations"]["PropertyAnnotationQualifiers.Product"]["Price/Amount"],902 "Target value exists"903 );904905 ok(906 !!oAnnotations907 ["propertyAnnotations"]908 ["PropertyAnnotationQualifiers.Product"]909 ["Price/Amount"]910 ["CQP.ISOCurrency#Amount1"],911 "Target value with Qualifier exists"912 );913914 ok(915 !!oAnnotations916 ["propertyAnnotations"]917 ["PropertyAnnotationQualifiers.Product"]918 ["Price/Amount"]919 ["CQP.ISOCurrency#Amount1"]920 ["Path"],921 "Target value with Qualifier value exists"922 );923924 equal(925 oAnnotations926 ["propertyAnnotations"]927 ["PropertyAnnotationQualifiers.Product"]928 ["Price/Amount"]929 ["CQP.ISOCurrency#Amount1"]930 ["Path"],931 "Price/CurrencyCode",932 "Target value with Qualifier value has correct content"933 );934935 });936937938 test("Other Property Values", function() {939 expect(8);940941 var mTest = mAdditionalTestsServices["Other Property Values"];942 var sServiceURI = mTest.service;943 var mModelOptions = {944 annotationURI : mTest.annotations,945 json : true,946 loadAnnotationsJoined: false,947 loadMetadataAsync: false948 };949950 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);951 var oMetadata = oModel.getServiceMetadata();952 var oAnnotations = oModel.getServiceAnnotations();953954 ok(!!oMetadata, "Metadata is available.");955 ok(!!oAnnotations, "Annotations are available.");956957 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");958959 ok(960 !!oAnnotations["propertyAnnotations"]["OtherPropertyValues.Product"],961 "Target namespace inside PropertyAnnotations exists"962 );963964 ok(965 !!oAnnotations966 ["propertyAnnotations"]["OtherPropertyValues.Product"]["Price/Amount"],967 "Target value exists"968 );969970 ok(971 !!oAnnotations972 ["propertyAnnotations"]973 ["OtherPropertyValues.Product"]974 ["Price/Amount"]975 ["CQP.ISOCurrency#Amount2"],976 "Target value with Qualifier exists"977 );978979 ok(980 !!oAnnotations981 ["propertyAnnotations"]982 ["OtherPropertyValues.Product"]983 ["Price/Amount"]984 ["CQP.ISOCurrency#Amount2"]985 ["String"],986 "Target value with Qualifier value exists"987 );988989 equal(990 oAnnotations991 ["propertyAnnotations"]992 ["OtherPropertyValues.Product"]993 ["Price/Amount"]994 ["CQP.ISOCurrency#Amount2"]995 ["String"],996 "EUR",997 "Target value with Qualifier value has correct content"998 );999 });10001001 test("Aliases in Namespaces", function() {1002 expect(8);10031004 var mTest = mAdditionalTestsServices["Aliases in Namespaces"];1005 var sServiceURI = mTest.service;1006 var mModelOptions = {1007 annotationURI : mTest.annotations,1008 json : true,1009 loadAnnotationsJoined: false,1010 loadMetadataAsync: false1011 };10121013 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1014 var oMetadata = oModel.getServiceMetadata();1015 var oAnnotations = oModel.getServiceAnnotations();10161017 ok(!!oMetadata, "Metadata is available.");1018 ok(!!oAnnotations, "Annotations are available.");10191020 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");10211022 ok(1023 !!oAnnotations["propertyAnnotations"]["NamespaceAliases.PurchaseOrder"],1024 "Target namespace inside PropertyAnnotations exists"1025 );10261027 ok(1028 !!oAnnotations1029 ["propertyAnnotations"]["NamespaceAliases.PurchaseOrder"]["GrossAmount"],1030 "Target value exists"1031 );10321033 ok(1034 !!oAnnotations1035 ["propertyAnnotations"]1036 ["NamespaceAliases.PurchaseOrder"]1037 ["GrossAmount"]1038 ["com.sap.vocabularies.Common.v1.Label"],1039 "Target value with correct alias replacement (none!) exists"1040 );10411042 ok(1043 !!oAnnotations1044 ["propertyAnnotations"]1045 ["NamespaceAliases.PurchaseOrder"]1046 ["GrossAmount"]1047 ["com.sap.vocabularies.Common.v1.Label"]1048 ["String"],1049 "Target value with String value exists"1050 );10511052 equal(1053 oAnnotations1054 ["propertyAnnotations"]1055 ["NamespaceAliases.PurchaseOrder"]1056 ["GrossAmount"]1057 ["com.sap.vocabularies.Common.v1.Label"]1058 ["String"],1059 "Gross Amount",1060 "Target value String value has correct content"1061 );10621063 });1064 1065 test("Namespaces in Other Property Values", function() {1066 expect(22);10671068 var mTest = mAdditionalTestsServices["Namespaces in Other Property Values"];1069 var sServiceURI = mTest.service;1070 var mModelOptions = {1071 annotationURI : mTest.annotations,1072 json : true,1073 loadAnnotationsJoined: false,1074 loadMetadataAsync: false1075 };10761077 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1078 var oMetadata = oModel.getServiceMetadata();1079 var oAnnotations = oModel.getServiceAnnotations();10801081 ok(!!oMetadata, "Metadata is available.");10821083 ok(!!oAnnotations, "Annotations are available.");10841085 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");10861087 ok(1088 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"],1089 "Target value exists"1090 );109110921093 ok(1094 !!oAnnotations1095 ["propertyAnnotations"]1096 ["OtherPropertyValueAliases.Test"]1097 ["Value"]1098 ["com.sap.vocabularies.UI.v1.Name"],1099 "Target value's namespace has been correctly replaced"1100 );1101 ok(1102 !!oAnnotations1103 ["propertyAnnotations"]1104 ["OtherPropertyValueAliases.Test"]1105 ["Value"]1106 ["com.sap.vocabularies.UI.v1.Name"]1107 ["EnumMember"],1108 "Target value's child exists"1109 );1110 equal(1111 oAnnotations1112 ["propertyAnnotations"]1113 ["OtherPropertyValueAliases.Test"]1114 ["Value"]1115 ["com.sap.vocabularies.UI.v1.Name"]1116 ["EnumMember"],1117 "com.sap.vocabularies.UI.v1.Value",1118 "Target value's namespace has been correctly replaced"1119 );112011211122 ok(1123 !!oAnnotations1124 ["propertyAnnotations"]1125 ["OtherPropertyValueAliases.Test"]1126 ["Value"]1127 ["com.sap.vocabularies.Communication.v1.Name"],1128 "Target value's namespace has been correctly replaced"1129 );1130 ok(1131 !!oAnnotations1132 ["propertyAnnotations"]1133 ["OtherPropertyValueAliases.Test"]1134 ["Value"]1135 ["com.sap.vocabularies.Communication.v1.Name"]1136 ["EnumMember"],1137 "Target value's child exists"1138 );1139 equal(1140 oAnnotations1141 ["propertyAnnotations"]1142 ["OtherPropertyValueAliases.Test"]1143 ["Value"]1144 ["com.sap.vocabularies.Communication.v1.Name"]1145 ["EnumMember"],1146 "com.sap.vocabularies.Communication.v1.Value",1147 "Target value's namespace has been correctly replaced"1148 );114911501151 ok(1152 !!oAnnotations1153 ["propertyAnnotations"]1154 ["OtherPropertyValueAliases.Test"]1155 ["Value"]1156 ["Org.OData.Measures.V1.Name"],1157 "Target value's namespace has been correctly replaced"1158 );1159 ok(1160 !!oAnnotations1161 ["propertyAnnotations"]1162 ["OtherPropertyValueAliases.Test"]1163 ["Value"]1164 ["Org.OData.Measures.V1.Name"]1165 ["EnumMember"],1166 "Target value's child exists"1167 );1168 equal(1169 oAnnotations1170 ["propertyAnnotations"]1171 ["OtherPropertyValueAliases.Test"]1172 ["Value"]1173 ["Org.OData.Measures.V1.Name"]1174 ["EnumMember"],1175 "Org.OData.Measures.V1.Value",1176 "Target value's namespace has been correctly replaced"1177 );117811791180 ok(1181 !!oAnnotations1182 ["propertyAnnotations"]1183 ["OtherPropertyValueAliases.Test"]1184 ["Value"]1185 ["Org.OData.Measures.V1.Name"],1186 "Target value's namespace has been correctly replaced"1187 );1188 ok(1189 !!oAnnotations1190 ["propertyAnnotations"]1191 ["OtherPropertyValueAliases.Test"]1192 ["Value"]1193 ["Org.OData.Measures.V1.Name"]1194 ["EnumMember"],1195 "Target value's child exists"1196 );1197 equal(1198 oAnnotations1199 ["propertyAnnotations"]1200 ["OtherPropertyValueAliases.Test"]1201 ["Value"]1202 ["Org.OData.Measures.V1.Name"]1203 ["EnumMember"],1204 "Org.OData.Measures.V1.Value",1205 "Target value's namespace has been correctly replaced"1206 );120712081209 ok(1210 !!oAnnotations1211 ["propertyAnnotations"]1212 ["OtherPropertyValueAliases.Test"]1213 ["Value"]1214 ["com.sap.vocabularies.Common.v1.Name"],1215 "Target value's namespace has been correctly replaced"1216 );1217 ok(1218 !!oAnnotations1219 ["propertyAnnotations"]1220 ["OtherPropertyValueAliases.Test"]1221 ["Value"]1222 ["com.sap.vocabularies.Common.v1.Name"]1223 ["EnumMember"],1224 "Target value's child exists"1225 );1226 equal(1227 oAnnotations1228 ["propertyAnnotations"]1229 ["OtherPropertyValueAliases.Test"]1230 ["Value"]1231 ["com.sap.vocabularies.Common.v1.Name"]1232 ["EnumMember"],1233 "com.sap.vocabularies.Common.v1.Value",1234 "Target value's namespace has been correctly replaced"1235 );123612371238 ok(1239 !!oAnnotations1240 ["propertyAnnotations"]1241 ["OtherPropertyValueAliases.Test"]1242 ["Value"]1243 ["FTGEN_HB_TE.Name"],1244 "Target value's namespace has been correctly replaced"1245 );1246 ok(1247 !!oAnnotations1248 ["propertyAnnotations"]1249 ["OtherPropertyValueAliases.Test"]1250 ["Value"]1251 ["FTGEN_HB_TE.Name"]1252 ["EnumMember"],1253 "Target value's child exists"1254 );1255 equal(1256 oAnnotations1257 ["propertyAnnotations"]1258 ["OtherPropertyValueAliases.Test"]1259 ["Value"]1260 ["FTGEN_HB_TE.Name"]1261 ["EnumMember"],1262 "FTGEN_HB_TE.Value",1263 "Target value's namespace has been correctly replaced"1264 );12651266 });1267 1268 1269 test("Text Properties", function() {1270 expect(14);12711272 var mTest = mAdditionalTestsServices["Text Properties"];1273 var sServiceURI = mTest.service;1274 var mModelOptions = {1275 annotationURI : mTest.annotations,1276 json : true,1277 loadAnnotationsJoined: false,1278 loadMetadataAsync: false1279 };12801281 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1282 var oMetadata = oModel.getServiceMetadata();1283 var oAnnotations = oModel.getServiceAnnotations();12841285 ok(!!oMetadata, "Metadata is available.");12861287 ok(!!oAnnotations, "Annotations are available.");12881289 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations group exists");1290 1291 ok(1292 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"],1293 "PropertyAnnotation definition exists"1294 );1295 1296 ok(1297 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"],1298 "PropertyAnnotation definition value exists"1299 );1300 1301 ok(1302 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name1"],1303 "Name1 with replaced alias exists"1304 );1305 ok(1306 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name2"],1307 "Name2 with replaced alias exists"1308 );1309 ok(1310 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name3"],1311 "Name3 with replaced alias exists"1312 );1313 1314 ok(1315 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name1"]["EnumMember"],1316 "Name1 with replaced alias exists and has EnumMember child node"1317 );1318 ok(1319 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name2"]["String"],1320 "Name2 with replaced alias exists and has String child node"1321 );1322 ok(1323 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name3"]["Invalid"],1324 "Name3 with replaced alias exists and has Invalid child node"1325 );1326 1327 equals(1328 oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name1"]["EnumMember"],1329 "com.sap.vocabularies.UI.v1.Value",1330 "Name1 with replaced alias exists and has EnumMember child node that contains alias replaced tet with trimmed white-spaces"1331 );1332 equals(1333 oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name2"]["String"],1334 " test test ",1335 "Name2 with replaced alias exists and has String child node that contains the exact text inclunding white-spaces"1336 );1337 deepEqual(1338 oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name3"]["Invalid"],1339 {},1340 "Name3 with replaced alias exists and has Invalid child node that only contains an empy object"1341 );1342 13431344 });1345 1346 test("Entity Containers", function() {1347 expect(30);13481349 var mTest = mAdditionalTestsServices["Entity Containers"];1350 var sServiceURI = mTest.service;1351 var mModelOptions = {1352 annotationURI : mTest.annotations,1353 json : true,1354 loadAnnotationsJoined: false,1355 loadMetadataAsync: false1356 };13571358 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1359 var oMetadata = oModel.getServiceMetadata();1360 var oAnnotations = oModel.getServiceAnnotations();13611362 ok(!!oMetadata, "Metadata is available.");13631364 ok(!!oAnnotations, "Annotations are available.");13651366 1367 ok(!!oAnnotations["EntityContainer"], "Entity container entry exists");1368 1369 ok(!!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"], "Entity container exists");1370 1371 ok(1372 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1373 ["SalesOrder"],1374 "Entity in container exists"1375 );13761377 ok(1378 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1379 ["SalesOrder"]1380 ["com.sap.vocabularies.Common.v1.DraftRoot"],1381 "Sub Entity in container exists"1382 );13831384 ok(1385 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1386 ["SalesOrder"]1387 ["com.sap.vocabularies.Common.v1.DraftRoot"]1388 ["ActivationAction"],1389 "Sub Entity value in container exists"1390 );1391 ok(1392 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1393 ["SalesOrder"]1394 ["com.sap.vocabularies.Common.v1.DraftRoot"]1395 ["ActivationAction"]1396 ["String"],1397 "Sub Entity value in container exists"1398 );1399 equal(1400 oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1401 ["SalesOrder"]1402 ["com.sap.vocabularies.Common.v1.DraftRoot"]1403 ["ActivationAction"]1404 ["String"],1405 "AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities/Activate",1406 "Sub Entity value in container exists"1407 );1408 1409 ok(1410 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1411 ["SalesOrder"]1412 ["com.sap.vocabularies.Common.v1.DraftRoot"]1413 ["EditAction"],1414 "Sub Entity value in container exists"1415 );1416 ok(1417 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1418 ["SalesOrder"]1419 ["com.sap.vocabularies.Common.v1.DraftRoot"]1420 ["EditAction"]1421 ["String"],1422 "Sub Entity value in container exists"1423 );1424 equal(1425 oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1426 ["SalesOrder"]1427 ["com.sap.vocabularies.Common.v1.DraftRoot"]1428 ["EditAction"]1429 ["String"],1430 "AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities/Edit",1431 "Sub Entity value in container exists"1432 );1433 1434 ok(1435 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1436 ["SalesOrder"]1437 ["com.sap.vocabularies.Common.v1.DraftRoot"]1438 ["ValidationFunction"],1439 "Sub Entity value in container exists"1440 );1441 ok(1442 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1443 ["SalesOrder"]1444 ["com.sap.vocabularies.Common.v1.DraftRoot"]1445 ["ValidationFunction"]1446 ["String"],1447 "Sub Entity value in container exists"1448 );1449 equal(1450 oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1451 ["SalesOrder"]1452 ["com.sap.vocabularies.Common.v1.DraftRoot"]1453 ["ValidationFunction"]1454 ["String"],1455 "AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities/Validate",1456 "Sub Entity value in container exists"1457 );1458 1459 ok(1460 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1461 ["SalesOrder"]1462 ["com.sap.vocabularies.Common.v1.DraftRoot"]1463 ["PreparationAction"],1464 "Sub Entity value in container exists"1465 );1466 ok(1467 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1468 ["SalesOrder"]1469 ["com.sap.vocabularies.Common.v1.DraftRoot"]1470 ["PreparationAction"]1471 ["String"],1472 "Sub Entity value in container exists"1473 );1474 equal(1475 oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1476 ["SalesOrder"]1477 ["com.sap.vocabularies.Common.v1.DraftRoot"]1478 ["PreparationAction"]1479 ["String"],1480 "AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities/Prepare",1481 "Sub Entity value in container exists"1482 );1483 1484 ok(1485 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"],1486 "Entity in namespace exists"1487 );1488 ok(1489 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"]1490 ["com.sap.vocabularies.Common.v1.SemanticKey"],1491 "Entity in namespace exists"1492 );1493 ok(1494 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"]1495 ["com.sap.vocabularies.Common.v1.SemanticKey"]1496 [0],1497 "Entity entries in namespace exists"1498 );1499 ok(1500 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"]1501 ["com.sap.vocabularies.Common.v1.SemanticKey"]1502 [0]1503 ["PropertyPath"],1504 "Property exists"1505 );1506 equal(1507 oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"]1508 ["com.sap.vocabularies.Common.v1.SemanticKey"]1509 [0]1510 ["PropertyPath"],1511 "SalesOrderID",1512 "Entity in namespace exists"1513 );1514 1515 ok(1516 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"],1517 "Entity in namespace exists"1518 );1519 ok(1520 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1521 ["com.sap.vocabularies.Common.v1.SemanticKey"],1522 "Entity in namespace exists"1523 );1524 ok(1525 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1526 ["com.sap.vocabularies.Common.v1.SemanticKey"]1527 [0],1528 "Entity entries in namespace exists"1529 );1530 ok(1531 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1532 ["com.sap.vocabularies.Common.v1.SemanticKey"]1533 [0]1534 ["PropertyPath"],1535 "Property exists"1536 );1537 ok(1538 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1539 ["com.sap.vocabularies.Common.v1.SemanticKey"]1540 [1]1541 ["PropertyPath"],1542 "Property exists"1543 );1544 equal(1545 oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1546 ["com.sap.vocabularies.Common.v1.SemanticKey"]1547 [0]1548 ["PropertyPath"],1549 "SalesOrderID",1550 "Entity in namespace exists"1551 );1552 equal(1553 oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1554 ["com.sap.vocabularies.Common.v1.SemanticKey"]1555 [1]1556 ["PropertyPath"],1557 "SalesOrderItemID",1558 "Entity in namespace exists"1559 );1560 });1561 1562 1563 test("Simple Values", function() {1564 expect(3);15651566 var mTest = mAdditionalTestsServices["Simple Values"];1567 var sServiceURI = mTest.service;1568 var mModelOptions = {1569 annotationURI : mTest.annotations,1570 json : true,1571 loadAnnotationsJoined: false,1572 loadMetadataAsync: false1573 };15741575 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1576 var oMetadata = oModel.getServiceMetadata();1577 var oAnnotations = oModel.getServiceAnnotations();15781579 ok(!!oMetadata, "Metadata is available.");15801581 ok(!!oAnnotations, "Annotations are available.");1582 1583 deepEqual(1584 oAnnotations["SimpleValues.Test"]["com.sap.vocabularies.UI.v1.Name1"],1585 oAnnotations["SimpleValues.Test"]["com.sap.vocabularies.UI.v1.Name2"],1586 "Simple value attributes have the meaning as child elements"1587 );1588 1589 });15901591 1592 test("Alias Replacement", function() {1593 expect(11);15941595 var mTest = mAdditionalTestsServices["Alias Replacement"];1596 var sServiceURI = mTest.service;1597 var mModelOptions = {1598 annotationURI : mTest.annotations,1599 json : true,1600 loadAnnotationsJoined: false,1601 loadMetadataAsync: false1602 };16031604 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1605 var oMetadata = oModel.getServiceMetadata();1606 var oAnnotations = oModel.getServiceAnnotations();16071608 ok(!!oMetadata, "Metadata is available.");16091610 ok(!!oAnnotations, "Annotations are available.");16111612 1613 1614 ok(!!oAnnotations["Test.AliasReplacement"], "Namespace is available.");1615 ok(!!oAnnotations["Test.AliasReplacement"]["TestAnnotation"], "Annotation is available.");1616 1617 1618 ok(!!oAnnotations["Test.AliasReplacement"]["TestAnnotation"]["NotReplaced"], "First Entry is available.");1619 ok(!!oAnnotations["Test.AliasReplacement"]["TestAnnotation"]["NotReplaced"][0], "First Entry array is available.");1620 ok(!!oAnnotations["Test.AliasReplacement"]["TestAnnotation"]["NotReplaced"][0]["AnnotationPath"], "First Entry value is available.");1621 equal(oAnnotations["Test.AliasReplacement"]["TestAnnotation"]["NotReplaced"][0]["AnnotationPath"], "@internal.ui5.test.Value", "First Entry value is correct.");1622 1623 ok(!!oAnnotations["Test.AliasReplacement"]["TestAnnotation"]["Replaced"], "Second Entry is available.");1624 ok(!!oAnnotations["Test.AliasReplacement"]["TestAnnotation"]["Replaced"]["AnnotationPath"], "Second Entry value is available.");1625 equal(oAnnotations["Test.AliasReplacement"]["TestAnnotation"]["Replaced"]["AnnotationPath"], "@internal.ui5.test.Value", "Second Entry value is correct.");1626 });16271628 test("DynamicExpressions", function() {1629 expect(15);16301631 var mTest = mAdditionalTestsServices["DynamicExpressions"];1632 var sServiceURI = mTest.service;1633 var mModelOptions = {1634 annotationURI : mTest.annotations,1635 json : true,1636 loadAnnotationsJoined: false,1637 loadMetadataAsync: false1638 };16391640 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1641 var oMetadata = oModel.getServiceMetadata();1642 var oAnnotations = oModel.getServiceAnnotations();16431644 ok(!!oMetadata, "Metadata is available.");1645 ok(!!oAnnotations, "Annotations are available.");1646 1647 ok(!!oAnnotations["DynamicExpressions"], "Annotation target is available");1648 ok(!!oAnnotations["DynamicExpressions"]["org.example.person.Gender"], "Annotation term is available");1649 1650 var mValue = oAnnotations["DynamicExpressions"]["org.example.person.Gender"];1651 var mExpected = {1652 "If" : [1653 { "Path": "IsFemale" },1654 { "String": "Female" },1655 { "String": "Male" }1656 ]1657 };1658 deepContains(mValue, mExpected, "Value is correct: DynamicExpressions/org.example.person.Gender");1659 });16601661 test("DynamicExpressions 2", function() {1662 expect(56);16631664 var mTest = mAdditionalTestsServices["DynamicExpressions2"];1665 var sServiceURI = mTest.service;1666 var mModelOptions = {1667 annotationURI : mTest.annotations,1668 json : true,1669 loadAnnotationsJoined: false,1670 loadMetadataAsync: false1671 };16721673 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1674 var oMetadata = oModel.getServiceMetadata();1675 var oAnnotations = oModel.getServiceAnnotations();16761677 ok(!!oMetadata, "Metadata is available.");1678 ok(!!oAnnotations, "Annotations are available.");1679 1680 ok(!!oAnnotations["DynamicExpressions2"], "Annotation target is available");1681 ok(!!oAnnotations["DynamicExpressions2"]["com.sap.vocabularies.Test.v1.Data"], "Annotation term is available");1682 ok(!!oAnnotations["DynamicExpressions2"]["com.sap.vocabularies.Test.v1.Data"]["Value"], "Annotation value is available");1683 1684 var mValue = oAnnotations["DynamicExpressions2"]["com.sap.vocabularies.Test.v1.Data"]["Value"];1685 var mExpected = {1686 "And": [{1687 "Or":[{1688 "Eq":[{1689 "Lt":[{1690 "Not":{1691 "Path":"p1"1692 }1693 }, {1694 "Path":"p2"1695 }]1696 }, {1697 "Path":"p3"1698 }]1699 }, {1700 "Gt": [{1701 "Path":"p4"1702 }, {1703 "Path":"p5"1704 }]1705 }]1706 }, {1707 "Ne": [{1708 "Ge":[{1709 "Path":"p6"1710 }, {1711 "Path":"p7"1712 }]1713 }, {1714 "Le":[{1715 "Path":"p8"1716 },{1717 "Path":"p9"1718 }]1719 }]1720 }]1721 };1722 1723 deepContains(mValue, mExpected, "Value is correct: DynamicExpressions2/com.sap.vocabularies.Test.v1.Data/Value");1724 1725 1726 1727 });17281729 test("CollectionsWithSimpleValues", function() {1730 expect(14);17311732 var mTest = mAdditionalTestsServices["CollectionsWithSimpleValues"];1733 var sServiceURI = mTest.service;1734 var mModelOptions = {1735 annotationURI : mTest.annotations,1736 json : true,1737 loadAnnotationsJoined: false,1738 loadMetadataAsync: false1739 };17401741 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1742 var oMetadata = oModel.getServiceMetadata();1743 var oAnnotations = oModel.getServiceAnnotations();17441745 ok(!!oMetadata, "Metadata is available.");1746 ok(!!oAnnotations, "Annotations are available.");1747 1748 ok(!!oAnnotations["CollectionsWithSimpleValues"], "Annotation target is available");1749 ok(!!oAnnotations["CollectionsWithSimpleValues"]["com.sap.vocabularies.Test.v1.Data"], "Annotation term is available");1750 ok(!!oAnnotations["CollectionsWithSimpleValues"]["com.sap.vocabularies.Test.v1.Data"]["Collection"], "Annotation collection is available");17511752 var mValue = oAnnotations["CollectionsWithSimpleValues"]["com.sap.vocabularies.Test.v1.Data"]["Collection"];1753 var mExpected = [1754 { "String": "String01" },1755 { "String": "String02" },1756 { "String": "String03" }1757 ];1758 deepContains(mValue, mExpected, "Value is correct: CollectionsWithSimpleValues/com.sap.vocabularies.Test.v1.Data");1759 });1760 1761 test("Multiple Simple Values", function() {1762 expect(9);1763 1764 var mTest = mAdditionalTestsServices["Simple Values 2"];1765 var sServiceURI = mTest.service;1766 var mModelOptions = {1767 annotationURI : mTest.annotations,1768 json : true,1769 loadAnnotationsJoined: false,1770 loadMetadataAsync: false1771 };17721773 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1774 var oMetadata = oModel.getServiceMetadata();1775 var oAnnotations = oModel.getServiceAnnotations();17761777 ok(!!oMetadata, "Metadata is available.");1778 ok(!!oAnnotations, "Annotations are available.");1779 1780 deepContains(1781 oAnnotations["SimpleValues"],1782 {1783 "com.sap.vocabularies.Test.v1.Data": {1784 "String": "String03",1785 "Path": "Path02",1786 "Int": "4"1787 }1788 },1789 "Multiple String values as array: SimpleValues"1790 );1791 });1792 1793 1794 asyncTest("If in Apply", function() {1795 expect(57);1796 var mTest = mAdditionalTestsServices["If in Apply"];1797 var sServiceURI = mTest.service;1798 var mModelOptions = {1799 annotationURI : mTest.annotations,1800 json : true1801 };18021803 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);1804 1805 oModel.attachAnnotationsLoaded(function() {1806 var oMetadata = oModel.getServiceMetadata();1807 var oAnnotations = oModel.getServiceAnnotations();1808 1809 ok(!!oMetadata, "Metadata is available.");1810 ok(!!oAnnotations, "Annotations are available.");1811 1812 deepContains(1813 oAnnotations["IfInApply"],1814 1815 {1816 "com.sap.vocabularies.Test.v1.Data": {1817 "Value": {1818 "Apply": {1819 "Parameters": [{1820 "Type": "If",1821 "Value": [{1822 "Eq": [1823 {"Path":"Sex"},1824 {"String":"M"}1825 ]1826 }, {1827 "String": "Mr. "1828 }, {1829 "If": [{1830 "Eq": [{1831 "Path": "Sex"1832 }, {1833 "String": "F"1834 }]1835 }, {1836 "String": "Mrs. "1837 }, {1838 "String": ""1839 }]1840 }]1841 }, {1842 "Type": "Path",1843 "Value": "FirstName"1844 }, {1845 "Type": "String",1846 "Value": ""1847 }, {1848 "Type": "Path",1849 "Value": "LastName"1850 }]1851 }1852 }1853 }1854 },1855 "IfInApply"1856 );1857 1858 start();1859 });1860 });1861 1862 1863 asyncTest("Other Elements in LabeledElement", function() {1864 expect(97);1865 var mTest = mAdditionalTestsServices["Other Elements in LabeledElement"];1866 var sServiceURI = mTest.service;1867 var mModelOptions = {1868 annotationURI : mTest.annotations,1869 json : true1870 };18711872 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);1873 1874 oModel.attachAnnotationsLoaded(function() {1875 var oMetadata = oModel.getServiceMetadata();1876 var oAnnotations = oModel.getServiceAnnotations();1877 1878 ok(!!oMetadata, "Metadata is available.");1879 ok(!!oAnnotations, "Annotations are available.");1880 1881 deepContains(1882 oAnnotations["LabeledElement"], 1883 {1884 "com.sap.vocabularies.Test.v1.Data": {1885 "Url": {1886 "UrlRef": {1887 "Apply": {1888 "Name": "odata.fillUriTemplate",1889 "Parameters": [{1890 "Type": "String",1891 "Value":"#{Bool}/{Date}/{DateTimeOffset}/{Decimal}/{Float}/{Guid}/{Int}/{Path}/{String}/{TimeOfDay}"1892 }, {1893 "Type":"LabeledElement",1894 "Name":"Bool",1895 "Value": {1896 "Bool": "true"1897 }1898 }, {1899 "Type": "LabeledElement",1900 "Name": "Date",1901 "Value": {1902 "Date": "2015-03-24"1903 }1904 }, {1905 "Type": "LabeledElement",1906 "Name": "DateTimeOffset",1907 "Value": {1908 "DateTimeOffset": "2015-03-24T14:03:27Z"1909 }1910 }, {1911 "Type": "LabeledElement",1912 "Name": "Decimal",1913 "Value": {1914 "Decimal": "-123456789012345678901234567890.1234567890"1915 }1916 }, {1917 "Type": "LabeledElement",1918 "Name": "Float",1919 "Value": {1920 "Float": "-7.4503e-36"1921 }1922 }, {1923 "Type": "LabeledElement",1924 "Name": "Guid",1925 "Value": {1926 "Guid": "0050568D-393C-1ED4-9D97-E65F0F3FCC23"1927 }1928 }, {1929 "Type": "LabeledElement",1930 "Name": "Int",1931 "Value": {1932 "Int": "9007199254740992"1933 }1934 }, {1935 "Type": "LabeledElement",1936 "Name": "Path",1937 "Value": {1938 "Path": "BusinessPartnerID"1939 }1940 }, {1941 "Type": "LabeledElement",1942 "Name": "String",1943 "Value": {1944 "String": "hello, world"1945 }1946 }, {1947 "Type": "LabeledElement",1948 "Name": "TimeOfDay",1949 "Value": {1950 "TimeOfDay": "13:57:06"1951 }1952 }]1953 }1954 }1955 },1956 "RecordType": "com.sap.vocabularies.Test.v1.Data.DataFieldWithUrl"1957 },1958 },1959 "LabeledElement"1960 );19611962 start();1963 });1964 });1965 1966 1967 asyncTest("Apply Parameters", function() {1968 expect(32);1969 var mTest = mAdditionalTestsServices["Apply Parameters"];1970 var sServiceURI = mTest.service;1971 var mModelOptions = {1972 annotationURI : mTest.annotations,1973 json : true1974 };19751976 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);1977 1978 oModel.attachAnnotationsLoaded(function() {1979 var oMetadata = oModel.getServiceMetadata();1980 var oAnnotations = oModel.getServiceAnnotations();1981 1982 ok(!!oMetadata, "Metadata is available.");1983 ok(!!oAnnotations, "Annotations are available.");1984 1985 deepContains(1986 oAnnotations["CatalogService.Annotation"],1987 {1988 "UI.data": {1989 "Path":"MediaType"1990 },1991 "UI.data2": {1992 "Path":"MediaType2"1993 },1994 "UI.data3": {1995 "Apply": {1996 "Name": "odata.concat",1997 "Parameters": [{1998 "Type": "String",1999 "Value": "Yes"2000 }, {2001 "Type": "String",2002 "Value": "we"2003 }, {2004 "Type": "String",2005 "Value": "can"2006 }]2007 }2008 },2009 "UI.meta": {2010 "String":"text"2011 }2012 },2013 "Apply in Dynamic expression is parsed correctly: CatalogService.Annotation"2014 );2015 2016 start();2017 });2018 });20192020 2021 var fnTestAnnotationInRecord = function(iModelVersion) {2022 expect(53);20232024 var mTest = mAdditionalTestsServices["Default Annotated Service"];2025 2026 var oModel;2027 if (iModelVersion == 1) {2028 oModel = new sap.ui.model.odata.ODataModel(mTest.service, {2029 annotationURI : mTest.annotations,2030 loadMetadataAsync: true2031 });2032 } else if (iModelVersion == 2) {2033 oModel = new sap.ui.model.odata.v2.ODataModel(mTest.service, {2034 annotationURI : mTest.annotations,2035 });2036 } else {2037 ok(false, "Unknown ODataModel version requested for test");2038 return;2039 }20402041 oModel.attachAnnotationsLoaded(function() {2042 var oMetadata = oModel.getServiceMetadata();2043 var oAnnotations = oModel.getServiceAnnotations();2044 2045 ok(!!oMetadata, "Metadata is available.");2046 ok(!!oAnnotations, "Annotations are available.");2047 2048 2049 ok(!!oAnnotations["Test.AnnotationInRecord"], "Outer Annotations container exists");2050 ok(!!oAnnotations["Test.AnnotationInRecord"]["Test.AnnotationInRecord.Case1"], "Outer Annotation exists");2051 2052 var mTestCase1 = oAnnotations["Test.AnnotationInRecord"]["Test.AnnotationInRecord.Case1"];2053 2054 deepContains(mTestCase1, {2055 "Test.AnnotationInRecord.Case1.Record.SubAnnotation1": {2056 "String": "SubAnnotation1"2057 },2058 "Label": {2059 "String": "Label1"2060 },2061 "Test.AnnotationInRecord.Case1.Record.SubAnnotation2": {2062 "If" : [{2063 "Eq": [{2064 "Path": "Condition" 2065 }, {2066 "Bool": "false"2067 }]2068 }, {2069 "String": "ConditionalValue"2070 }]2071 },2072 "RecordType": "Test.AnnotationInRecord.Case1.Record"2073 }, "Case 1 Annotation has correct values");20742075 var mTestCase2 = oAnnotations["Test.AnnotationInRecord"]["Test.AnnotationInRecord.Case2"];2076 2077 deepContains(mTestCase2, {2078 "Test.AnnotationInRecord.Case2.Record.SubAnnotation1": {2079 "String": "SubAnnotation1"2080 },2081 "Label": {2082 "String": "Annotation"2083 },2084 "Test.AnnotationInRecord.Case2.Record.SubAnnotation2": {2085 "If" : [{2086 "Eq": [{2087 "Path": "Condition" 2088 }, {2089 "Bool": "false"2090 }]2091 }, {2092 "String": "ConditionalValue"2093 }]2094 },2095 "RecordType": "Test.AnnotationInRecord.Case2.Record"2096 }, "Case 2 Annotation has correct values");2097 2098 var mTestCase3 = oAnnotations["Test.AnnotationInRecord"]["Test.AnnotationInRecord.Case3"];20992100 deepContains(mTestCase3, {2101 "Null": null,2102 "RecordType": "Test.AnnotationInRecord.Case3.Record"2103 }, "Case 3 has correct values");21042105 oModel.destroy();2106 start();2107 });2108 }2109 2110 asyncTest("V1: Annotation in Record", fnTestAnnotationInRecord.bind(this, 1));2111 asyncTest("V1: Annotation in Record", fnTestAnnotationInRecord.bind(this, 2));2112 ...

Full Screen

Full Screen

ODataAnnotationsV2Test.qunit.js

Source:ODataAnnotationsV2Test.qunit.js Github

copy

Full Screen

1/* global module start test asyncTest expect ok equal deepEqual */23/* eslint-disable no-unused-vars */4function runODataAnnotationTests() {5/* eslint-enable no-unused-vars */6"use strict";78 var aServices = [{9 name : "Northwind",10 service : "fakeService://testdata/odata/northwind/",11 annotations : "fakeService://testdata/odata/northwind-annotations-normal.xml",12 serviceValid : true,13 annotationsValid : true14 }, {15 name : "Northwind",16 service : "fakeService://testdata/odata/northwind/",17 annotations : "fakeService://testdata/odata/northwind-annotations-malformed.xml",18 serviceValid : true,19 annotationsValid : false20 }, {21 name : "Northwind",22 service : "fakeService://testdata/odata/northwind/",23 annotations : "fakeService://testdata/odata/NOT_EXISTANT",24 serviceValid : true,25 annotationsValid : false26 },{27 name : "Invalid",28 service : "fakeService://testdata/odata/NOT_EXISTANT/",29 annotations : "fakeService://testdata/odata/NOT_EXISTANT",30 serviceValid : false,31 annotationsValid : false32 },{33 name : "Complex EPM",34 service : "fakeService://testdata/odata/northwind/",35 annotations : "fakeService://testdata/odata/epm-annotations-complex.xml",36 serviceValid : true,37 annotationsValid : true38 },{39 name : "Northwind",40 service : "fakeService://testdata/odata/northwind/",41 annotations : "fakeService://testdata/odata/northwind-annotations-normal.xml",42 serviceValid : true,43 annotationsValid : true,44 sharedMetadata : true45 }, {46 name : "Northwind",47 service : "fakeService://testdata/odata/northwind/",48 annotations : "fakeService://testdata/odata/northwind-annotations-malformed.xml",49 serviceValid : true,50 annotationsValid : false,51 sharedMetadata : true52 }, {53 name : "Northwind",54 service : "fakeService://testdata/odata/northwind/",55 annotations : "fakeService://testdata/odata/NOT_EXISTANT",56 serviceValid : true,57 annotationsValid : false,58 sharedMetadata : true59 },{60 name : "Invalid",61 service : "fakeService://testdata/odata/NOT_EXISTANT/",62 annotations : "fakeService://testdata/odata/NOT_EXISTANT",63 serviceValid : false,64 annotationsValid : false,65 sharedMetadata : true66 },{67 name : "Northwind with annotated metadata",68 service : "fakeService://testdata/odata/northwind-annotated/",69 annotations : "fakeService://testdata/odata/northwind-annotated/$metadata",70 serviceValid : true,71 annotationsValid : true,72 sharedMetadata : true73 },{74 name : "Northwind with annotated metadata + annotations",75 service : "fakeService://testdata/odata/northwind-annotated/",76 annotations : [ 77 "fakeService://testdata/odata/northwind-annotated/$metadata",78 "fakeService://testdata/odata/northwind-annotations-normal.xml"79 ],80 serviceValid : true,81 annotationsValid : true,82 sharedMetadata : true83 },{84 name : "Northwind with annotated metadata + annotations",85 service : "fakeService://testdata/odata/northwind-annotated/",86 annotations : [ 87 "fakeService://testdata/odata/northwind-annotated/$metadata",88 "fakeService://testdata/odata/northwind-annotations-malformed.xml"89 ],90 serviceValid : true,91 annotationsValid : false,92 sharedMetadata : true93 }];9495 // Additional tests that have extra tests and should thus be referable by name. For this the name96 // of the test is not added as property of the test but as key in the map97 var mAdditionalTestsServices = {98 "Test 2014-12-08": {99 service : "fakeService://testdata/odata/northwind/",100 annotations : "fakeService://testdata/odata/2014-12-08-test.xml",101 serviceValid : true,102 annotationsValid : true103 },104 "Multiple Property Annotations": {105 service : "fakeService://testdata/odata/northwind/",106 annotations : "fakeService://testdata/odata/multiple-property-annotations.xml",107 serviceValid : true,108 annotationsValid : true109 },110 "Property Annotation Qualifiers": {111 service : "fakeService://testdata/odata/northwind/",112 annotations : "fakeService://testdata/odata/property-annotation-qualifiers.xml",113 serviceValid : true,114 annotationsValid : true115 },116 "Other Property Values": {117 service : "fakeService://testdata/odata/northwind/",118 annotations : "fakeService://testdata/odata/other-property-values.xml",119 serviceValid : true,120 annotationsValid : true121 },122 "Aliases in Namespaces": {123 service : "fakeService://testdata/odata/northwind/",124 annotations : "fakeService://testdata/odata/namespaces-aliases.xml",125 serviceValid : true,126 annotationsValid : true127 },128 "Namespaces in Other Property Values": {129 service : "fakeService://testdata/odata/northwind/",130 annotations : "fakeService://testdata/odata/other-property-value-aliases.xml",131 serviceValid : true,132 annotationsValid : true133 },134 "Text Properties" : {135 service : "fakeService://testdata/odata/northwind/",136 annotations : "fakeService://testdata/odata/other-property-textproperties.xml",137 serviceValid : true,138 annotationsValid : true139 },140 "Entity Containers": {141 service : "fakeService://testdata/odata/sapdata01/",142 annotations : "fakeService://testdata/odata/sapdata01/$metadata",143 serviceValid : true,144 annotationsValid : true145 }146 };147148149 // Add additional tests to stadard tests as well150 for (var sName in mAdditionalTestsServices) {151 var mTest = mAdditionalTestsServices[sName];152 mTest.name = sName;153 aServices.push(mTest);154 }155156 var 157 sTestName, sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid, bSharedMetadata,158 sTestType, fnTest, mService, i;159160 sap.ui.test.qunit.delayTestStart();161162 module("Asynchronous loading");163164 fnTest = function(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid, bSharedMetadata) {165 return function() {166 if (!bSharedMetadata){167 sap.ui.model.odata.v2.ODataModel.mServiceData = {};168 }169 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);170171 var bMetadataLoaded = false;172 var bAnnotationsLoaded = false;173174 var fnOnLoaded = function(sWhat) {175176 switch (sWhat) {177178 case "Metadata":179 ok(bMetadataLoaded, "Metadata loaded successfully");180 jQuery.sap.log.debug("check for metadata");181 break;182183 case "Annotations":184 ok(bAnnotationsLoaded, "Annotations loaded successfully");185 break;186187 case "Both":188 ok(bMetadataLoaded && bAnnotationsLoaded, "Check: Annotations and Metadata loaded");189 jQuery.sap.log.debug("check for both");190 start();191 break;192193 case "MetadataFailed": 194 // Nothing should be loaded195 ok(!bServiceValid && !bAnnotationsLoaded, "Check: Invalid Service - Annotations and Metadata NOT loaded");196 jQuery.sap.log.debug("check for none");197 start();198 break;199200 case "AnnotationsFailed":201 // Metadata should be loaded, but no annotations202 ok(bMetadataLoaded && !bAnnotationsLoaded, "Check: Invalid Annotations - Only Metadata loaded");203 jQuery.sap.log.debug("check for no annotations");204 start();205 break;206207 default:208 throw "This is unexpected and should never happen...";209210 }211 };212213 /* eslint-disable new-cap */214 var metadataDfd = jQuery.Deferred();215 var annotationsDfd = jQuery.Deferred();216 /* eslint-enable new-cap */217218 // Metadata must be loaded before annotations219 oModel.attachMetadataLoaded(function() {220 bMetadataLoaded = true;221 jQuery.sap.log.debug("metadata loaded is fired");222 fnOnLoaded("Metadata");223 metadataDfd.resolve();224 });225226 oModel.attachAnnotationsLoaded(function() {227 bAnnotationsLoaded = true;228 jQuery.sap.log.debug("annotations loaded is fired");229 fnOnLoaded("Annotations");230 annotationsDfd.resolve();231 });232233 oModel.attachMetadataFailed(function() {234 jQuery.sap.log.debug("metadata failed is fired");235 metadataDfd.reject();236 });237238 if (bServiceValid && bAnnotationsValid){239 jQuery.when(metadataDfd, annotationsDfd).done(function(e){240 jQuery.sap.log.debug("both promises fulfilled");241 fnOnLoaded("Both");242 }).fail(function(e){243 jQuery.sap.log.debug("metadata promise failed");244 ok(false, 'Metadata promise rejected');245 }); 246 } else if (bServiceValid && !bAnnotationsValid){247 jQuery.when(metadataDfd).done(function(e){248 jQuery.sap.log.debug("metadata promise fulfilled");249 //make sure annotations really don't load an we're not just too quick250 window.setTimeout(function() {251 fnOnLoaded("AnnotationsFailed");252 }, 50);253 });254 } else if (!bServiceValid){255 jQuery.when(metadataDfd).fail(function(e){256 jQuery.sap.log.debug("metadata failed fulfilled");257 fnOnLoaded("MetadataFailed");258 });259 }260 this.clock.tick(50);261 };262 };263264 for (i = 0; i < aServices.length; ++i) {265266 mService = aServices[i];267268 sServiceURI = mService.service;269 mModelOptions = {270 annotationURI : mService.annotations,271 json : true272 };273 bServiceValid = mService.serviceValid;274 bAnnotationsValid = mService.annotationsValid;275 bSharedMetadata = mService.sharedMetadata;276 sTestName = aServices[i].name ? aServices[i].name : "";277278 // Check asynchronous loading279 mModelOptions.loadAnnotationsJoined = false;280 mModelOptions.loadMetadataAsync = true;281 282 sTestType = 283 sTestName + " (" + 284 (bServiceValid ? "Valid Service" : "Broken Service") + "/" + 285 (bAnnotationsValid ? "Valid Annotations" : "Broken Annotations") +286 (bSharedMetadata ? "/Shared Metadata" : "") + 287 ")";288289 jQuery.sap.log.debug("testtype: " + sTestType);290291 asyncTest(292 "Asynchronous loading - " + sTestType,293 fnTest(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid)294 );295 }296297298 module("Asynchronous loading (joined events)");299300 fnTest = function(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid, bSharedMetadata) {301 return function() {302 if (!bSharedMetadata){303 sap.ui.model.odata.v2.ODataModel.mServiceData = {};304 }305 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);306 var that = this;307 var bMetadataLoaded = false;308 var bAnnotationsLoaded = false;309 var bInternalMetadataLoaded = false;310311 var fnOnLoaded = function(sWhat) {312313 switch (sWhat) {314315 case "InternalMetadata":316 ok(!bAnnotationsLoaded, "Internal metadata loaded before annotations");317 break;318319 case "Metadata":320 ok(bMetadataLoaded, "Metadata loaded successfully");321 ok(bAnnotationsLoaded, "Metadata loaded after annotations");322 break;323324 case "Both":325 ok(bMetadataLoaded && bAnnotationsLoaded, "Check: Annotations and Metadata loaded");326 jQuery.sap.log.debug("check for both");327 start();328 break;329330 case "MetadataFailed": 331 // Nothing should be loaded332 ok(!bInternalMetadataLoaded && !bAnnotationsLoaded, "Check: Invalid Service - Annotations and Metadata NOT loaded");333 jQuery.sap.log.debug("check for none");334 start();335 break;336337 case "AnnotationsFailed":338 // Metadata should be loaded, but no annotations339 ok(bInternalMetadataLoaded && !bAnnotationsLoaded, "Check: Invalid Annotations - Only Metadata loaded");340 jQuery.sap.log.debug("check for no annotations");341 start();342 break;343344 default:345 throw "This is unexpected and should never happen...";346 } 347348 };349350 /* eslint-disable new-cap */351 var metadataDfd = jQuery.Deferred();352 var internalMetadataDfd = jQuery.Deferred();353 /* eslint-enable new-cap */354355 // Use internal metadata loaded event, because in case of joined loading, the real one356 // does not fire until Annotations are there357 if (oModel.oMetadata.getServiceMetadata()){358 bInternalMetadataLoaded = true;359 fnOnLoaded("InternalMetadata");360 internalMetadataDfd.resolve();361 } else {362 oModel.oMetadata.attachLoaded(function() {363 bInternalMetadataLoaded = true;364 fnOnLoaded("InternalMetadata");365 internalMetadataDfd.resolve();366 });367 }368 // Metadata must be loaded before annotations369 oModel.attachMetadataLoaded(function() {370 bMetadataLoaded = true;371 if (oModel.bLoadMetadataAsync && oModel.bLoadAnnotationsJoined){372 // Metadata loaded event is only fired after both metadata and annotations have been loaded successfully, so we can also set bAnnotationsloaded to true373 bAnnotationsLoaded = true;374 }375 fnOnLoaded("Metadata");376 metadataDfd.resolve();377 });378379 oModel.attachMetadataFailed(function() {380 metadataDfd.reject();381 });382 oModel.attachAnnotationsLoaded(function() {383 bAnnotationsLoaded = true;384 });385386 if (bServiceValid && bAnnotationsValid){387 jQuery.when(metadataDfd).done(function(e){388 jQuery.sap.log.debug("metadata promise fulfilled");389 fnOnLoaded("Both");390 }).fail(function(e){391 jQuery.sap.log.debug("metadata promise failed");392 ok(false, 'Metadata promise rejected');393 }); 394 } else if (bServiceValid && !bAnnotationsValid){395 //internal metadata needs to be sucessful prior to the failed annotations396 jQuery.when(internalMetadataDfd).done(function(){397 jQuery.sap.log.debug("metadata promise rejected");398 oModel.attachAnnotationsFailed(function(){fnOnLoaded("AnnotationsFailed");}, that);399 });400 } else if (!bServiceValid){401 jQuery.when(metadataDfd).fail(function(e){402 jQuery.sap.log.debug("metadata failed fulfilled");403 fnOnLoaded("MetadataFailed");404 });405 }406 this.clock.tick(100);407 };408 };409410 for (i = 0; i < aServices.length; ++i) {411 mService = aServices[i];412413 sServiceURI = mService.service;414 mModelOptions = {415 annotationURI : mService.annotations,416 json : true417 };418 bServiceValid = mService.serviceValid;419 bAnnotationsValid = mService.annotationsValid;420 bSharedMetadata = mService.sharedMetadata;421 sTestName = aServices[i].name ? aServices[i].name : "";422 423 // Check asynchronous loading424 mModelOptions.loadAnnotationsJoined = true;425 mModelOptions.loadMetadataAsync = true;426427428 sTestType = 429 sTestName + " (" +430 (bServiceValid ? "Valid Service" : "Broken Service") + "/" +431 (bAnnotationsValid ? "Valid Annotations" : "Broken Annotations") +432 (bSharedMetadata ? "/Shared Metadata" : "") +433 ")";434435 asyncTest(436 "Asynchronous loading (joined events) - " + sTestType,437 fnTest(sServiceURI, mModelOptions, bServiceValid, bAnnotationsValid)438 ); 439 }440441442 module("Multiple Annotation Sources Merged");443444 asyncTest("Asynchronous loading", function() {445 expect(6);446 var asyncStartsExpected = 2; // The number of asynchronous starts expected before the real start is triggered447448 var oModel3 = new sap.ui.model.odata.v2.ODataModel(449 "fakeService://testdata/odata/northwind-annotated/", 450 {451 annotationURI : [452 "fakeService://testdata/odata/northwind-annotations-normal.xml",453 "fakeService://testdata/odata/northwind-annotated/$metadata"454 ],455 json : true,456 loadAnnotationsJoined : false,457 loadMetadataAsync : true458 }459 );460 oModel3.attachAnnotationsLoaded(function() {461 var oAnnotations = oModel3.getServiceAnnotations();462 ok(oAnnotations.UnitTest["Test.FromAnnotations"][0].Value.Path === "Annotations", "Annotation from correct source (Annotations)");463 ok(oAnnotations.UnitTest["Test.FromMetadata"][0].Value.Path === "Metadata", "Annotation from correct source (Metadata)");464 ok(oAnnotations.UnitTest["Test.Merged"][0].Value.Path === "Metadata", "Annotation from correct source (Metadata)");465 asyncStart();466 });467468 var oModel4 = new sap.ui.model.odata.v2.ODataModel(469 "fakeService://testdata/odata/northwind-annotated/", 470 {471 annotationURI : [472 "fakeService://testdata/odata/northwind-annotated/$metadata",473 "fakeService://testdata/odata/northwind-annotations-normal.xml"474 ],475 json : true,476 loadAnnotationsJoined : false,477 loadMetadataAsync : true478 }479 );480 oModel4.attachAnnotationsLoaded(function() {481 var oAnnotations = oModel4.getServiceAnnotations();482 ok(oAnnotations.UnitTest["Test.FromAnnotations"][0].Value.Path === "Annotations", "Annotation from correct source (Annotations)");483 ok(oAnnotations.UnitTest["Test.FromMetadata"][0].Value.Path === "Metadata", "Annotation from correct source (Metadata)");484 ok(oAnnotations.UnitTest["Test.Merged"][0].Value.Path === "Annotations", "Annotation from correct source (Annotations)");485 asyncStart();486 });487488489 function asyncStart() {490 if (asyncStart.num === undefined) {491 asyncStart.num = 0;492 }493494 if (++asyncStart.num >= asyncStartsExpected) {495 oModel3.destroy();496 oModel4.destroy();497498 start();499 }500 }501 502 });503504505506 module("Additional tests for fixed bugs");507508509 asyncTest("Test 2014-12-08", function() {510 expect(12);511512 var mTest = mAdditionalTestsServices["Test 2014-12-08"];513 var sServiceURI = mTest.service;514 var mModelOptions = {515 annotationURI : mTest.annotations,516 json : true,517 loadAnnotationsJoined: false518 };519520 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);521 oModel.attachAnnotationsLoaded(function() {522 var oMetadata = oModel.getServiceMetadata();523 var oAnnotations = oModel.getServiceAnnotations();524 525 ok(!!oMetadata, "Metadata is available.");526 ok(!!oAnnotations, "Annotations are available.");527 528 ok(529 !!oAnnotations530 ["Test.2014-12-08"],531 "Test Annotations are available"532 );533 ok(534 !!oAnnotations535 ["Test.2014-12-08"]536 ["com.sap.vocabularies.UI.v1.Identification"],537 "Namespace exists"538 );539 ok(540 !!oAnnotations541 ["Test.2014-12-08"]542 ["com.sap.vocabularies.UI.v1.Identification"]543 [0],544 "Namespace has content"545 );546 547 548 var mNamespace = oAnnotations["Test.2014-12-08"]["com.sap.vocabularies.UI.v1.Identification"][0];549 550 ok(551 !!mNamespace552 ["com.sap.vocabularies.UI.v1.Importance"],553 "Sub-namespace exists"554 );555 ok(556 !!mNamespace557 ["com.sap.vocabularies.UI.v1.Importance"]558 ["EnumMember"],559 "EnumMember exists"560 );561 equal(562 mNamespace563 ["com.sap.vocabularies.UI.v1.Importance"]564 ["EnumMember"],565 "com.sap.vocabularies.UI.v1.Priority/High",566 "EnumMember has correct value"567 );568 569 ok(!!mNamespace["RecordType"], "RecordType exists");570 equal(571 mNamespace["RecordType"],572 "com.sap.vocabularies.UI.v1.DataField",573 "RecordType has correct value"574 );575 576 ok(!!mNamespace["Value"], "Value exists");577 578 var mCorrectValue = {579 "Apply": {580 "Name" : "odata.concat",581 "Parameters" : [{582 "Type" : "Path",583 "Value" : "CompanyCodeTESet/ContactPerson"584 }, {585 "Type" : "String",586 "Value" : " ("587 }, {588 "Type" : "Path",589 "Value" : "CompanyCode"590 }, {591 "Type" : "String",592 "Value" : ")"593 }]594 }595 };596 597 deepEqual(mNamespace["Value"], mCorrectValue, "Value has correct value");598 start();599 });600 });601602603 asyncTest("Multiple Property Annotations", function() {604 expect(11);605606 var mTest = mAdditionalTestsServices["Multiple Property Annotations"];607 var sServiceURI = mTest.service;608 var mModelOptions = {609 annotationURI : mTest.annotations,610 json : true,611 loadAnnotationsJoined: false,612 loadMetadataAsync: false613 };614615 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);616 oModel.attachAnnotationsLoaded(function() {617 var oMetadata = oModel.getServiceMetadata();618 var oAnnotations = oModel.getServiceAnnotations();619 620 ok(!!oMetadata, "Metadata is available.");621 ok(!!oAnnotations, "Annotations are available.");622 623 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");624 625 ok(626 !!oAnnotations["propertyAnnotations"]["MultiplePropertyAnnotations.Product"],627 "Target namespace inside PropertyAnnotations exists"628 );629 630 ok(631 !!oAnnotations["propertyAnnotations"]["MultiplePropertyAnnotations.Product"]["Price/Amount"],632 "Target values exist"633 );634 635 ok(636 !!oAnnotations637 ["propertyAnnotations"]638 ["MultiplePropertyAnnotations.Product"]639 ["Price/Amount"]640 ["CQP.ISOCurrency"],641 "Target value 1 exists"642 );643 644 ok(645 !!oAnnotations646 ["propertyAnnotations"]647 ["MultiplePropertyAnnotations.Product"]648 ["Price/Amount"]649 ["Common.Label"],650 "Target value 2 exists"651 );652 653 ok(654 !!oAnnotations655 ["propertyAnnotations"]656 ["MultiplePropertyAnnotations.Product"]657 ["Price/Amount"]658 ["CQP.ISOCurrency"]659 ["Path"],660 "Target value 1 property exists"661 );662 663 ok(664 !!oAnnotations665 ["propertyAnnotations"]666 ["MultiplePropertyAnnotations.Product"]667 ["Price/Amount"]668 ["Common.Label"]669 ["String"],670 "Target value 2 property exists"671 );672 673 equal(674 oAnnotations675 ["propertyAnnotations"]676 ["MultiplePropertyAnnotations.Product"]677 ["Price/Amount"]678 ["CQP.ISOCurrency"]679 ["Path"],680 "Price/CurrencyCode",681 "Target value 1 property exists"682 );683 684 equal(685 oAnnotations686 ["propertyAnnotations"]687 ["MultiplePropertyAnnotations.Product"]688 ["Price/Amount"]689 ["Common.Label"]690 ["String"],691 "Price",692 "Target value 2 property exists"693 );694 start();695 });696 });697698699 asyncTest("Qualifiers in Property Annotations", function() {700 expect(8);701702 var mTest = mAdditionalTestsServices["Property Annotation Qualifiers"];703 var sServiceURI = mTest.service;704 var mModelOptions = {705 annotationURI : mTest.annotations,706 json : true,707 loadAnnotationsJoined: false,708 loadMetadataAsync: false709 };710711 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);712 oModel.attachAnnotationsLoaded(function() {713 var oMetadata = oModel.getServiceMetadata();714 var oAnnotations = oModel.getServiceAnnotations();715 716 ok(!!oMetadata, "Metadata is available.");717 ok(!!oAnnotations, "Annotations are available.");718 719 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");720 721 ok(722 !!oAnnotations["propertyAnnotations"]["PropertyAnnotationQualifiers.Product"],723 "Target namespace inside PropertyAnnotations exists"724 );725 726 ok(727 !!oAnnotations728 ["propertyAnnotations"]["PropertyAnnotationQualifiers.Product"]["Price/Amount"],729 "Target value exists"730 );731 732 ok(733 !!oAnnotations734 ["propertyAnnotations"]735 ["PropertyAnnotationQualifiers.Product"]736 ["Price/Amount"]737 ["CQP.ISOCurrency#Amount1"],738 "Target value with Qualifier exists"739 );740 741 ok(742 !!oAnnotations743 ["propertyAnnotations"]744 ["PropertyAnnotationQualifiers.Product"]745 ["Price/Amount"]746 ["CQP.ISOCurrency#Amount1"]747 ["Path"],748 "Target value with Qualifier value exists"749 );750 751 equal(752 oAnnotations753 ["propertyAnnotations"]754 ["PropertyAnnotationQualifiers.Product"]755 ["Price/Amount"]756 ["CQP.ISOCurrency#Amount1"]757 ["Path"],758 "Price/CurrencyCode",759 "Target value with Qualifier value has correct content"760 );761 start();762 });763 });764765766 asyncTest("Other Property Values", function() {767 expect(8);768769 var mTest = mAdditionalTestsServices["Other Property Values"];770 var sServiceURI = mTest.service;771 var mModelOptions = {772 annotationURI : mTest.annotations,773 json : true,774 loadAnnotationsJoined: false,775 loadMetadataAsync: false776 };777778 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);779 oModel.attachAnnotationsLoaded(function() {780 var oMetadata = oModel.getServiceMetadata();781 var oAnnotations = oModel.getServiceAnnotations();782 783 ok(!!oMetadata, "Metadata is available.");784 ok(!!oAnnotations, "Annotations are available.");785 786 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");787 788 ok(789 !!oAnnotations["propertyAnnotations"]["OtherPropertyValues.Product"],790 "Target namespace inside PropertyAnnotations exists"791 );792 793 ok(794 !!oAnnotations795 ["propertyAnnotations"]["OtherPropertyValues.Product"]["Price/Amount"],796 "Target value exists"797 );798 799 ok(800 !!oAnnotations801 ["propertyAnnotations"]802 ["OtherPropertyValues.Product"]803 ["Price/Amount"]804 ["CQP.ISOCurrency#Amount2"],805 "Target value with Qualifier exists"806 );807 808 ok(809 !!oAnnotations810 ["propertyAnnotations"]811 ["OtherPropertyValues.Product"]812 ["Price/Amount"]813 ["CQP.ISOCurrency#Amount2"]814 ["String"],815 "Target value with Qualifier value exists"816 );817 818 equal(819 oAnnotations820 ["propertyAnnotations"]821 ["OtherPropertyValues.Product"]822 ["Price/Amount"]823 ["CQP.ISOCurrency#Amount2"]824 ["String"],825 "EUR",826 "Target value with Qualifier value has correct content"827 );828 start();829 });830 });831832 asyncTest("Aliases in Namespaces", function() {833 expect(8);834835 var mTest = mAdditionalTestsServices["Aliases in Namespaces"];836 var sServiceURI = mTest.service;837 var mModelOptions = {838 annotationURI : mTest.annotations,839 json : true,840 loadAnnotationsJoined: false,841 loadMetadataAsync: false842 };843844 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);845 oModel.attachAnnotationsLoaded(function() {846 var oMetadata = oModel.getServiceMetadata();847 var oAnnotations = oModel.getServiceAnnotations();848 849 ok(!!oMetadata, "Metadata is available.");850 ok(!!oAnnotations, "Annotations are available.");851 852 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");853 854 ok(855 !!oAnnotations["propertyAnnotations"]["NamespaceAliases.PurchaseOrder"],856 "Target namespace inside PropertyAnnotations exists"857 );858 859 ok(860 !!oAnnotations861 ["propertyAnnotations"]["NamespaceAliases.PurchaseOrder"]["GrossAmount"],862 "Target value exists"863 );864 865 ok(866 !!oAnnotations867 ["propertyAnnotations"]868 ["NamespaceAliases.PurchaseOrder"]869 ["GrossAmount"]870 ["com.sap.vocabularies.Common.v1.Label"],871 "Target value with correct alias replacement (none!) exists"872 );873 874 ok(875 !!oAnnotations876 ["propertyAnnotations"]877 ["NamespaceAliases.PurchaseOrder"]878 ["GrossAmount"]879 ["com.sap.vocabularies.Common.v1.Label"]880 ["String"],881 "Target value with String value exists"882 );883 884 equal(885 oAnnotations886 ["propertyAnnotations"]887 ["NamespaceAliases.PurchaseOrder"]888 ["GrossAmount"]889 ["com.sap.vocabularies.Common.v1.Label"]890 ["String"],891 "Gross Amount",892 "Target value String value has correct content"893 );894 start();895 });896 });897 898 asyncTest("Namespaces in Other Property Values", function() {899 expect(22);900901 var mTest = mAdditionalTestsServices["Namespaces in Other Property Values"];902 var sServiceURI = mTest.service;903 var mModelOptions = {904 annotationURI : mTest.annotations,905 json : true,906 loadAnnotationsJoined: false,907 loadMetadataAsync: false908 };909910 var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceURI, mModelOptions);911 oModel.attachAnnotationsLoaded(function() {912 var oMetadata = oModel.getServiceMetadata();913 var oAnnotations = oModel.getServiceAnnotations();914 915 ok(!!oMetadata, "Metadata is available.");916 917 ok(!!oAnnotations, "Annotations are available.");918 919 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations namespace exists");920 921 ok(922 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"],923 "Target value exists"924 );925 926 927 ok(928 !!oAnnotations929 ["propertyAnnotations"]930 ["OtherPropertyValueAliases.Test"]931 ["Value"]932 ["com.sap.vocabularies.UI.v1.Name"],933 "Target value's namespace has been correctly replaced"934 );935 ok(936 !!oAnnotations937 ["propertyAnnotations"]938 ["OtherPropertyValueAliases.Test"]939 ["Value"]940 ["com.sap.vocabularies.UI.v1.Name"]941 ["EnumMember"],942 "Target value's child exists"943 );944 equal(945 oAnnotations946 ["propertyAnnotations"]947 ["OtherPropertyValueAliases.Test"]948 ["Value"]949 ["com.sap.vocabularies.UI.v1.Name"]950 ["EnumMember"],951 "com.sap.vocabularies.UI.v1.Value",952 "Target value's namespace has been correctly replaced"953 );954 955 956 ok(957 !!oAnnotations958 ["propertyAnnotations"]959 ["OtherPropertyValueAliases.Test"]960 ["Value"]961 ["com.sap.vocabularies.Communication.v1.Name"],962 "Target value's namespace has been correctly replaced"963 );964 ok(965 !!oAnnotations966 ["propertyAnnotations"]967 ["OtherPropertyValueAliases.Test"]968 ["Value"]969 ["com.sap.vocabularies.Communication.v1.Name"]970 ["EnumMember"],971 "Target value's child exists"972 );973 equal(974 oAnnotations975 ["propertyAnnotations"]976 ["OtherPropertyValueAliases.Test"]977 ["Value"]978 ["com.sap.vocabularies.Communication.v1.Name"]979 ["EnumMember"],980 "com.sap.vocabularies.Communication.v1.Value",981 "Target value's namespace has been correctly replaced"982 );983 984 985 ok(986 !!oAnnotations987 ["propertyAnnotations"]988 ["OtherPropertyValueAliases.Test"]989 ["Value"]990 ["Org.OData.Measures.V1.Name"],991 "Target value's namespace has been correctly replaced"992 );993 ok(994 !!oAnnotations995 ["propertyAnnotations"]996 ["OtherPropertyValueAliases.Test"]997 ["Value"]998 ["Org.OData.Measures.V1.Name"]999 ["EnumMember"],1000 "Target value's child exists"1001 );1002 equal(1003 oAnnotations1004 ["propertyAnnotations"]1005 ["OtherPropertyValueAliases.Test"]1006 ["Value"]1007 ["Org.OData.Measures.V1.Name"]1008 ["EnumMember"],1009 "Org.OData.Measures.V1.Value",1010 "Target value's namespace has been correctly replaced"1011 );1012 1013 1014 ok(1015 !!oAnnotations1016 ["propertyAnnotations"]1017 ["OtherPropertyValueAliases.Test"]1018 ["Value"]1019 ["Org.OData.Measures.V1.Name"],1020 "Target value's namespace has been correctly replaced"1021 );1022 ok(1023 !!oAnnotations1024 ["propertyAnnotations"]1025 ["OtherPropertyValueAliases.Test"]1026 ["Value"]1027 ["Org.OData.Measures.V1.Name"]1028 ["EnumMember"],1029 "Target value's child exists"1030 );1031 equal(1032 oAnnotations1033 ["propertyAnnotations"]1034 ["OtherPropertyValueAliases.Test"]1035 ["Value"]1036 ["Org.OData.Measures.V1.Name"]1037 ["EnumMember"],1038 "Org.OData.Measures.V1.Value",1039 "Target value's namespace has been correctly replaced"1040 );1041 1042 1043 ok(1044 !!oAnnotations1045 ["propertyAnnotations"]1046 ["OtherPropertyValueAliases.Test"]1047 ["Value"]1048 ["com.sap.vocabularies.Common.v1.Name"],1049 "Target value's namespace has been correctly replaced"1050 );1051 ok(1052 !!oAnnotations1053 ["propertyAnnotations"]1054 ["OtherPropertyValueAliases.Test"]1055 ["Value"]1056 ["com.sap.vocabularies.Common.v1.Name"]1057 ["EnumMember"],1058 "Target value's child exists"1059 );1060 equal(1061 oAnnotations1062 ["propertyAnnotations"]1063 ["OtherPropertyValueAliases.Test"]1064 ["Value"]1065 ["com.sap.vocabularies.Common.v1.Name"]1066 ["EnumMember"],1067 "com.sap.vocabularies.Common.v1.Value",1068 "Target value's namespace has been correctly replaced"1069 );1070 1071 1072 ok(1073 !!oAnnotations1074 ["propertyAnnotations"]1075 ["OtherPropertyValueAliases.Test"]1076 ["Value"]1077 ["FTGEN_HB_TE.Name"],1078 "Target value's namespace has been correctly replaced"1079 );1080 ok(1081 !!oAnnotations1082 ["propertyAnnotations"]1083 ["OtherPropertyValueAliases.Test"]1084 ["Value"]1085 ["FTGEN_HB_TE.Name"]1086 ["EnumMember"],1087 "Target value's child exists"1088 );1089 equal(1090 oAnnotations1091 ["propertyAnnotations"]1092 ["OtherPropertyValueAliases.Test"]1093 ["Value"]1094 ["FTGEN_HB_TE.Name"]1095 ["EnumMember"],1096 "FTGEN_HB_TE.Value",1097 "Target value's namespace has been correctly replaced"1098 );1099 start();1100 });1101 });11021103 test("Text Properties", function() {1104 expect(14);11051106 var mTest = mAdditionalTestsServices["Text Properties"];1107 var sServiceURI = mTest.service;1108 var mModelOptions = {1109 annotationURI : mTest.annotations,1110 json : true,1111 loadAnnotationsJoined: false,1112 loadMetadataAsync: false1113 };11141115 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1116 var oMetadata = oModel.getServiceMetadata();1117 var oAnnotations = oModel.getServiceAnnotations();11181119 ok(!!oMetadata, "Metadata is available.");11201121 ok(!!oAnnotations, "Annotations are available.");11221123 ok(!!oAnnotations["propertyAnnotations"], "PropertyAnnotations group exists");1124 1125 ok(1126 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"],1127 "PropertyAnnotation definition exists"1128 );1129 1130 ok(1131 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"],1132 "PropertyAnnotation definition value exists"1133 );1134 1135 ok(1136 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name1"],1137 "Name1 with replaced alias exists"1138 );1139 ok(1140 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name2"],1141 "Name2 with replaced alias exists"1142 );1143 ok(1144 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name3"],1145 "Name3 with replaced alias exists"1146 );1147 1148 ok(1149 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name1"]["EnumMember"],1150 "Name1 with replaced alias exists and has EnumMember child node"1151 );1152 ok(1153 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name2"]["String"],1154 "Name2 with replaced alias exists and has String child node"1155 );1156 ok(1157 !!oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name3"]["Invalid"],1158 "Name3 with replaced alias exists and has Invalid child node"1159 );1160 1161 equals(1162 oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name1"]["EnumMember"],1163 "com.sap.vocabularies.UI.v1.Value",1164 "Name1 with replaced alias exists and has EnumMember child node that contains alias replaced tet with trimmed white-spaces"1165 );1166 equals(1167 oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name2"]["String"],1168 " test test ",1169 "Name2 with replaced alias exists and has String child node that contains the exact text inclunding white-spaces"1170 );1171 deepEqual(1172 oAnnotations["propertyAnnotations"]["OtherPropertyValueAliases.Test"]["Value"]["com.sap.vocabularies.UI.v1.Name3"]["Invalid"],1173 {},1174 "Name3 with replaced alias exists and has Invalid child node that only contains an empy object"1175 );1176 11771178 });1179 1180 test("Entity Containers", function() {1181 expect(30);11821183 var mTest = mAdditionalTestsServices["Entity Containers"];1184 var sServiceURI = mTest.service;1185 var mModelOptions = {1186 annotationURI : mTest.annotations,1187 json : true,1188 loadAnnotationsJoined: false,1189 loadMetadataAsync: false1190 };11911192 var oModel = new sap.ui.model.odata.ODataModel(sServiceURI, mModelOptions);1193 var oMetadata = oModel.getServiceMetadata();1194 var oAnnotations = oModel.getServiceAnnotations();11951196 ok(!!oMetadata, "Metadata is available.");11971198 ok(!!oAnnotations, "Annotations are available.");11991200 1201 ok(!!oAnnotations["EntityContainer"], "Entity container entry exists");1202 1203 ok(!!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"], "Entity container exists");1204 1205 ok(1206 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1207 ["SalesOrder"],1208 "Entity in container exists"1209 );12101211 ok(1212 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1213 ["SalesOrder"]1214 ["com.sap.vocabularies.Common.v1.DraftRoot"],1215 "Sub Entity in container exists"1216 );12171218 ok(1219 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1220 ["SalesOrder"]1221 ["com.sap.vocabularies.Common.v1.DraftRoot"]1222 ["ActivationAction"],1223 "Sub Entity value in container exists"1224 );1225 ok(1226 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1227 ["SalesOrder"]1228 ["com.sap.vocabularies.Common.v1.DraftRoot"]1229 ["ActivationAction"]1230 ["String"],1231 "Sub Entity value in container exists"1232 );1233 equal(1234 oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1235 ["SalesOrder"]1236 ["com.sap.vocabularies.Common.v1.DraftRoot"]1237 ["ActivationAction"]1238 ["String"],1239 "AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities/Activate",1240 "Sub Entity value in container exists"1241 );1242 1243 ok(1244 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1245 ["SalesOrder"]1246 ["com.sap.vocabularies.Common.v1.DraftRoot"]1247 ["EditAction"],1248 "Sub Entity value in container exists"1249 );1250 ok(1251 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1252 ["SalesOrder"]1253 ["com.sap.vocabularies.Common.v1.DraftRoot"]1254 ["EditAction"]1255 ["String"],1256 "Sub Entity value in container exists"1257 );1258 equal(1259 oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1260 ["SalesOrder"]1261 ["com.sap.vocabularies.Common.v1.DraftRoot"]1262 ["EditAction"]1263 ["String"],1264 "AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities/Edit",1265 "Sub Entity value in container exists"1266 );1267 1268 ok(1269 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1270 ["SalesOrder"]1271 ["com.sap.vocabularies.Common.v1.DraftRoot"]1272 ["ValidationFunction"],1273 "Sub Entity value in container exists"1274 );1275 ok(1276 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1277 ["SalesOrder"]1278 ["com.sap.vocabularies.Common.v1.DraftRoot"]1279 ["ValidationFunction"]1280 ["String"],1281 "Sub Entity value in container exists"1282 );1283 equal(1284 oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1285 ["SalesOrder"]1286 ["com.sap.vocabularies.Common.v1.DraftRoot"]1287 ["ValidationFunction"]1288 ["String"],1289 "AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities/Validate",1290 "Sub Entity value in container exists"1291 );1292 1293 ok(1294 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1295 ["SalesOrder"]1296 ["com.sap.vocabularies.Common.v1.DraftRoot"]1297 ["PreparationAction"],1298 "Sub Entity value in container exists"1299 );1300 ok(1301 !!oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1302 ["SalesOrder"]1303 ["com.sap.vocabularies.Common.v1.DraftRoot"]1304 ["PreparationAction"]1305 ["String"],1306 "Sub Entity value in container exists"1307 );1308 equal(1309 oAnnotations["EntityContainer"]["AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities"]1310 ["SalesOrder"]1311 ["com.sap.vocabularies.Common.v1.DraftRoot"]1312 ["PreparationAction"]1313 ["String"],1314 "AIVS_NEW_BO_SRV.AIVS_NEW_BO_SRV_Entities/Prepare",1315 "Sub Entity value in container exists"1316 );1317 1318 ok(1319 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"],1320 "Entity in namespace exists"1321 );1322 ok(1323 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"]1324 ["com.sap.vocabularies.Common.v1.SemanticKey"],1325 "Entity in namespace exists"1326 );1327 ok(1328 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"]1329 ["com.sap.vocabularies.Common.v1.SemanticKey"]1330 [0],1331 "Entity entries in namespace exists"1332 );1333 ok(1334 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"]1335 ["com.sap.vocabularies.Common.v1.SemanticKey"]1336 [0]1337 ["PropertyPath"],1338 "Property exists"1339 );1340 equal(1341 oAnnotations["AIVS_NEW_BO_SRV.SalesOrderType"]1342 ["com.sap.vocabularies.Common.v1.SemanticKey"]1343 [0]1344 ["PropertyPath"],1345 "SalesOrderID",1346 "Entity in namespace exists"1347 );1348 1349 ok(1350 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"],1351 "Entity in namespace exists"1352 );1353 ok(1354 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1355 ["com.sap.vocabularies.Common.v1.SemanticKey"],1356 "Entity in namespace exists"1357 );1358 ok(1359 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1360 ["com.sap.vocabularies.Common.v1.SemanticKey"]1361 [0],1362 "Entity entries in namespace exists"1363 );1364 ok(1365 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1366 ["com.sap.vocabularies.Common.v1.SemanticKey"]1367 [0]1368 ["PropertyPath"],1369 "Property exists"1370 );1371 ok(1372 !!oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1373 ["com.sap.vocabularies.Common.v1.SemanticKey"]1374 [1]1375 ["PropertyPath"],1376 "Property exists"1377 );1378 equal(1379 oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1380 ["com.sap.vocabularies.Common.v1.SemanticKey"]1381 [0]1382 ["PropertyPath"],1383 "SalesOrderID",1384 "Entity in namespace exists"1385 );1386 equal(1387 oAnnotations["AIVS_NEW_BO_SRV.SalesOrderItemType"]1388 ["com.sap.vocabularies.Common.v1.SemanticKey"]1389 [1]1390 ["PropertyPath"],1391 "SalesOrderItemID",1392 "Entity in namespace exists"1393 );1394 }); ...

Full Screen

Full Screen

annotation.service.ts

Source:annotation.service.ts Github

copy

Full Screen

1import { Injectable } from '@angular/core';2import { Hotkey } from '@app/config';3import { EventEmitter } from '@app/event';4import { ProcessStorageService, StorageService } from '@app/storage';5import { Observable, of } from 'rxjs';6import { flatMap, map, mergeMap } from 'rxjs/operators';7import { Annotation, AnnotationCondition, AnnotationConditionMap, AnnotationMap, AnnotationMessage } from './annotation';8const ANNOTATION_DATA_KEY = 'ANNOTATION_DATA';9const ANNOTATIONS: Annotation[] = [10 { id: 'welcome' },11 {12 id: 'settings',13 hotkey: Hotkey.SettingsToggle,14 expressions: [AnnotationCondition.SettingsOpen],15 children: [16 { id: 'game-settings' },17 { id: 'app-settings' },18 {19 id: 'close',20 hotkey: Hotkey.SettingsToggle,21 expressions: [AnnotationCondition.SettingsClose]22 }23 ]24 },25 {26 id: 'commands',27 hotkey: Hotkey.Command1,28 expressions: [AnnotationCondition.CommandExecuted],29 skippable: true30 },31 {32 id: 'market',33 hotkey: Hotkey.MarketToggle,34 expressions: [AnnotationCondition.MarketOpen],35 children: [36 { id: 'filter' },37 { id: 'search' },38 { id: 'reset' },39 {40 id: 'close',41 hotkey: Hotkey.MarketToggle,42 expressions: [AnnotationCondition.MarketClose]43 }44 ]45 },46 { id: 'trade.init' },47 { id: 'trade.incoming' },48 { id: 'trade.highlight' },49 { id: 'trade.outgoing' },50 { id: 'trade.settings' },51 {52 id: 'evaluate',53 hotkey: Hotkey.Evaluate,54 expressions: [AnnotationCondition.EvaluateOpen],55 children: [56 { id: 'properties' },57 { id: 'stats' },58 { id: 'price' },59 { id: 'search' },60 { id: 'options' },61 { id: 'settings' },62 { id: 'close', expressions: [AnnotationCondition.EvaluateClose] }63 ]64 },65 {66 id: 'inspect',67 hotkey: Hotkey.Inspect,68 expressions: [AnnotationCondition.InspectOpen],69 children: [70 { id: 'loot' },71 { id: 'urls' },72 { id: 'settings' },73 { id: 'close', expressions: [AnnotationCondition.InspectClose] }74 ]75 },76 {77 id: 'replay',78 hotkey: Hotkey.SettingsToggle79 },80 {81 id: 'misc',82 hotkey: Hotkey.MiscStashHighlight,83 expressions: [AnnotationCondition.MiscStashHighlightExecuted],84 skippable: true,85 },86 {87 id: 'bookmarks',88 hotkey: Hotkey.Bookmark1,89 expressions: [AnnotationCondition.BookmarkOpened],90 skippable: true91 },92 {93 id: 'support',94 hotkey: Hotkey.SettingsToggle95 },96 { id: 'thanks' },97 { id: 'changelog-1-0-11' },98];99@Injectable({100 providedIn: 'root'101})102export class AnnotationService {103 private get conditions(): AnnotationConditionMap {104 return this.processStorage.get(`${ANNOTATION_DATA_KEY}_CONDITIONS`, () => ({}));105 }106 constructor(107 private readonly processStorage: ProcessStorageService,108 private readonly storage: StorageService) { }109 public get message$(): EventEmitter<AnnotationMessage> {110 return this.processStorage.get(`${ANNOTATION_DATA_KEY}_MESSAGE`, () => new EventEmitter<AnnotationMessage>());111 }112 public init(): Observable<void> {113 return this.getAnnotations().pipe(114 mergeMap(annotations => {115 this.updateMessage(annotations, false);116 return this.updateAnnotations(annotations);117 })118 );119 }120 public continue(): Observable<void> {121 return this.getAnnotations().pipe(122 mergeMap(annotations => {123 this.updateMessage(annotations, true);124 return this.updateAnnotations(annotations);125 })126 );127 }128 public skip(): Observable<void> {129 return this.getAnnotations().pipe(130 mergeMap(annotations => {131 for (const annotation of ANNOTATIONS) {132 if (annotation.id === 'thanks' || annotation.id.startsWith('changelog')) {133 continue;134 }135 annotations[annotation.id] = true;136 }137 this.updateMessage(annotations, false);138 return this.updateAnnotations(annotations);139 })140 );141 }142 public update(condition: AnnotationCondition, value: boolean): Observable<void> {143 return this.getAnnotations().pipe(144 mergeMap(annotations => {145 this.conditions[condition] = value;146 this.updateMessage(annotations, false);147 return this.updateAnnotations(annotations);148 })149 );150 }151 private updateMessage(annotations: AnnotationMap, next: boolean): void {152 for (const annotation of ANNOTATIONS) {153 if (annotations[annotation.id]) {154 continue;155 }156 if (annotation.expressions) {157 if (annotation.expressions.some(x => !this.conditions[x])) {158 if (!(annotation.skippable && next)) {159 return this.setMessage(annotation);160 }161 }162 if (!annotation.children) {163 next = true;164 }165 }166 if (annotation.children) {167 for (const child of annotation.children) {168 const id = `${annotation.id}.${child.id}`;169 if (annotations[id]) {170 continue;171 }172 if (child.expressions) {173 if (child.expressions.some(x => !this.conditions[x])) {174 if (!(child.skippable && next)) {175 return this.setMessage(child, id);176 }177 }178 next = false;179 annotations[id] = true;180 } else {181 if (next) {182 next = false;183 annotations[id] = true;184 } else {185 return this.setMessage(child, id);186 }187 }188 }189 // next annotation if all children have been annotated190 next = true;191 }192 if (next) {193 next = false;194 annotations[annotation.id] = true;195 } else {196 return this.setMessage(annotation);197 }198 }199 return this.clearMessage();200 }201 private getAnnotations(): Observable<AnnotationMap> {202 return of(null).pipe(203 mergeMap(() => this.storage.get<AnnotationMap>(`${ANNOTATION_DATA_KEY}_ANNOTATIONS`)),204 map(value => value || {})205 );206 }207 private updateAnnotations(annotations: AnnotationMap): Observable<void> {208 return this.storage.put(`${ANNOTATION_DATA_KEY}_ANNOTATIONS`, annotations).pipe(209 map(() => null)210 );211 }212 private clearMessage(): void {213 this.message$.next(undefined);214 }215 private setMessage(annotation: Annotation, id?: string): void {216 this.message$.next({217 id: id || annotation.id,218 title: `annotation.${id || annotation.id}.title`,219 message: `annotation.${id || annotation.id}.message`,220 skippable: annotation.skippable || !annotation.expressions?.length,221 hotkey: annotation.hotkey222 });223 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withRootDecorator } from 'storybook-root-decorator';2import { withKnobs } from '@storybook/addon-knobs';3import { withA11y } from '@storybook/addon-a11y';4import { withTests } from '@storybook/addon-jest';5import results from '../.jest-test-results.json';6 withTests({ results }),7];8export const parameters = {9 actions: { argTypesRegex: '^on[A-Z].*' },10 backgrounds: {11 {12 },13 {14 },15 },16};17import { addDecorator } from '@storybook/react';18import { withRootDecorator } from 'storybook-root-decorator';19addDecorator(withRootDecorator);20const path = require('path');21const toPath = (_path) => path.join(process.cwd(), _path);22module.exports = {23 stories: ['../src/**/*.stories.(js|mdx)'],24 webpackFinal: async (config) => {25 config.module.rules.push({26 include: toPath('../src'),27 });28 return config;29 },30};31import { addons } from '@storybook/addons';32import { create } from '@storybook/theming';33addons.setConfig({34 theme: create({35 }),36});37 window.__STORYBOOK_ADDON_ROOT_DECORATOR__ = {38 annotations: {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withKnobs, text } from '@storybook/addon-knobs';2import { storiesOf } from '@storybook/react';3storiesOf('Button', module)4 .addDecorator(withKnobs)5 .add('with text', () => (6 <button>{text('Label', 'Hello Button')}</button>7 ));8import { configure, addDecorator } from '@storybook/react';9import { withKnobs } from '@storybook/addon-knobs';10configure(() => {11 require('../test.js');12}, module);13The decorator should be added before the stories are imported. In your case, before14configure(() => {15 require('../test.js');16}, module);17The decorator should be added before the stories are imported. In your case, before18configure(() => {19 require('../test.js');20}, module);21The decorator should be added before the stories are imported. In your case, before22configure(() => {23 require('../test.js');24}, module);25The decorator should be added before the stories are imported. In your case, before26configure(() => {27 require('../test.js');28}, module);29The decorator should be added before the stories are imported. In your case, before30configure(() => {31 require('../test.js');32}, module);33The decorator should be added before the stories are imported. In your case, before34configure(() => {35 require('../test.js');36}, module);37The decorator should be added before the stories are imported. In your case, before38configure(() => {39 require('../test.js');40}, module);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { annotations } from 'storybook-root-decorator';2const annotations = require('storybook-root-decorator').annotations;3const annotations = require('storybook-root-decorator/annotations').default;4const annotations = require('storybook-root-decorator/annotations');5const { annotations } = require('storybook-root-decorator');6const { annotations } = require('storybook-root-decorator/annotations');7const { annotations } = require('storybook-root-decorator/annotations').default;8const { default: { annotations } } = require('storybook-root-decorator/annotations');9const { default: { annotations } } = require('storybook-root-decorator');10const { annotations } = require('storybook-root-decorator/annotations').default;11const { default: { annotations } } = require('storybook-root-decorator/annotations');12const { default: { annotations } } = require('storybook-root-decorator');13const { annotations } = require('storybook-root-decorator/annotations').default;14const { default: { annotations } } = require('storybook-root-decorator/annotations');15const { default: { annotations } } = require('storybook-root-decorator');16const { annotations } = require('storybook-root-decorator/annotations').default;17const { default: { annotations } } = require('storybook-root-decor

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withRootDecorator } from 'storybook-addon-root-decorator';2addDecorator(withRootDecorator);3import { withRootDecorator } from 'storybook-addon-root-decorator';4addDecorator(withRootDecorator);5import { withRootDecorator } from 'storybook-addon-root-decorator';6addDecorator(withRootDecorator);7import { withRootDecorator } from 'storybook-addon-root-decorator';8addDecorator(withRootDecorator);9import { withRootDecorator } from 'storybook-addon-root-decorator';10addDecorator(withRootDecorator);11import { withRootDecorator } from 'storybook-addon-root-decorator';12addDecorator(withRootDecorator);13import { withRootDecorator } from 'storybook-addon-root-decorator';14addDecorator(withRootDecorator);15import { withRootDecorator } from 'storybook-addon-root-decorator';16addDecorator(withRootDecorator);17import { withRootDecorator } from 'storybook-addon-root-decorator';18addDecorator(withRootDecorator);19import { withRootDecorator } from 'storybook-addon-root-decorator';20addDecorator(withRootDecorator);21import { withRootDecorator } from 'storybook-addon-root-decorator';22addDecorator(withRootDecorator);23import { withRootDecorator } from 'storybook-addon-root-decorator';24addDecorator(withRootDecorator);25import { withRootDecorator } from 'storybook-addon-root-decorator';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { annotations } from 'storybook-root-decorator';2const { addDecorator, addParameters } = require('@storybook/react');3const { withContexts } = require('@storybook/addon-contexts/react');4const { contexts } = require('./contexts');5const { withA11y } = require('@storybook/addon-a11y');6const { withKnobs } = require('@storybook/addon-knobs');7const { withInfo } = require('@storybook/addon-info');8const { withTests } = require('@storybook/addon-jest');9const { withThemesProvider } = require('storybook-addon-styled-component-theme');10const { withTests: withTests2 } = require('storybook-addon-jest');11const { withTests: withTests3 } = require('storybook-addon-jest-react');12const { withTests: withTests4 } = require('storybook-addon-jest-results');13const { withTests: withTests5 } = require('storybook-addon-jest-test');14const { withTests: withTests6 } = require('storybook-addon-jest-tests');15const { withTests: withTests7 } = require('storybook-addon-jest-tests2');16const { withTests: withTests8 } = require('storybook-addon-jest-tests3');17const { withTests: withTests9 } = require('storybook-addon-jest-tests4');18const { withTests: withTests10 } = require('storybook-addon-jest-tests5');19const { withTests: withTests11 } = require('storybook-addon-jest-tests6');20const { withTests: withTests12 } = require('storybook-addon-jest-tests7');21const { withTests: withTests13 } = require('storybook-addon-jest-tests8');22const { withTests: withTests14 } = require('storybook-addon-jest-tests9');23const { withTests: withTests15 } = require('storybook-addon-jest-tests10');24const { withTests: withTests16 } = require('storybook-addon-jest-tests11');25const { withTests: withTests17 } = require('storybook-addon-jest-tests12');26const { withTests: withTests18 } = require('storybook-addon-jest-tests13');27const { withTests: withTests19 } = require('storybook-addon-jest-tests14');28const { withTests:

Full Screen

Using AI Code Generation

copy

Full Screen

1import { addDecorator } from '@storybook/react';2import { withAnnotations } from 'storybook-addon-annotations';3addDecorator(withAnnotations);4import React from 'react';5import { storiesOf } from '@storybook/react';6import Test from './test';7storiesOf('Test', module)8 .add('Test', () => (9 .addAnnotations({10 annotations: {11 'Test': {12 }13 }14 });15import { addDecorator } from '@storybook/react';16import { annotations } from 'storybook-addon-annotations';17addDecorator(annotations);18import React from 'react';19import { storiesOf } from '@storybook/react';20import Test from './test';21storiesOf('Test', module)22 .add('Test', () => (23 .add('Test 2', () => (24 .addAnnotations({25 annotations: {26 'Test': {27 }28 }29 });30import { addDecorator } from '@storybook/react';31import { annotations } from 'storybook-addon-annotations';32addDecorator(annotations);33import React from

Full Screen

Using AI Code Generation

copy

Full Screen

1import { annotations } from 'storybook-root-decorator'2export default {3 decorators: [annotations()],4}5export const story1 = () => <button>Click me</button>6import { withAnnotations } from '@storybook/addon-annotations'7import { annotations } from 'storybook-root-decorator'8export default {9 decorators: [withAnnotations, annotations()],10}11import { annotations } from 'storybook-root-decorator'12export const decorators = [annotations()]

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Annotations } from "storybook-root";2const annotations = new Annotations();3annotations.add({4});5annotations.add({6});7const annotationsArray = annotations.asArray();8const annotationsObject = annotations.asObject();9const annotationsString = annotations.asString();10const specificAnnotation = annotations.get("1");11annotations.update("1", {12});13annotations.remove("1");14annotations.removeAll();15const numberOfAnnotations = annotations.count();16const annotationsString = annotations.asString();17MIT © [michael-brade](

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