describe('Test related item list directive', function () { var scope, compile, $httpBackend, removeCIData; beforeEach(module('myitsmApp', 'templates')); beforeEach(function () { inject(function ($compile, $rootScope, $injector, relationModel, events, relationService, $q) { var deferred = $q.defer(), getLocale = function () { return readJSON('scripts/app/i18n/resources-locale_en.json'); }; $httpBackend = $injector.get('$httpBackend'); compile = $compile; scope = $rootScope.$new(); this.relationModel = relationModel; this.relationService = relationService; this.events = events; $httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale()); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=asset').respond(200); $httpBackend.whenGET('/smartit/rest/relations/change/IDGAA5V0GEXADAPGZQ1EPGDCV45ZN3').respond(200); $httpBackend.whenPOST('/smartit/rest/asset/relationshiptypes').respond('[]'); $httpBackend.whenDELETE('/smartit/rest/relations/change/IDGAA5V0GEXADAPGZQ1EPGDCV45ZN3').respond('[]'); spyOn(relationService, 'removeRelation').and.callFake(function () { deferred.resolve(true); return deferred.promise; }); spyOn(relationModel, 'refreshRelations').and.callFake(function () { deferred.resolve(true); return deferred.promise; }); scope.basicData = { "type": "change", "crossLaunchURL": "http://clm-aus-000230.bmc.com:8080/arsys//forms/clm-aus-000225/SHR%3ALandingConsole/Default+Administrator+View/?mode=search&F304255500=CHG%3AInfrastructure+Change&F1000000076=FormOpen&F303647600=SearchTicketWithQual&F304255610='179'=\"IDGAA5V0GEXADAPGZQ1EPGDCV45ZN3\"", "id": "IDGAA5V0GEXADAPGZQ1EPGDCV45ZN3", "createDate": 1523399158000, "displayId": "CRQ305", "modifiedDate": 1523429455000, "summary": "Test 2", "priority": "Low", "customFields": {}, "following": true, "accessMappings": { "fieldMappings": { "priority": "write", "impact": "write", "urgency": "write", "riskLevel": "write", "impactedService": "write", "operationCategoryTier1": "write", "operationCategoryTier2": "write", "operationCategoryTier3": "write", "productCategoryTier1": "write", "productCategoryTier2": "write", "productCategoryTier3": "write", "productName": "write", "productModelVersion": "write", "siteName": "write", "siteGroup": "write", "siteRegion": "write", "displayId": "read", "changeReason": "write", "desc": "write", "previousStatus": "write", "customerFirstName": "write", "customerLastName": "write", "customerDepartment": "write", "customerPhone": "write", "customerEmail": "write", "assigneeName": "write", "assigneeLoginId": "write", "assigneeGroup": "write", "assigneeGroupId": "write", "managerName": "write", "managerLoginId": "write", "managerGroup": "write", "managerGroupId": "write", "scheduledStartDate": "write", "scheduledEndDate": "write", "actualStartDate": "write", "actualEndDate": "write", "timing": "write", "contactCompany": "write", "contactOrganization": "write", "summary": "write", "status": "write", "contactDepartment": "write", "targetDate": "write" } } }; scope.dependency = "change-to-cis"; removeCIData = { "desc": "Dell Latitude E6410", "displayId": "", "parentId": "IDGAA5V0GEXADAPGZQ1EPGDCV45ZN3", "relationshipType": "changes", "tag": "linkeditem", "type": "asset", "templateName": "", "realObject": { "reconciliationId": "REHAA5V0GQBORANBH631IKTA4IJMQ1", "name": "1LLZ6BS", "classId": "BMC_COMPUTERSYSTEM", "type": "Hardware", "status": { "value": "Deployed" }, "hasImpact": false, "isParent": false, "isChild": false, "instanceId": "OI-A2A564F898CD11E3AD4F005056AC510B", "assetType": "Computer System", "manufacturer": "Dell" }, "visited": false, "subType": "", "id": "REHAA5V0GQBORANBH631IKTA4IJMQ1", "isPoi": false, "entityLink": "#/asset/REHAA5V0GQBORANBH631IKTA4IJMQ1/BMC_COMPUTERSYSTEM", "$$hashKey": "object:930" }; this.relationModel.cache = { "IDGAA5V0GEXADAPGZQ1EPGDCV45ZN3": [ { "desc": "Dell Latitude E6410", "displayId": "", "parentId": "IDGAA5V0GEXADAPGZQ1EPGDCV45ZN3", "relationshipType": "changes", "tag": "linkeditem", "type": "asset", "templateName": "", "realObject": { "reconciliationId": "REHAA5V0GQBORANBH631IKTA4IJMQ1", "name": "1LLZ6BS", "classId": "BMC_COMPUTERSYSTEM", "type": "Hardware", "status": { "value": "Deployed" }, "hasImpact": false, "isParent": false, "isChild": false, "instanceId": "OI-A2A564F898CD11E3AD4F005056AC510B", "assetType": "Computer System", "manufacturer": "Dell" }, "visited": false, "subType": "", "id": "REHAA5V0GQBORANBH631IKTA4IJMQ1", "isPoi": false, "entityLink": "#/asset/REHAA5V0GQBORANBH631IKTA4IJMQ1/BMC_COMPUTERSYSTEM" } ] } }); }); function getCompiledElement(){ var element = angular.element(''), compiledElement = compile(element)(scope); scope.$digest(); return compiledElement; } it('should compile related item list directive', function () { var ele = getCompiledElement(this), divElem = ele[0]; scope.$digest(); expect(divElem).toBeDefined(); }); it('should emit RELATIONS_UPDATE_COMPLETE event on Removing CI', function () { var ele = getCompiledElement(this), isoScope = ele.isolateScope(); spyOn(isoScope, '$emit'); isoScope.factory.remove(removeCIData); isoScope.$digest(); expect(isoScope.$emit).toHaveBeenCalledWith(this.events.RELATIONS_UPDATE_COMPLETE, false); }); it('should emit RELATIONS_UPDATE_COMPLETE event on refreshing CI', function () { var ele = getCompiledElement(this), isoScope = ele.isolateScope(); spyOn(isoScope, '$emit'); isoScope.factory.refresh(); isoScope.$digest(); expect(isoScope.$emit).toHaveBeenCalledWith(this.events.RELATIONS_UPDATE_COMPLETE, false); }); });