/*** Created by npatil2.*/ describe('PersonController', function () { var $httpBackend; beforeEach(module('myitsmApp')); beforeEach(inject(function ($injector, $rootScope, $controller, personModel, userModel, $state, $filter, attachmentService, screenConfigurationModel, events, ticketActionService, $q, chatModel, openMailClientService, configurationModel) { $httpBackend = $injector.get('$httpBackend'); this.$rootScope = $rootScope; this.scope = $rootScope.$new(); this.controller = $controller; this.personModel = personModel; this.userModel = userModel; this.$state = $state; this.$filter = $filter; this.attachmentService = attachmentService; this.screenConfigurationModel = screenConfigurationModel; this.events = events; this.ticketActionService = ticketActionService; this.$q = $q; this.chatModel = chatModel; this.openMailClientService = openMailClientService; this.configurationModel = configurationModel; 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('views/dashboard/index.html').respond(200); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200); $httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200); $httpBackend.when('POST', '/smartit/rest/person/workitems/get').respond(200); $httpBackend.whenGET('/smartit/rest/v2/customization/application/search?name=Galileo&phase=2&screen=personDetailsScreen').respond(200); $httpBackend.when('GET', '/smartit/rest/v2/metadata?type=workorder').respond(200); $httpBackend.when('GET', '/smartit/rest/v2/metadata?type=incident').respond(200); $httpBackend.when('GET', '/smartit/rest/v2/metadata?type=problem').respond(200); $httpBackend.when('GET', '/smartit/rest/v2/metadata?type=change').respond(200); $httpBackend.when('GET', '/smartit/rest/v2/metadata?type=asset').respond(200); $httpBackend.when('GET', '/smartit/rest/v2/metadata?type=release').respond(200); $httpBackend.when('GET', '/smartit/rest/v2/metadata?type=knowledge').respond(200); $httpBackend.when('GET', '/smartit/rest/v2/metadata?type=task').respond(200); this.controllerInstance = this.controller('PersonController', { $scope: this.scope }); })); beforeEach(inject(function ($q, $rootScope) { var deferred = $q.defer(), data = { accessRestrictions: [ { name: 'Calbro Services' }, { name: 'Invention, Inc.' } ], company: { name: 'Calbro Services' }, department: 'Customer Service', displayId: 'PPL000000000013', email: 'A.Allbrook@calbroservices.com', firstName: 'Allen', fullName: 'Allen Allbrook', id: 'Allen', instanceId: 'AG00123F73CF5ERkUTSQmjgZAAgaQA', isSupportStaff: true, loginId: 'Allen', openTickets: 70, organization: 'Information Technology', personId: 'PPL000000000013', supportGroups: [ { name: 'Service Desk', company: { name: 'Calbro Services' }, organization: 'IT Support', isDefault: true, id: 'SGP000000000011' }, { name: 'Frontoffice Support', company: { name: 'Calbro Services' }, organization: 'IT Support', isDefault: false, id: 'SGP000000000010' } ], thumbnail: 'test', thumbnailMime: '', entityLink: '#/person/Allen', type: 'person', isVIP: false, accessMappings: { detailsEditAllowed: true, timelineEditAllowed: true, relationsEditAllowed: true } }, that = this; spyOn(this.personModel, 'followPerson').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.personModel, 'unfollowPerson').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.personModel, 'getServiceSummaryStats').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.personModel, 'getPersonDetailsByID').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.screenConfigurationModel, 'loadFieldsLabels').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.screenConfigurationModel, 'loadScreenConfigurationAndCustomFieldLabels').and.callFake(function () { deferred.resolve({}); return deferred.promise; }); spyOn(this.personModel, 'getPersonAssets').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.personModel, 'getOpenTickets').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.personModel, 'getAssignedTickets').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.personModel, 'getKnowledgeArticles').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.attachmentService, 'uploadProfileThumbnail').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.personModel, 'getAllTickets').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.configurationModel, 'isServerApplicationEnabled').and.returnValue(true); spyOn(this.personModel, 'getOpenServiceBrokerTickets').and.callFake(function () { var data = readJSON('mocks/user-sberequest-workitems.json'); that.personModel.personOpenServiceBrokerTickets.ticketList = data[0].items[0].objects; that.personModel.personOpenServiceBrokerTickets.totalMatches = data[0].items[0].totalMatches; deferred.resolve(); return deferred.promise; }); })); it('should be defined', function () { expect(this.controllerInstance).toBeDefined(); }); it('should broadcast SHOW_PROGRESS_MODAL_FOR_EDIT ', inject(function ($rootScope) { this.personId = 'PES1234'; this.scope.activeEditableSectionId = 'test'; this.personModel.personDetails = { accessRestrictions: [ { name: 'Calbro Services' }, { name: 'Invention, Inc.' } ], company: { name: 'Calbro Services' }, displayId: 'PPL000000000013', email: 'A.Allbrook@calbroservices.com', firstName: 'Allen', following: false, fullName: 'Allen Allbrook', id: 'Allen', instanceId: 'AG00123F73CF5ERkUTSQmjgZAAgaQA', isSupportStaff: true, loginId: 'Allen', openTickets: 70, organization: 'Information Technology', personId: 'PPL000000000013', supportGroups: [ { name: 'Service Desk', company: { name: 'Calbro Services' }, organization: 'IT Support', isDefault: true, id: 'SGP000000000011' } ], thumbnail: '', thumbnailMime: '', entityLink: '#/person/Allen', type: 'person', isVIP: false, accessMappings: { detailsEditAllowed: true, timelineEditAllowed: true, relationsEditAllowed: true }, availability: 'test' }; this.personModel.serviceSummary = { ratingCount: 0, ratingScore: 0, escalation: 0, ratingMarkers: [ { value: 0, $$hashKey: 'object:6790' }, { value: 0, $$hashKey: 'object:6791' }, { value: 0, $$hashKey: 'object:6792' } ] }; this.personModel.personAllTickets = { ticketList: [ { summary: 'Work order title', type: 'workorder', status: { value: 'Pending' }, assignee: { fullName: 'change_user2 m change_user2', company: { name: 'Calbro Services' }, loginId: 'change_user2' }, modifiedDate: 1509628366000, isAutomatic: false, id: 'IDGAA5V0GEPCIAOYSKMEOXWHUD56R8', displayId: 'WO133' }, { summary: 'Add ITSM User', type: 'workorder', status: { value: 'Assigned' }, assignee: { fullName: 'ka m ka', company: { name: 'Calbro Services' }, loginId: 'ka' }, isAutomatic: false, subType: "", id: 'IDGAA5V0GEPCIAOYSK21OXWHK0569B', displayId: 'WO131' } ] }; this.personModel.personAssets = [ { reconciliationId: 'OI-11f9477b81634c8aa2e7074b14059246', name: 'test', desc: '', type: 'Hardware', assetType: 'Computer System', ticketCount: 0, selected: false, receivedDate: '', classId: 'BMC_COMPUTERSYSTEM', categories: [ { name: 'product', tiers: {} } ], entityLink: '#/asset/OI-11f9477b81634c8aa2e7074b14059246/BMC_COMPUTERSYSTEM', status: { value: 'Deployed' }, role: 'usedby', assetReceivedDate: 'a few seconds' } ]; this.scope.isServiceBrokerEnabled = true; this.scope.init(this.personId); expect(this.scope.editHeader).toBe(false); expect(this.scope.isCollapsed).toBe(true); expect(this.scope.activeTaskSection).toEqual('assets'); expect(this.scope.state.isPersonDataLoading).toBe(true); $rootScope.$broadcast(this.events.TOGGLE_EDIT_MODE, 'ticket-header'); expect(this.scope.editHeader).toBe(true); $rootScope.$broadcast(this.events.EDIT_COMPLETE, 'ticket-header'); expect(this.scope.editHeader).toBe(false); this.scope.$emit('personDataUpdated'); expect(this.scope.person).toBeTruthy(); expect(this.scope.person.accessMappings.detailsEditAllowed).toBe(true); expect(this.scope.person.accessMappings.timelineEditAllowed).toBe(true); expect(this.scope.person.accessMappings.relationsEditAllowed).toBe(true); this.scope.$apply(); expect(this.scope.serviceSummary).toBeTruthy(); expect(this.scope.serviceSummary.ratingCount).toBe(0); expect(this.scope.serviceSummary.ratingScore).toBe(0); expect(this.scope.serviceSummary.escalation).toBe(0); expect(this.scope.personAssetList).toBeTruthy(); expect(this.scope.personAssetList[0].reconciliationId).toBe('OI-11f9477b81634c8aa2e7074b14059246'); expect(this.scope.personAssetList[0].assetType).toBe('Computer System'); expect(this.scope.personAssetList[0].role).toBe('usedby'); expect(this.scope.personOpenSBETickets).toBeTruthy(); expect(this.scope.personOpenSBETickets[0].summary).toBe('Test Service 2.0'); }) ); it('should follow', function () { this.userModel.userFullData = { loginId: 'Allen' }; this.scope.person = { loginId: 'Allen' }; this.myResult = this.scope.follow(); this.scope.$apply(); expect(this.myResult.$$state.value.accessRestrictions[0].name).toEqual('Calbro Services'); }); it('should un follow', function () { this.userModel.userFullData = { loginId: 'Allen' }; this.scope.person = { loginId: 'Allen', email: 'test@gmail.com' }; this.myResult = this.scope.unfollow(); this.scope.$apply(); expect(this.myResult.$$state.value.accessRestrictions[0].name).toEqual('Calbro Services'); }); it('should edit Disabled For', function () { this.sectionId = 'person-customer-card'; this.scope.activeEditableSectionId = 'test-header'; this.myResult = this.scope.editDisabledFor(this.sectionId); expect(this.myResult).toBe(true); }); it('should is URL', function () { this.str = 'person-customer-card'; this.myResult = this.scope.isURL(this.str); expect(this.myResult).toBe(false); }); it('should set Task Section', function () { this.sectionId = 'person-customer-card'; this.myResult = this.scope.setTaskSection(this.sectionId); expect(this.scope.activeTaskSection).toEqual('person-customer-card'); }); it('should handle File Change', function () { this.scope.person = { loginId: 'Allen' }; this.fileInput = 'txt'; this.userModel.userFullData = { loginId: 'Allen' }; this.myResult = this.scope.handleFileChange(this.fileInput); this.scope.$apply(); expect(this.scope.person.thumbnail).toEqual('test'); expect(this.userModel.userFullData.thumbnail).toEqual('test') }); it('should load More Requested By Tickets', function () { this.scope.state = { isPersonDataLoading: false, isMoreRequestedByTicketsLoading: undefined }; this.personModel.personOpenTickets = { "ticketList": [ { summary: 'Work order title', type: 'workorder', status: { value: 'Pendin' }, assignee: { fullName: 'change_user2 m change_user2', company: { name: 'Calbro Services' }, loginId: 'change_user2' }, isAutomatic: false, id: 'IDGAA5V0GEPCIAOYSKMEOXWHUD56R8', createDate: 1509628280000, displayId: 'WO133' } ], "totalMatches": 153 }; this.scope.loadMoreRequestedByTickets(); expect(this.scope.state.isMoreRequestedByTicketsLoading).toBe(true); this.scope.$apply(); expect(this.scope.state.isMoreRequestedByTicketsLoading).toBe(false); expect(this.scope.personOpenTickets).toBeTruthy(); expect(this.scope.personOpenTickets[0].type).toEqual('workorder'); expect(this.scope.personOpenTicketsTotalMatches).toEqual(153); }); it('should load More All Tickets', function () { this.scope.state = { isPersonDataLoading: false, isMoreAllTicketsLoading: undefined }; this.personModel.personAllTickets = { "ticketList": [ { summary: 'Work order title', type: 'workorder', status: { value: 'Pendin' }, assignee: { fullName: 'change_user2 m change_user2', company: { name: 'Calbro Services' }, loginId: 'change_user2' }, isAutomatic: false, id: 'IDGAA5V0GEPCIAOYSKMEOXWHUD56R8', createDate: 1509628280000, displayId: 'WO133' } ], "totalMatches": 153 }; this.scope.loadMoreAllTickets(); expect(this.scope.state.isMoreAllTicketsLoading).toBe(true); this.scope.$apply(); expect(this.scope.state.isMoreAllTicketsLoading).toBe(false); expect(this.scope.personAllTickets).toBeTruthy(); expect(this.scope.personAllTickets[0].summary).toEqual('Work order title'); expect(this.scope.personAllTicketsTotalMatches).toEqual(153); }); it('should load More Assigned Tickets', function () { this.scope.state = { isPersonDataLoading: false, isPersonMoreTicketsLoading: undefined }; this.personModel.personAssignedTickets = { "ticketList": [ { summary: 'Work order title', type: 'workorder', status: { value: 'Pendin' }, assignee: { fullName: 'change_user2 m change_user2', company: { name: 'Calbro Services' }, loginId: 'change_user2' }, isAutomatic: false, id: 'IDGAA5V0GEPCIAOYSKMEOXWHUD56R8', createDate: 1509628280000, displayId: 'WO133' } ], "totalMatches": 153 }; this.scope.loadMoreAssignedTickets(); expect(this.scope.state.isPersonMoreTicketsLoading).toBe(true); this.scope.$apply(); expect(this.scope.state.isPersonMoreTicketsLoading).toBe(false); expect(this.scope.personAssignedTickets).toBeTruthy(); expect(this.scope.personAssignedTickets[0].summary).toEqual('Work order title'); expect(this.scope.totalMatches).toEqual(153); }); it('should load More Service Broker Tickets', function () { this.scope.state = { isPersonMoreOpenSBETicketsLoading: undefined }; this.scope.getMoreOpenServiceBrokerTickets(); expect(this.scope.state.isPersonMoreOpenSBETicketsLoading).toBe(true); this.scope.$apply(); expect(this.scope.state.isPersonMoreOpenSBETicketsLoading).toBe(false); expect(this.scope.personOpenSBETickets).toBeTruthy(); expect(this.scope.personOpenSBETickets[0].summary).toBe('Test Service 2.0'); expect(this.scope.personOpenSBETicketsTotalMatches).toEqual(5); }); });