describe('LinkController', function () { 'use strict'; var ctrl, $controller, $rootScope, $scope, modalInstance, linkParams, $httpBackend; beforeEach(module('myitsmApp')); beforeEach(inject(function (_$controller_, _$rootScope_, $injector, $q, metadataModel, systemAlertService) { $controller = _$controller_; $rootScope = _$rootScope_; $scope = $rootScope.$new(); $httpBackend = $injector.get('$httpBackend'); this.$q = $q; this.metadataModel = metadataModel; this.systemAlertService = systemAlertService; linkParams = {selectedItems: [{company: 'Calbro Services', id: 'IDGAA5V0GEWV1APIHEJMPH07I0NQTY', type: 'incident'}]}; var getLocale = function () { return readJSON('scripts/app/i18n/resources-locale_en.json'); }; $httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale()); $httpBackend.whenGET('/smartit/rest/serverstates').respond(200); $httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=outage').respond(200); $httpBackend.whenGET('/smartit/rest').respond(200); $httpBackend.whenGET('/smartit/rest/relations').respond(200); $httpBackend.whenGET('/smartit/rest/v2/incident/IDGAA5V0GEWV1APIHEJMPH07I0NQTY').respond(200); $httpBackend.whenGET('/smartit/rest/attachment/info/incident/IDGAA5V0GEWV1APIHEJMPH07I0NQTY').respond(200); $httpBackend.whenGET('/smartit/rest/relations/incident/IDGAA5V0GEWV1APIHEJMPH07I0NQTY').respond(200); $httpBackend.whenPOST('/smartit/rest/bulkupdate/relations/bulk').respond('[]'); modalInstance = { close: jasmine.createSpy('modalInstance.close'), dismiss: jasmine.createSpy('modalInstance.dismiss'), result: { then: jasmine.createSpy('modalInstance.result.then') } }; ctrl = $controller('LinkController', { $scope: $scope, $modalInstance: modalInstance, linkParams: linkParams }); })); beforeEach(inject(function ($q, $rootScope, relationModel) { var deferred = $q.defer(), ticketData = { id: '123sdxws', name: 'test', status: { name: 'asd', value: '', reason: '' }, resolution: 'test', customer: { id: 'ab12333', name: 'test', accessMappings: [ { permission: 'write', id: 'details' }, { permission: 'write', id: 'timeline' }, { permission: 'read', id: 'relations' } ] }, contact: { name: 'test', id: '123ddd' }, desc: 'test desc', impact: { name: 'test' }, urgency: { name: 'test' }, impactedService: { name: 'test', reconciliationId: 'qsew12' }, displayId: '12345rfdfg' }; $scope.selected.relation = "relatedto"; $scope.selected.entities = [ { "category": "tickets", "desc": "Work Log Entry from Ian. Remedy Application Service CWL000000000009 Work Log Entry from Ian. Stafford Ian Plyment Frontoffice Support Calbro Services IT Support Mary Mann Calbro Services CRQ_CAL_1000006 Service...", "displayId": "CRQ_CAL_1000006", "id": "AG00123F73CF5EWtETSQ9WQ8Ag90gB", "relevancy": 100, "title": "Backup laptop prior to restaging back to factory specifications.", "type": "change", "templateName": "", "visited": false, "subType": "", "$$hashKey": "object:2111", "isSelected": true } ]; relationModel.cache ={ "IDGAA5V0GEWV1APIHEJMPH07I0NQTY": [ { "desc": "Backup laptop prior to restaging back to factory specifications.", "displayId": "CRQ_CAL_1000006", "parentId": "IDGAA5V0GEWV1APIHEJMPH07I0NQTY", "relationshipType": "relatedto", "tag": "linkeditem", "type": "change", "templateName": "", "visited": false, "subType": "", "id": "AG00123F73CF5EWtETSQ9WQ8Ag90gB", "isPoi": false } ] }; spyOn(this.metadataModel, 'getMetadataByType').and.callFake(function () { deferred.resolve(ticketData); return deferred.promise; }); spyOn(this.systemAlertService, 'warning').and.callFake(function () { deferred.resolve(true); return deferred.promise; }); })); it('should exist', function () { expect(ctrl).toBeDefined(); }); it('searchConfig length greater that 0', function () { expect($scope.searchConfig.length).toBeGreaterThan(0); }); it('should show a notification if relationships are already existed while linking relationship', function () { $scope.link(); $scope.$digest(); expect(this.systemAlertService.warning).toHaveBeenCalled(); }); });